getDefinedTags example

if ('cli' !== \PHP_SAPI) {
    throw new Exception('This script must be run from the command line.');
}

require dirname(__DIR__, 6).'/vendor/autoload.php';

use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTagsPassUtils;

$target = dirname(__DIR__, 2).'/DependencyInjection/Compiler/UnusedTagsPass.php';
$contents = file_get_contents($target);
$contents = preg_replace('{private const KNOWN_TAGS = \[(.+?)\];}sm', "private const KNOWN_TAGS = [\n '".implode("',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents);
file_put_contents($target$contents);
$pass->process($container);

        $this->assertSame([sprintf('%s: Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?', UnusedTagsPass::class)]$container->getCompiler()->getLog());
    }

    public function testMissingKnownTags()
    {
        if (\dirname((new \ReflectionClass(ContainerBuilder::class))->getFileName(), 3) !== \dirname(__DIR__, 5)) {
            $this->markTestSkipped('Tests are not run from the root symfony/symfony metapackage.');
        }

        $this->assertSame(UnusedTagsPassUtils::getDefinedTags()$this->getKnownTags(), 'The src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php file must be updated; run src/Symfony/Bundle/FrameworkBundle/Resources/bin/check-unused-known-tags.php.');
    }

    private function getKnownTags(): array
    {
        $tags = \Closure::bind(
            fn () => UnusedTagsPass::KNOWN_TAGS,
            null,
            UnusedTagsPass::class
        D();
        sort($tags);

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