Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php (PHP)

Code before:
        ], $builder->findTaggedServiceIds('foo'), '->findTaggedServiceIds() returns an array of service ids and its tag attributes');
        $this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services');
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The service "foo" tagged "foo" must not be abstract.');
        $builder->findTaggedServiceIds('foo', true);
    }

    public function testFindTaggedValueClasses()
    {
        $builder = new ContainerBuilder();
        $builder
            ->register('foo', 'Bar\FooClass')
            ->setAbstract(true)
            ->addTag('foo', ['foo' => 'foo'])
            ->addTag('bar', ['bar' => 'bar'])
            ->addTag('foo', ['foofoo' => 'foofoo'])
        ;

        $expected = [
            'foo' => [
                ['foo' => 'foo'],
                ['foofoo' => 'foofoo'],
            ],
        ];

        $this->assertEquals($expected, $builder->findTaggedValueClasses('foo', false));
        $this->assertFalse($builder->getDefinition('foo')->hasTag('container.excluded'));

        $this->assertEquals($expected, $builder->findTaggedValueClasses('foo'));
        $this->assertTrue($builder->getDefinition('foo')->hasTag('container.excluded'));
    }

    public function testFindUnusedTags()
    {
        $builder = new ContainerBuilder();
        $builder
            ->register('foo', 'Bar\FooClass')
            ->addTag('kernel.event_listener', ['foo' => 'foo'])
            ->addTag('kenrel.event_listener', ['bar' => 'bar'])
        ;
        $builder->findTaggedServiceIds('kernel.event_listener');
        $this->assertEquals(['kenrel.event_listener'], $builder->findUnusedTags(), '->findUnusedTags() returns an array with unused tags');
    }

    public function testFindDefinition()
    {
        $container = new ContainerBuilder();
        $container->setDefinition('foo', $definition = new Definition('Bar\FooClass'));
        $container->setAlias('bar', 'foo');
        $container->setAlias('foobar', 'bar');
        $this->assertEquals($definition, $container->findDefinition('foobar'), '->findDefinition() returns a Definition');

Review comment (suggestion):
```suggestion
        $this->assertSame($expected, $builder->findTaggedValueClasses('foo', false));
```

Code after:

    public function testFindTaggedServiceIdsThrowsWhenAbstract()
    {
        $builder = new ContainerBuilder();
        $builder->register('foo', 'Bar\FooClass')
            ->setAbstract(true)
            ->addTag('foo', ['foo' => 'foo']);

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The service "foo" tagged "foo" must not be abstract.');
        $builder->findTaggedServiceIds('foo', true);
    }

    public function testFindExcludedServiceIds()
    {
        $builder = new ContainerBuilder();
        $builder->register('myservice', 'Bar\FooClass')
            ->addTag('foo', ['foo' => 'foo'])
            ->addTag('bar', ['bar' => 'bar'])
            ->addTag('foo', ['foofoo' => 'foofoo'])
            ->addExcludeTag('container.excluded');

        $expected = ['myservice' => [['foo' => 'foo'], ['foofoo' => 'foofoo']]];
        $this->assertSame($expected, $builder->findExcludedServiceIds('foo'));
        $this->assertSame([], $builder->findExcludedServiceIds('foofoo'));
    }

    public function testFindExcludedServiceIdsThrowsWhenNotExcluded()
    {
        $builder = new ContainerBuilder();
        $builder->register('myservice', 'Bar\FooClass')
            ->addTag('foo', ['foo' => 'foo'])
            ->addTag('bar', ['bar' => 'bar'])
            ->addTag('foo', ['foofoo' => 'foofoo']);

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The service "myservice" tagged "foo" is missing the "container.excluded" tag.');
        $builder->findExcludedServiceIds('foo', true);
    }

    public function testFindUnusedTags()
    {
        $builder = new ContainerBuilder();
        $builder
            ->register('foo', 'Bar\FooClass')
            ->addTag('kernel.event_listener', ['foo' => 'foo'])
            ->addTag('kenrel.event_listener', ['bar' => 'bar'])
        ;
        $builder->findTaggedServiceIds('kernel.event_listener');
        $this->assertEquals(['kenrel.event_listener'], $builder->findUnusedTags(), '->findUnusedTags() returns an array with unused tags');
    }