Skip to content

Commit 1b78e8a

Browse files
committed
Add more basic tests
1 parent f36e248 commit 1b78e8a

File tree

9 files changed

+628
-86
lines changed

9 files changed

+628
-86
lines changed

tests/Acceptance/BasicTagKindsTest.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/Acceptance/ClassesTest.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class ClassesTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itCreatesTagForTopLevelClass()
11+
{
12+
$this->givenSourceFile('TopLevelClassExample.php', <<<'EOS'
13+
<?php
14+
15+
class TestClass
16+
{
17+
public $publicProperty;
18+
protected $protectedProperty;
19+
private $privateProperty;
20+
21+
public function publicMethod()
22+
{
23+
}
24+
25+
protected function protectedMethod()
26+
{
27+
}
28+
29+
private function privateMethod()
30+
{
31+
}
32+
}
33+
EOS
34+
);
35+
36+
$this->runPHPCtags();
37+
38+
$this->assertTagsFileHeaderIsCorrect();
39+
$this->assertNumberOfTagsInTagsFileIs(7);
40+
$this->assertTagsFileContainsTag(
41+
'TopLevelClassExample.php',
42+
'TestClass',
43+
self::KIND_CLASS,
44+
3
45+
);
46+
$this->assertTagsFileContainsTag(
47+
'TopLevelClassExample.php',
48+
'publicProperty',
49+
self::KIND_PROPERTY,
50+
5,
51+
'class:TestClass',
52+
'access:public'
53+
);
54+
$this->assertTagsFileContainsTag(
55+
'TopLevelClassExample.php',
56+
'protectedProperty',
57+
self::KIND_PROPERTY,
58+
6,
59+
'class:TestClass',
60+
'access:protected'
61+
);
62+
$this->assertTagsFileContainsTag(
63+
'TopLevelClassExample.php',
64+
'privateProperty',
65+
self::KIND_PROPERTY,
66+
7,
67+
'class:TestClass',
68+
'access:private'
69+
);
70+
$this->assertTagsFileContainsTag(
71+
'TopLevelClassExample.php',
72+
'publicMethod',
73+
self::KIND_METHOD,
74+
9,
75+
'class:TestClass',
76+
'access:public'
77+
);
78+
$this->assertTagsFileContainsTag(
79+
'TopLevelClassExample.php',
80+
'protectedMethod',
81+
self::KIND_METHOD,
82+
13,
83+
'class:TestClass',
84+
'access:protected'
85+
);
86+
$this->assertTagsFileContainsTag(
87+
'TopLevelClassExample.php',
88+
'privateMethod',
89+
self::KIND_METHOD,
90+
17,
91+
'class:TestClass',
92+
'access:private'
93+
);
94+
}
95+
96+
/**
97+
* @test
98+
*/
99+
public function itAddsNamespacesToClassTags()
100+
{
101+
$this->givenSourceFile('MultiLevelNamespace.php', <<<'EOS'
102+
<?php
103+
104+
namespace Level1\Level2;
105+
106+
class TestClass
107+
{
108+
private $testProperty = 22;
109+
110+
function setProperty($value)
111+
{
112+
$this->testProperty = $value;
113+
}
114+
}
115+
EOS
116+
);
117+
118+
$this->runPHPCtags();
119+
120+
$this->assertTagsFileHeaderIsCorrect();
121+
$this->markTestIncomplete('Surely $this->varname shouldn\'t tag varname');
122+
$this->assertNumberOfTagsInTagsFileIs(4);
123+
$this->assertTagsFileContainsTag(
124+
'MultiLevelNamespace.php',
125+
'Level1\Level2',
126+
self::KIND_NAMESPACE,
127+
3
128+
);
129+
$this->assertTagsFileContainsTag(
130+
'MultiLevelNamespace.php',
131+
'TestClass',
132+
self::KIND_CLASS,
133+
5,
134+
'namespace:Level1\Level2'
135+
);
136+
$this->assertTagsFileContainsTag(
137+
'MultiLevelNamespace.php',
138+
'testProperty',
139+
self::KIND_PROPERTY,
140+
7,
141+
'class:Level1\Level2\TestClass',
142+
'access:private'
143+
);
144+
$this->assertTagsFileContainsTag(
145+
'MultiLevelNamespace.php',
146+
'setProperty',
147+
self::KIND_METHOD,
148+
9,
149+
'class:Level1\Level2\TestClass',
150+
'access:public'
151+
);
152+
}
153+
}

tests/Acceptance/ConstantsTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class ConstantsTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itCreatesTagFileForGlobalConstants()
11+
{
12+
$this->givenSourceFile('Constants.php', <<<'EOS'
13+
<?php
14+
15+
define('CONSTANT_1', 1);
16+
17+
const CONSTANT_2 = 2;
18+
EOS
19+
);
20+
21+
$this->runPHPCtags();
22+
23+
$this->assertTagsFileHeaderIsCorrect();
24+
$this->assertNumberOfTagsInTagsFileIs(2);
25+
$this->assertTagsFileContainsTag(
26+
'Constants.php',
27+
'CONSTANT_1',
28+
self::KIND_CONSTANT,
29+
3
30+
);
31+
$this->assertTagsFileContainsTag(
32+
'Constants.php',
33+
'CONSTANT_2',
34+
self::KIND_CONSTANT,
35+
5
36+
);
37+
}
38+
}

tests/Acceptance/FunctionsTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class FunctionsTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itCreatesTagForFunction()
11+
{
12+
$this->givenSourceFile('FunctionExample.php', <<<'EOS'
13+
<?php
14+
15+
function testFunction($a, $b)
16+
{
17+
}
18+
EOS
19+
);
20+
21+
$this->runPHPCtags();
22+
23+
$this->assertTagsFileHeaderIsCorrect();
24+
$this->assertNumberOfTagsInTagsFileIs(1);
25+
$this->assertTagsFileContainsTag(
26+
'FunctionExample.php',
27+
'testFunction',
28+
self::KIND_FUNCTION,
29+
3
30+
);
31+
}
32+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace tests\PHPCTags\Acceptance;
4+
5+
final class InterfacesTest extends AcceptanceTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function itCreatesTagForTopLevelInterface()
11+
{
12+
$this->givenSourceFile('InterfaceExample.php', <<<'EOS'
13+
<?php
14+
15+
interface TestInterface
16+
{
17+
public $publicProperty;
18+
19+
public function publicMethod();
20+
}
21+
EOS
22+
);
23+
24+
$this->runPHPCtags();
25+
26+
$this->assertTagsFileHeaderIsCorrect();
27+
$this->assertNumberOfTagsInTagsFileIs(3);
28+
$this->assertTagsFileContainsTag(
29+
'InterfaceExample.php',
30+
'TestInterface',
31+
self::KIND_INTERFACE,
32+
3
33+
);
34+
$this->assertTagsFileContainsTag(
35+
'InterfaceExample.php',
36+
'publicProperty',
37+
self::KIND_PROPERTY,
38+
5,
39+
'interface:TestInterface',
40+
'access:public'
41+
);
42+
$this->assertTagsFileContainsTag(
43+
'InterfaceExample.php',
44+
'publicMethod',
45+
self::KIND_METHOD,
46+
7,
47+
'interface:TestInterface',
48+
'access:public'
49+
);
50+
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function itAddsNamespacesToInterfaceTags()
56+
{
57+
$this->givenSourceFile('MultiLevelNamespace.php', <<<'EOS'
58+
<?php
59+
60+
namespace Level1\Level2;
61+
62+
interface TestInterface
63+
{
64+
public $testProperty;
65+
66+
function setProperty($value);
67+
}
68+
EOS
69+
);
70+
71+
$this->runPHPCtags();
72+
73+
$this->assertTagsFileHeaderIsCorrect();
74+
$this->assertNumberOfTagsInTagsFileIs(4);
75+
$this->assertTagsFileContainsTag(
76+
'MultiLevelNamespace.php',
77+
'Level1\Level2',
78+
self::KIND_NAMESPACE,
79+
3
80+
);
81+
$this->assertTagsFileContainsTag(
82+
'MultiLevelNamespace.php',
83+
'TestInterface',
84+
self::KIND_INTERFACE,
85+
5,
86+
'namespace:Level1\Level2'
87+
);
88+
$this->markTestIncomplete('Interface tag scopes are not fully qualified yet.');
89+
$this->assertTagsFileContainsTag(
90+
'MultiLevelNamespace.php',
91+
'testProperty',
92+
self::KIND_PROPERTY,
93+
7,
94+
'interface:Level1\Level2\TestInterface',
95+
'access:public'
96+
);
97+
$this->assertTagsFileContainsTag(
98+
'MultiLevelNamespace.php',
99+
'setProperty',
100+
self::KIND_METHOD,
101+
9,
102+
'interface:Level1\Level2\TestInterface',
103+
'access:public'
104+
);
105+
}
106+
}

0 commit comments

Comments
 (0)