8000 [FrameworkBundle] do not stumble upon empty tags by xabbuh · Pull Request #16932 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] do not stumble upon empty tags #16932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ public function process(ContainerBuilder $container)

// check for typos
$candidates = array();
foreach ($tags as $definedTag) {
if ($definedTag === $tag) {
continue;
}

if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= strlen($tag) / 3) {
$candidates[] = $definedTag;
if (null !== $tag && '' !== $tag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findUnusedTags has @return string[]. So $tag can never be null.

foreach ($tags as $definedTag) {
if ($definedTag === $tag) {
continue;
}

if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= strlen($tag) / 3) {
$candidates[] = $definedTag;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;

use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UnusedTagsPassTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -49,4 +50,23 @@ public function testProcess()

$pass->process($container);
}

public function testEmptyTagNameIsIgnored()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is missing as assertion which is not good practice

{
$pass = new UnusedTagsPass();

$container = new ContainerBuilder();
$definition = $container->register('foo');
$definition->addTag('', array('bar' => 'baz'));
$definition->addTag('foo');

$pass->process($container);

$this->assertMessageIsLogged($container, 'Tag "foo" was defined on service(s) "foo", but was never used.');
}

private function assertMessageIsLogged(ContainerBuilder $container, $message)
{
$this->assertContains('Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass: '.$message, $container->getCompiler()->getLog());
}
}
0