TestHook example


    public function testExecute(array $hooks, array $expected): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures');

        $object = new ArrayStruct();

        $context = Context::createDefaultContext();
        foreach ($hooks as $hook) {
            $this->executor->execute(new TestHook($hook$context['object' => $object]));
        }

        static::assertNotEmpty($expected);

        foreach ($expected as $key => $value) {
            static::assertTrue($object->has($key));
            static::assertEquals($value$object->get($key));
        }
    }

    public function testNoneExistingServicesRequired(): void
    {

    public function testWithoutApp(array $criteria, string $method, IdsCollection $ids, callable $expectation): void
    {
        $this->ids = $ids;
        $this->createProducts();

        $facade = $this->factory->factory(
            new TestHook('test', Context::createDefaultContext()),
            new Script('test', '', new \DateTimeImmutable())
        );

        $result = $facade->$method('product', $criteria); /* @phpstan-ignore-line */

        $expectation($result);
    }

    /** * @return array<string, array<int, mixed>> */
    
if ($closure instanceof \Closure) {
            $closure($service$this->ids);
        }
    }

    public function testDependency(): void
    {
        $this->expectException(HookInjectionException::class);

        $service = $this->getContainer()->get(CartFacadeHookFactory::class);
        $service->factory(new TestHook('test', Context::createDefaultContext())$this->script);
    }

    public static function addProductProvider(): \Generator
    {
        yield 'Test with simple product' => ['p1', 'p1'];
        yield 'Test variant support' => ['v2.1', 'v2.1'];
        yield 'Test parents will not be added' => ['p2', null];
    }

    public static function scriptProvider(): \Generator
    {
        
/** * @return array<string, array<int, mixed>> */
    public static function getWithoutAppCases(): array
    {
        $salesChannelContext = Generator::createSalesChannelContext();
        $salesChannelContext->getSalesChannel()->setId(TestDefaults::SALES_CHANNEL);

        return [
            'simpleGet' => [
                new TestHook('test', Context::createDefaultContext()),
                null,
                'generic',
            ],
            'salesChannelSpecificGet' => [
                new TestHook('test', Context::createDefaultContext()),
                TestDefaults::SALES_CHANNEL,
                'specific',
            ],
            'itUsesSalesChannelFromSalesChannelContextPerDefault' => [
                new SalesChannelTestHook('test', $salesChannelContext),
                null,
                

    public function testFacade(array $payload, string $method, IdsCollection $ids, callable $expectation): void
    {
        $this->ids = $ids;
        $this->createProducts();

        $facade = $this->factory->factory(
            new TestHook('test', $this->context),
            new Script('test', '', new \DateTimeImmutable())
        );

        $facade->$method('product', $payload); /* @phpstan-ignore-line */

        $expectation($this->context, $this->getContainer());
    }

    /** * @return array<string, array<int, mixed>> */
    
$this->controller->setContainer($container);

        static::expectException(\Exception::class);
        static::expectExceptionMessageMatches('/does not have twig injected. Add to your service definition a method call to setTwig with the twig instance/');

        $this->controller->testRenderView('test.html.twig', ['foo' => 'bar']);
    }

    public function testHook(): void
    {
        $hook = new TestHook('test', Context::createDefaultContext());

        $executor = static::createMock(ScriptExecutor::class);
        $executor
            ->expects(static::once())
            ->method('execute')
            ->with($hook);

        $container = new ContainerBuilder();
        $container->set(ScriptExecutor::class$executor);

        $this->controller->setContainer($container);

        
Home | Imprint | This part of the site doesn't use cookies.