1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace phpDocumentor\Configuration; |
6
|
|
|
|
7
|
|
|
use BadMethodCallException; |
8
|
|
|
use phpDocumentor\Faker\Faker; |
9
|
|
|
use phpDocumentor\Path; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @coversDefaultClass \phpDocumentor\Configuration\Source |
14
|
|
|
*/ |
15
|
|
|
final class SourceTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
use Faker; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @uses \phpDocumentor\Dsn |
21
|
|
|
* |
22
|
|
|
* @covers ::__construct |
23
|
|
|
* @covers ::dsn |
24
|
|
|
*/ |
25
|
|
|
public function testSourceReturnsDsn() : void |
26
|
|
|
{ |
27
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
28
|
|
|
$source = new Source($dsn, []); |
29
|
|
|
|
30
|
|
|
self::assertSame($dsn, $source->dsn()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @uses \phpDocumentor\Dsn |
35
|
|
|
* |
36
|
|
|
* @covers ::__construct |
37
|
|
|
* @covers ::dsn |
38
|
|
|
* @covers ::withDsn |
39
|
|
|
*/ |
40
|
|
|
public function testWithDsnReturnsNewInstanceOfSource() : void |
41
|
|
|
{ |
42
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
43
|
|
|
$source = new Source($dsn, []); |
44
|
|
|
|
45
|
|
|
$newSource = $source->withDsn($dsn); |
46
|
|
|
|
47
|
|
|
self::assertEquals($newSource, $source); |
48
|
|
|
self::assertNotSame($newSource, $source); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @uses \phpDocumentor\Dsn |
53
|
|
|
* |
54
|
|
|
* @covers ::__construct |
55
|
|
|
* @covers ::dsn |
56
|
|
|
* @covers ::withDsn |
57
|
|
|
*/ |
58
|
|
|
public function testWithDsnReturnsSetsNewDsn() : void |
59
|
|
|
{ |
60
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
61
|
|
|
$source = new Source($dsn, []); |
62
|
|
|
|
63
|
|
|
$newDsn = $this->faker()->dsn(); |
64
|
|
|
$newSource = $source->withDsn($newDsn); |
65
|
|
|
|
66
|
|
|
self::assertSame($newDsn, $newSource->dsn()); |
67
|
|
|
self::assertSame($dsn, $source->dsn()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers ::__construct |
72
|
|
|
* @covers ::offsetGet |
73
|
|
|
*/ |
74
|
|
|
public function testSourceImplementsArrayAccess() : void |
75
|
|
|
{ |
76
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
77
|
|
|
$paths = [ |
78
|
|
|
$this->faker->path(), |
79
|
|
|
$this->faker->path(), |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$source = new Source($dsn, $paths); |
83
|
|
|
|
84
|
|
|
self::assertSame($dsn, $source['dsn']); |
85
|
|
|
self::assertSame($paths, $source['paths']); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers ::__construct |
90
|
|
|
* @covers ::offsetSet |
91
|
|
|
*/ |
92
|
|
|
public function testSourceArrayAccessIsImmutableCannotSet() : void |
93
|
|
|
{ |
94
|
|
|
$this->expectException(BadMethodCallException::class); |
95
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
96
|
|
|
$paths = [ |
97
|
|
|
$this->faker->path(), |
98
|
|
|
$this->faker->path(), |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
$source = new Source($dsn, $paths); |
102
|
|
|
|
103
|
|
|
$source['paths'] = []; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @covers ::__construct |
108
|
|
|
* @covers ::offsetUnset |
109
|
|
|
*/ |
110
|
|
|
public function testSourceArrayAccessIsImmutableCannotUnset() : void |
111
|
|
|
{ |
112
|
|
|
$this->expectException(BadMethodCallException::class); |
113
|
|
|
$dsn = $this->faker()->dsn(); |
|
|
|
|
114
|
|
|
$paths = [ |
115
|
|
|
$this->faker->path(), |
116
|
|
|
$this->faker->path(), |
117
|
|
|
]; |
118
|
|
|
|
119
|
|
|
$source = new Source($dsn, $paths); |
120
|
|
|
|
121
|
|
|
unset($source['paths']); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @dataProvider pathProvider |
126
|
|
|
* @covers ::__construct |
127
|
|
|
* @covers ::globPatterns |
128
|
|
|
* @covers ::<private> |
129
|
|
|
*/ |
130
|
|
|
public function testSourceGlobPathsNormalizesPaths(Path $input, string $glob) : void |
131
|
|
|
{ |
132
|
|
|
$source = new Source($this->faker()->dsn(), [$input]); |
|
|
|
|
133
|
|
|
|
134
|
|
|
self::assertEquals([$glob], $source->globPatterns()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function pathProvider() : array |
138
|
|
|
{ |
139
|
|
|
return [ |
140
|
|
|
[ |
141
|
|
|
new Path('src'), |
142
|
|
|
'/src/**/*', |
143
|
|
|
], |
144
|
|
|
[ |
145
|
|
|
new Path('.'), |
146
|
|
|
'/**/*', |
147
|
|
|
], |
148
|
|
|
[ |
149
|
|
|
new Path('./src'), |
150
|
|
|
'/src/**/*', |
151
|
|
|
], |
152
|
|
|
[ |
153
|
|
|
new Path('/src/*'), |
154
|
|
|
'/src/*', |
155
|
|
|
], |
156
|
|
|
[ |
157
|
|
|
new Path('src/dir/test.php'), |
158
|
|
|
'/src/dir/test.php', |
159
|
|
|
], |
160
|
|
|
]; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: