StaticDefinitionInstanceRegistry example

protected function setUp(): void
    {
        $this->ids = new IdsCollection();
    }

    /** * @param class-string<EntityDefinition> $class */
    public function getDefinition(string $class = OrderLineItemDefinition::class): EntityDefinition
    {
        new StaticDefinitionInstanceRegistry(
            [$definition = new $class()],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        return $definition;
    }

    public function testGetSubscribedEvents(): void
    {
        $events = OrderStockSubscriber::getSubscribedEvents();

        
$writeContextMockWithVersionId->expects(static::once())->method('scope')
            ->with(static::equalTo(Context::SYSTEM_SCOPE)static::callback(function Dcallable $closure) use ($writeContextMockWithVersionId) {
                /** @var callable(MockObject&WriteContext): void $closure */
                $closure($writeContextMockWithVersionId);

                return true;
            }));

        $writeContextMockWithVersionId->expects(static::exactly(2))->method('getContext')->willReturn(Context::createDefaultContext());

        $registry = new StaticDefinitionInstanceRegistry(
            [
                VersionManagerTestDefinition::class,
            ],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $entityWriteResult = $this->versionManager->clone(
            $registry->getByEntityName('product'),
            Uuid::randomHex(),
            Uuid::randomHex(),
            
'id' => ['resolver' => 'dummy', 'value' => 'c1']],
                ['id' => ['resolver' => 'dummy', 'value' => 'c2']],
            ],

            // nesting case             'visibilities' => [
                ['visibility' => 1, 'salesChannelId' => ['resolver' => 'dummy', 'value' => 's1']],
            ],
        ];

        $resolver = new SyncFkResolver(
            new StaticDefinitionInstanceRegistry(
                [
                    ProductDefinition::class,
                    TaxDefinition::class,
                    ProductVisibilityDefinition::class,
                    SalesChannelDefinition::class,
                    CategoryDefinition::class,
                    ProductCategoryDefinition::class,
                ],
                $this->createMock(ValidatorInterface::class),
                $this->createMock(EntityWriteGatewayInterface::class)
            ),
            [

class RequestCriteriaBuilderTest extends TestCase
{
    private RequestCriteriaBuilder $requestCriteriaBuilder;

    private StaticDefinitionInstanceRegistry $staticDefinitionRegistry;

    protected function setUp(): void
    {
        $aggregationParser = new AggregationParser();

        $this->staticDefinitionRegistry = new StaticDefinitionInstanceRegistry(
            [
                new ProductDefinition(),
                new ProductOptionDefinition(),
                new PropertyGroupOptionDefinition(),
                new ProductPriceDefinition(),
                new ProductCategoryDefinition(),
                new CategoryDefinition(),
            ],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        
$extractor = new WriteCommandExtractor(
            $this->createMock(EntityWriteGateway::class)
        );

        $data = [
            'name' => 'My super webhook',
            'eventName' => 'product.written',
            'url' => 'http://localhost',
        ];
        $data = \array_replace($data$payload);

        $registry = new StaticDefinitionInstanceRegistry(
            [
                WebhookDefinition::class,
            ],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $context = Context::createDefaultContext($scope);

        $parameters = new WriteParameterBag(
            $registry->get(WebhookDefinition::class),
            
static::assertEquals($expected$result);
    }

    public function testProcess(): void
    {
        $request = new Request();
        $request->setMethod(Request::METHOD_POST);

        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getContext')->willReturn(Context::createDefaultContext());

        new StaticDefinitionInstanceRegistry(
            [$definition = new PropertyGroupOptionDefinition()],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $repository = new StaticEntityRepository([
            function DCriteria $criteria) {
                static::assertContains('red', $criteria->getIds());
                static::assertContains('green', $criteria->getIds());
                static::assertContains('xl', $criteria->getIds());
                static::assertContains('l', $criteria->getIds());

                
private RuleDefinition $definition;

    private MockObject&RuleConditionRegistry $conditionRegistry;

    private RuleAreaUpdater $areaUpdater;

    protected function setUp(): void
    {
        $this->connection = $this->createMock(Connection::class);
        $this->conditionRegistry = $this->createMock(RuleConditionRegistry::class);

        $registry = new StaticDefinitionInstanceRegistry(
            [
                RuleAreaDefinitionTest::class,
                RuleAreaTestManyToMany::class,
                RuleAreaTestOneToMany::class,
                RuleAreaTestOneToOne::class,
                RuleAreaTestManyToOne::class,
            ],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        
class AvailableStockMirrorSubscriberTest extends TestCase
{
    private IdsCollection $ids;

    protected function setUp(): void
    {
        $this->ids = new IdsCollection();
    }

    public function getDefinition(): ProductDefinition
    {
        new StaticDefinitionInstanceRegistry(
            [$definition = new ProductDefinition()],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        return $definition;
    }

    public function testBeforeWriteOnlyReactsToLiveVersions(): void
    {
        $context = Context::createDefaultContext()->createWithVersionId($this->ids->create('version'));

        

class ApiCriteriaValidatorTest extends TestCase
{
    /** * @dataProvider criteriaProvider * * @param class-string<\Exception>|null $expectedException */
    public function testCriteria(Criteria $criteria, Context $context, ?string $expectedException): void
    {
        $validator = new ApiCriteriaValidator(
            new StaticDefinitionInstanceRegistry(
                [
                    SalesChannelProductDefinition::class,
                    OrderLineItemDefinition::class,
                ],
                $this->createMock(ValidatorInterface::class),
                $this->createMock(EntityWriteGatewayInterface::class)
            )
        );

        $e = null;

        
public function __construct(
        private array $searches,
        private readonly ?EntityDefinition $definition = null
    ) {
        if (!$definition instanceof EntityDefinition) {
            return;
        }

        try {
            $definition->getFields();
        } catch (\Throwable $exception) {
            $registry = new StaticDefinitionInstanceRegistry(
                [$definition],
                Validation::createValidator(),
                new StaticEntityWriterGateway()
            );
            $definition->compile($registry);
        }
    }

    /** * @return EntitySearchResult<TEntityCollection> */
    

            ],
            $repo->deletes
        );
    }

    /** * @param array<EntityDefinition> $definitions */
    private function configureRegistry(array $definitions): void
    {
        new StaticDefinitionInstanceRegistry(
            $definitions,
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );
    }

    /** * @param array<Field> $fields */
    private function getMediaDefinition(array $fields): EntityDefinition
    {
        

    private EntityHydrator $hydrator;

    private StaticDefinitionInstanceRegistry $definitionInstanceRegistry;

    protected function setUp(): void
    {
        $container = new ContainerBuilder();
        $this->hydrator = new EntityHydrator($container);
        $container->set(EntityHydrator::class$this->hydrator);

        $this->definitionInstanceRegistry = new StaticDefinitionInstanceRegistry(
            [
                FkExtensionFieldTest::class,
                CustomFieldPlainTestDefinition::class,
                CustomFieldTestDefinition::class,
                CustomFieldTestTranslationDefinition::class,
                SingleEntityDependencyTestRootDefinition::class,
                SingleEntityDependencyTestSubDefinition::class,
                SingleEntityDependencyTestDependencyDefinition::class,
                SingleEntityDependencyTestDependencySubDefinition::class,
                ToManyAssociationDefinition::class,
            ],
            

class EntityWriteEventTest extends TestCase
{
    public function testGetters(): void
    {
        $ids = new IdsCollection();

        $context = Context::createDefaultContext();
        $writeContext = WriteContext::createFromContext($context);

        $registry = new StaticDefinitionInstanceRegistry(
            [new ProductDefinition()],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $command = new DeleteCommand(
            $registry->getByEntityName('product'),
            ['id' => $ids->get('p1')],
            new EntityExistence('product', ['id' => $ids->get('p1')], true, true, true, [])
        );

        
'createdAt' => [
                        'gte' => '2023-06-01 00:00:00.000',
                        'lt' => '2023-06-03 13:47:42.000',
                    ],
                ],
            ],
        ];
    }

    public function getDefinition(): EntityDefinition
    {
        $instanceRegistry = new StaticDefinitionInstanceRegistry(
            [ProductDefinition::class, ProductManufacturerDefinition::class, ProductTranslationDefinition::class],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        return $instanceRegistry->getByEntityName('product');
    }
}

/** * @internal */
public function __construct(
        private array $searches,
        private readonly ?EntityDefinition $definition = null
    ) {
        if (!$definition) {
            return;
        }

        try {
            $definition->getFields();
        } catch (\Throwable $exception) {
            $registry = new StaticDefinitionInstanceRegistry(
                [$definition],
                Validation::createValidator(),
                new StaticEntityWriterGateway()
            );
            $definition->compile($registry);
        }
    }

    /** * @return EntitySearchResult<TEntityCollection> */
    
Home | Imprint | This part of the site doesn't use cookies.