Skip to content

Commit d7efbc7

Browse files
committed
Complete coverage of basic tag generation
1 parent 1b78e8a commit d7efbc7

File tree

7 files changed

+254
-21
lines changed

7 files changed

+254
-21
lines changed

tests/Acceptance/AcceptanceTestCase.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ protected function runPHPCtags()
6969
$this->tagsFileContent = $output;
7070
}
7171

72+
/**
73+
* @param string $patterns
74+
*
75+
* @return void
76+
*/
77+
protected function runPHPCtagsWithExcludes(array $patterns)
78+
{
79+
$entryPoint = realpath(__DIR__ . '/../../bootstrap.php');
80+
81+
$excludes = implode(
82+
' ',
83+
array_map(function ($pattern) {
84+
return '--exclude=\'' . $pattern . '\'';
85+
}, $patterns)
86+
);
87+
88+
exec("php \"$entryPoint\" --recurse=yes -f - $excludes {$this->testDir}", $output);
89+
90+
$this->tagsFileContent = $output;
91+
}
92+
7293
/**
7394
* @return void
7495
*/
@@ -125,6 +146,28 @@ protected function assertTagsFileContainsTag(
125146
);
126147
}
127148

149+
150+
/**
151+
* @param string $filename
152+
*
153+
* @return void
154+
*/
155+
public function assertTagsFileContainsNoTagsFromFile($filename)
156+
{
157+
$filename = $this->testDir . DIRECTORY_SEPARATOR . $filename;
158+
159+
$tags = array_filter(
160+
$this->tagsFileContent,
161+
function ($line) use ($filename) {
162+
$fields = explode("\t", $line);
163+
164+
return $fields[1] === $filename;
165+
}
166+
);
167+
168+
$this->assertEmpty($tags, "Tags for $filename were found in tag file.");
169+
}
170+
128171
/**
129172
* @return void
130173
*/
@@ -175,7 +218,7 @@ private function createTagLine($filename, $name, $kind, $line, $scope, $access)
175218
self::KIND_NAMESPACE => 'namespace',
176219
);
177220

178-
if(!empty($define['access'])) {
221+
if(!empty($access)) {
179222
$access = 'access:' . $access;
180223
}
181224

tests/Acceptance/ClassesTest.php

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,47 +49,47 @@ private function privateMethod()
4949
self::KIND_PROPERTY,
5050
5,
5151
'class:TestClass',
52-
'access:public'
52+
'public'
5353
);
5454
$this->assertTagsFileContainsTag(
5555
'TopLevelClassExample.php',
5656
'protectedProperty',
5757
self::KIND_PROPERTY,
5858
6,
5959
'class:TestClass',
60-
'access:protected'
60+
'protected'
6161
);
6262
$this->assertTagsFileContainsTag(
6363
'TopLevelClassExample.php',
6464
'privateProperty',
6565
self::KIND_PROPERTY,
6666
7,
6767
'class:TestClass',
68-
'access:private'
68+
'private'
6969
);
7070
$this->assertTagsFileContainsTag(
7171
'TopLevelClassExample.php',
7272
'publicMethod',
7373
self::KIND_METHOD,
7474
9,
7575
'class:TestClass',
76-
'access:public'
76+
'public'
7777
);
7878
$this->assertTagsFileContainsTag(
7979
'TopLevelClassExample.php',
8080
'protectedMethod',
8181
self::KIND_METHOD,
8282
13,
8383
'class:TestClass',
84-
'access:protected'
84+
'protected'
8585
);
8686
$this->assertTagsFileContainsTag(
8787
'TopLevelClassExample.php',
8888
'privateMethod',
8989
self::KIND_METHOD,
9090
17,
9191
'class:TestClass',
92-
'access:private'
92+
'private'
9393
);
9494
}
9595

@@ -139,15 +139,78 @@ function setProperty($value)
139139
self::KIND_PROPERTY,
140140
7,
141141
'class:Level1\Level2\TestClass',
142-
'access:private'
142+
'private'
143143
);
144144
$this->assertTagsFileContainsTag(
145145
'MultiLevelNamespace.php',
146146
'setProperty',
147147
self::KIND_METHOD,
148148
9,
149149
'class:Level1\Level2\TestClass',
150-
'access:public'
150+
'public'
151+
);
152+
}
153+
154+
/**
155+
* @test
156+
* @group bugfix3
157+
*/
158+
public function itTagsMagicMethods()
159+
{
160+
$this->givenSourceFile('DbConnectionUserDecorator.php', <<<'EOS'
161+
<?php
162+
class DbConnectionUserDecorator {
163+
public function __set($key, $value) {
164+
$this->conn->$key = $value;
165+
}
166+
}
167+
EOS
168+
);
169+
170+
$this->runPHPCtags();
171+
172+
$this->assertTagsFileHeaderIsCorrect();
173+
$this->assertNumberOfTagsInTagsFileIs(2);
174+
$this->assertTagsFileContainsTag(
175+
'DbConnectionUserDecorator.php',
176+
'DbConnectionUserDecorator',
177+
self::KIND_CLASS,
178+
2
179+
);
180+
$this->assertTagsFileContainsTag(
181+
'DbConnectionUserDecorator.php',
182+
'__set',
183+
self::KIND_METHOD,
184+
3,
185+
'class:DbConnectionUserDecorator',
186+
'public'
187+
);
188+
}
189+
190+
/**
191+
* @test
192+
* @group bugfix7
193+
*/
194+
public function itTagsClassInsideConditional()
195+
{
196+
$this->givenSourceFile('MultiLevelNamespace.php', <<<'EOS'
197+
<?php
198+
if (!class_exists('MyClass')) {
199+
class MyClass {
200+
}
201+
}
202+
EOS
203+
);
204+
205+
$this->runPHPCtags();
206+
207+
$this->assertTagsFileHeaderIsCorrect();
208+
$this->assertNumberOfTagsInTagsFileIs(1);
209+
$this->assertTagsFileContainsTag(
210+
'MultiLevelNamespace.php',
211+
'MyClass',
212+
self::KIND_CLASS,
213+
3
151214
);
152215
}
153216
}

tests/Acceptance/ConstantsTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,40 @@ public function itCreatesTagFileForGlobalConstants()
3535
5
3636
);
3737
}
38+
39+
/**
40+
* @test
41+
*/
42+
public function itCreatesTagFileForNamespacedConstants()
43+
{
44+
$this->givenSourceFile('Constants.php', <<<'EOS'
45+
<?php
46+
47+
namespace Level1\Level2;
48+
49+
define('CONSTANT_1', 1);
50+
51+
const CONSTANT_2 = 2;
52+
EOS
53+
);
54+
55+
$this->runPHPCtags();
56+
57+
$this->assertTagsFileHeaderIsCorrect();
58+
$this->assertNumberOfTagsInTagsFileIs(3);
59+
$this->assertTagsFileContainsTag(
60+
'Constants.php',
61+
'CONSTANT_1',
62+
self::KIND_CONSTANT,
63+
5,
64+
'namespace:Level1\Level2'
65+
);
66+
$this->assertTagsFileContainsTag(
67+
'Constants.php',
68+
'CONSTANT_2',
69+
self::KIND_CONSTANT,
70+
7,
71+
'namespace:Level1\Level2'
72+
);
73+
}
3874
}

tests/Acceptance/ExcludeTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class ExcludeTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itExcludesFileByName()
11+
{
12+
$this->givenSourceFile('File1.php', <<<'EOS'
13+
<?php
14+
15+
$test = 1;
16+
EOS
17+
);
18+
19+
$this->givenSourceFile('File2.php', <<<'EOS'
20+
<?php
21+
22+
$test = 1;
23+
EOS
24+
);
25+
26+
$this->runPHPCtagsWithExcludes(array('File2.php'));
27+
28+
$this->assertTagsFileHeaderIsCorrect();
29+
$this->assertTagsFileContainsNoTagsFromFile('File2.php');
30+
}
31+
32+
/**
33+
* @test
34+
*/
35+
public function itExcludesFileByPatter()
36+
{
37+
$this->givenSourceFile('File.php', <<<'EOS'
38+
<?php
39+
40+
$test = 1;
41+
EOS
42+
);
43+
44+
$this->givenSourceFile('File.skip.php', <<<'EOS'
45+
<?php
46+
47+
$test = 1;
48+
EOS
49+
);
50+
51+
$this->markTestIncomplete('Pattern matching currently doesn\'t appear to work');
52+
$this->runPHPCtagsWithExcludes(array('*.skip.php'));
53+
54+
$this->assertTagsFileHeaderIsCorrect();
55+
$this->assertTagsFileContainsNoTagsFromFile('File.skip.php');
56+
}
57+
}

tests/Acceptance/InterfacesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public function publicMethod();
3737
self::KIND_PROPERTY,
3838
5,
3939
'interface:TestInterface',
40-
'access:public'
40+
'public'
4141
);
4242
$this->assertTagsFileContainsTag(
4343
'InterfaceExample.php',
4444
'publicMethod',
4545
self::KIND_METHOD,
4646
7,
4747
'interface:TestInterface',
48-
'access:public'
48+
'public'
4949
);
5050
}
5151

@@ -92,15 +92,15 @@ function setProperty($value);
9292
self::KIND_PROPERTY,
9393
7,
9494
'interface:Level1\Level2\TestInterface',
95-
'access:public'
95+
'public'
9696
);
9797
$this->assertTagsFileContainsTag(
9898
'MultiLevelNamespace.php',
9999
'setProperty',
100100
self::KIND_METHOD,
101101
9,
102102
'interface:Level1\Level2\TestInterface',
103-
'access:public'
103+
'public'
104104
);
105105
}
106106
}

0 commit comments

Comments
 (0)