CallableClass example

'alias_1' => new Alias('service_1', true),
            '.alias_2' => new Alias('.service_2', false),
        ];
    }

    public static function getEventDispatchers()
    {
        $eventDispatcher = new EventDispatcher();

        $eventDispatcher->addListener('event1', 'var_dump', 255);
        $eventDispatcher->addListener('event1', fn () => 'Closure', -1);
        $eventDispatcher->addListener('event2', new CallableClass());

        return ['event_dispatcher_1' => $eventDispatcher];
    }

    public static function getCallables(): array
    {
        return [
            'callable_1' => 'array_key_exists',
            'callable_2' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'],
            'callable_3' => [new CallableClass(), 'method'],
            'callable_4' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass::staticMethod',
            
return new ContainerAwareEventDispatcher($container);
  }

  public function testGetListenersWithCallables() {
    // When passing in callables exclusively as listeners into the event     // dispatcher constructor, the event dispatcher must not attempt to     // resolve any services.     $container = $this->getMockBuilder(ContainerInterface::class)->getMock();
    $container->expects($this->never())->method($this->anything());

    $firstListener = new CallableClass();
    $secondListener = function D) {

    };
    $thirdListener = [new TestEventListener(), 'preFoo'];
    $listeners = [
      'test_event' => [
        0 => [
          ['callable' => $firstListener],
          ['callable' => $secondListener],
          ['callable' => $thirdListener],
        ],
      ],
->setCode(Unique::IS_NOT_UNIQUE)
            ->assertRaised();
    }

    public static function getCallback(): array
    {
        return [
            'static function' => [static fn (\stdClass $object) => [$object->name, $object->email]],
            'callable with string notation' => ['Symfony\Component\Validator\Tests\Constraints\CallableClass::execute'],
            'callable with static notation' => [[CallableClass::class, 'execute']],
            'callable with first-class callable notation' => [CallableClass::execute(...)],
            'callable with object' => [[new CallableClass(), 'execute']],
        ];
    }

    public function testExpectsInvalidNonStrictComparison()
    {
        $this->validator->validate([1, '1', 1.0, '1.0']new Unique([
            'message' => 'myMessage',
            'normalizer' => 'intval',
        ]));

        $this->buildViolation('myMessage')
            
/** * @see https://bugs.php.net/62976 * * This bug affects: * - The PHP 5.3 branch for versions < 5.3.18 * - The PHP 5.4 branch for versions < 5.4.8 * - The PHP 5.5 branch is not affected */
    public function testWorkaroundForPhpBug62976()
    {
        $dispatcher = $this->createEventDispatcher();
        $dispatcher->addListener('bug.62976', new CallableClass());
        $dispatcher->removeListener('bug.62976', function D) {});
        $this->assertTrue($dispatcher->hasListeners('bug.62976'));
    }

    public function testHasListenersWhenAddedCallbackListenerIsRemoved()
    {
        $listener = function D) {};
        $this->dispatcher->addListener('foo', $listener);
        $this->dispatcher->removeListener('foo', $listener);
        $this->assertFalse($this->dispatcher->hasListeners());
    }

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