Skip to content

Commit 3a6b586

Browse files
committed
Alias are not fetched, imroved coverage
1 parent c0d7ccc commit 3a6b586

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

Tag/TagFetcher.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public function fetch(FilterList $filters, $showPrivate = false)
2121
$definitions = $this->builder->getDefinitions();
2222

2323
foreach ($definitions as $definition) {
24-
if ($this->showOnyPublic($definition, $showPrivate)) {
25-
continue;
26-
}
27-
28-
if ($definition instanceof Alias) {
24+
if ($this->DontShowPrivate($definition, $showPrivate)) {
2925
continue;
3026
}
3127

@@ -35,9 +31,9 @@ public function fetch(FilterList $filters, $showPrivate = false)
3531
return $this->tags;
3632
}
3733

38-
private function showOnyPublic(Definition $definition, $showPrivate = false)
34+
private function DontShowPrivate(Definition $definition, $showPrivate = false)
3935
{
40-
if ($showPrivate && !$definition->isPublic()) {
36+
if (!$showPrivate && !$definition->isPublic()) {
4137
return true;
4238
}
4339

Tests/Tag/Filter/AttributeValueTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ public function testFilterByNotExistentAttribute()
2121
$attributeName = 'test';
2222
$string = 'value';
2323
$tag = new Tag('dummy_tag', array($attributeName => 'value'));
24-
$filter = new Filter\AttributeValue($attributeName, 'not-exists');
24+
$filter = new Filter\AttributeValue('fake-name', 'not-exists');
25+
$this->assertFalse($filter->isValid($tag));
26+
}
27+
28+
public function testFilterAttributeIsNotValid()
29+
{
30+
$attributeName = 'test';
31+
$string = 'value2';
32+
$tag = new Tag('dummy_tag', array($attributeName => 'value'));
33+
$filter = new Filter\AttributeValue($attributeName, $string);
2534
$this->assertFalse($filter->isValid($tag));
2635
}
2736
}

Tests/Tag/TagFetcherTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,58 @@ public function testFetchTagsFilteredWithMany()
7575
$this->assertCount(1, $tags);
7676
$this->assertCount(1, $tags['custom_tag_name']);
7777
}
78+
79+
public function testFetchTagsDefinitionHasNoTags()
80+
{
81+
$container = new ContainerBuilder();
82+
$container->register('dummy_service', 'Egulias\Tests\ServiceDummy');
83+
84+
$fetcher = new TagFetcher($container);
85+
86+
$filters = new FilterList();
87+
$filters->append(new Name('custom_tag_name'));
88+
$tags = $fetcher->fetch($filters);
89+
90+
$this->assertCount(0, $tags);
91+
}
92+
93+
public function testFetchTagsFromPublicDefinitionsOnly()
94+
{
95+
$container = new ContainerBuilder();
96+
$definition1 = $container->register('dummy_service', 'Egulias\Tests\ServiceDummy');
97+
$definition1
98+
->addTag('custom_tag_name', array('method' => 'name', 'number' => 8, 'another' => 'attribute'))
99+
->setPublic(true);
100+
$definition2 = $container->register('another_dummy_service', 'Egulias\Tests\Service2Dummy');
101+
$definition2
102+
->addTag('custom_tag_name', array('method' => 'name', 'number' => 10, 'another' => 'attribute'))
103+
->setPublic(false);
104+
105+
$fetcher = new TagFetcher($container);
106+
107+
$filters = new FilterList();
108+
$filters->append(new Name('custom_tag_name'));
109+
$tags = $fetcher->fetch($filters);
110+
111+
$this->assertCount(1, $tags);
112+
$this->assertCount(1, $tags['custom_tag_name']);
113+
}
114+
115+
public function testFetchTagsDefinitionIsAlias()
116+
{
117+
$container = new ContainerBuilder();
118+
$definition1 = $container->register('dummy_service', 'Egulias\Tests\ServiceDummy');
119+
$definition1
120+
->addTag('custom_tag_name', array('method' => 'name', 'number' => 8, 'another' => 'attribute'))
121+
->setPublic(true);
122+
$container->setAlias('alias_service', 'dummy_service');
123+
$fetcher = new TagFetcher($container);
124+
125+
$filters = new FilterList();
126+
$filters->append(new Name('custom_tag_name'));
127+
$tags = $fetcher->fetch($filters);
128+
129+
$this->assertCount(1, $tags);
130+
$this->assertCount(1, $tags['custom_tag_name']);
131+
}
78132
}

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
}
1313
],
1414
"require": {
15-
"symfony/event-dispatcher": "~2.3",
1615
"symfony/dependency-injection": "~2.3"
1716
},
1817
"require-dev": {

0 commit comments

Comments
 (0)