4
4
5
5
use InvalidArgumentException ;
6
6
use PhpSchool \PhpWorkshop \Solution \DirectorySolution ;
7
+ use PhpSchool \PhpWorkshop \TestUtils \SolutionPathTransformer ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
9
10
class DirectorySolutionTest extends TestCase
@@ -32,18 +33,23 @@ public function testWithDefaultEntryPoint(): void
32
33
33
34
$ solution = DirectorySolution::fromDirectory ($ tempPath );
34
35
35
- $ this ->assertSame ($ tempPath , $ solution ->getBaseDirectory ());
36
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
37
+
38
+ $ this ->assertSame ($ expectedBaseDir , $ solution ->getBaseDirectory ());
36
39
$ this ->assertFalse ($ solution ->hasComposerFile ());
37
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ solution ->getEntryPoint ());
40
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
38
41
$ files = $ solution ->getFiles ();
39
42
$ this ->assertCount (2 , $ files );
40
43
41
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ files [0 ]->__toString ());
42
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
44
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
45
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
43
46
47
+ unlink (sprintf ('%s/solution.php ' , $ expectedBaseDir ));
48
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
44
49
unlink (sprintf ('%s/solution.php ' , $ tempPath ));
45
50
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
46
51
rmdir ($ tempPath );
52
+ rmdir ($ expectedBaseDir );
47
53
}
48
54
49
55
public function testWithManualEntryPoint (): void
@@ -55,18 +61,23 @@ public function testWithManualEntryPoint(): void
55
61
56
62
$ solution = DirectorySolution::fromDirectory ($ tempPath , [], 'index.php ' );
57
63
58
- $ this ->assertSame ($ tempPath , $ solution ->getBaseDirectory ());
64
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
65
+
66
+ $ this ->assertSame ($ expectedBaseDir , $ solution ->getBaseDirectory ());
59
67
$ this ->assertFalse ($ solution ->hasComposerFile ());
60
- $ this ->assertSame (sprintf ('%s/index.php ' , $ tempPath ), $ solution ->getEntryPoint ());
68
+ $ this ->assertSame (sprintf ('%s/index.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
61
69
$ files = $ solution ->getFiles ();
62
70
$ this ->assertCount (2 , $ files );
63
71
64
- $ this ->assertSame (sprintf ('%s/index.php ' , $ tempPath ), $ files [0 ]->__toString ());
65
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
72
+ $ this ->assertSame (sprintf ('%s/index.php ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
73
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
66
74
75
+ unlink (sprintf ('%s/index.php ' , $ expectedBaseDir ));
76
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
67
77
unlink (sprintf ('%s/index.php ' , $ tempPath ));
68
78
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
69
79
rmdir ($ tempPath );
80
+ rmdir ($ expectedBaseDir );
70
81
}
71
82
72
83
public function testHasComposerFileReturnsTrueIfPresent (): void
@@ -79,15 +90,20 @@ public function testHasComposerFileReturnsTrueIfPresent(): void
79
90
80
91
$ solution = DirectorySolution::fromDirectory ($ tempPath );
81
92
82
- $ this ->assertSame ($ tempPath , $ solution ->getBaseDirectory ());
93
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
94
+
95
+ $ this ->assertSame ($ expectedBaseDir , $ solution ->getBaseDirectory ());
83
96
$ this ->assertTrue ($ solution ->hasComposerFile ());
84
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ solution ->getEntryPoint ());
97
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
85
98
$ files = $ solution ->getFiles ();
86
99
$ this ->assertCount (2 , $ files );
87
100
88
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ files [0 ]->__toString ());
89
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
101
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
102
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
90
103
104
+ unlink (sprintf ('%s/composer.lock ' , $ expectedBaseDir ));
105
+ unlink (sprintf ('%s/solution.php ' , $ expectedBaseDir ));
106
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
91
107
unlink (sprintf ('%s/composer.lock ' , $ tempPath ));
92
108
unlink (sprintf ('%s/solution.php ' , $ tempPath ));
93
109
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
@@ -105,17 +121,23 @@ public function testWithExceptions(): void
105
121
106
122
$ solution = DirectorySolution::fromDirectory ($ tempPath , $ exclusions );
107
123
108
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ solution ->getEntryPoint ());
124
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
125
+
126
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
109
127
$ files = $ solution ->getFiles ();
110
128
$ this ->assertCount (2 , $ files );
111
129
112
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ files [0 ]->__toString ());
113
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
130
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
131
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
114
132
133
+ unlink (sprintf ('%s/solution.php ' , $ expectedBaseDir ));
134
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
135
+ unlink (sprintf ('%s/exclude.txt ' , $ expectedBaseDir ));
115
136
unlink (sprintf ('%s/solution.php ' , $ tempPath ));
116
137
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
117
138
unlink (sprintf ('%s/exclude.txt ' , $ tempPath ));
118
139
rmdir ($ tempPath );
140
+ rmdir ($ expectedBaseDir );
119
141
}
120
142
121
143
public function testWithNestedDirectories (): void
@@ -134,15 +156,17 @@ public function testWithNestedDirectories(): void
134
156
135
157
$ solution = DirectorySolution::fromDirectory ($ tempPath );
136
158
137
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ solution ->getEntryPoint ());
159
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
160
+
161
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
138
162
$ files = $ solution ->getFiles ();
139
163
$ this ->assertCount (5 , $ files );
140
164
141
- $ this ->assertSame (sprintf ('%s/composer.json ' , $ tempPath ), $ files [0 ]->__toString ());
142
- $ this ->assertSame (sprintf ('%s/nested/another-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
143
- $ this ->assertSame (sprintf ('%s/nested/deep/even-more.php ' , $ tempPath ), $ files [2 ]->__toString ());
144
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ files [3 ]->__toString ());
145
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [4 ]->__toString ());
165
+ $ this ->assertSame (sprintf ('%s/composer.json ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
166
+ $ this ->assertSame (sprintf ('%s/nested/another-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
167
+ $ this ->assertSame (sprintf ('%s/nested/deep/even-more.php ' , $ expectedBaseDir ), $ files [2 ]->__toString ());
168
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ files [3 ]->__toString ());
169
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [4 ]->__toString ());
146
170
147
171
unlink (sprintf ('%s/solution.php ' , $ tempPath ));
148
172
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
@@ -152,6 +176,14 @@ public function testWithNestedDirectories(): void
152
176
rmdir (sprintf ('%s/nested/deep ' , $ tempPath ));
153
177
rmdir (sprintf ('%s/nested ' , $ tempPath ));
154
178
rmdir ($ tempPath );
179
+ unlink (sprintf ('%s/solution.php ' , $ expectedBaseDir ));
180
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
181
+ unlink (sprintf ('%s/composer.json ' , $ expectedBaseDir ));
182
+ unlink (sprintf ('%s/nested/another-class.php ' , $ expectedBaseDir ));
183
+ unlink (sprintf ('%s/nested/deep/even-more.php ' , $ expectedBaseDir ));
184
+ rmdir (sprintf ('%s/nested/deep ' , $ expectedBaseDir ));
185
+ rmdir (sprintf ('%s/nested ' , $ expectedBaseDir ));
186
+ rmdir ($ expectedBaseDir );
155
187
}
156
188
157
189
public function testExceptionsWithNestedDirectories (): void
@@ -175,12 +207,14 @@ public function testExceptionsWithNestedDirectories(): void
175
207
176
208
$ solution = DirectorySolution::fromDirectory ($ tempPath , $ exclusions );
177
209
178
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ solution ->getEntryPoint ());
210
+ $ expectedBaseDir = SolutionPathTransformer::tempPathToSolutionTempPath ($ tempPath );
211
+
212
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ solution ->getEntryPoint ());
179
213
$ files = $ solution ->getFiles ();
180
214
$ this ->assertCount (2 , $ files );
181
215
182
- $ this ->assertSame (sprintf ('%s/solution.php ' , $ tempPath ), $ files [0 ]->__toString ());
183
- $ this ->assertSame (sprintf ('%s/some-class.php ' , $ tempPath ), $ files [1 ]->__toString ());
216
+ $ this ->assertSame (sprintf ('%s/solution.php ' , $ expectedBaseDir ), $ files [0 ]->__toString ());
217
+ $ this ->assertSame (sprintf ('%s/some-class.php ' , $ expectedBaseDir ), $ files [1 ]->__toString ());
184
218
185
219
unlink (sprintf ('%s/solution.php ' , $ tempPath ));
186
220
unlink (sprintf ('%s/some-class.php ' , $ tempPath ));
@@ -193,5 +227,16 @@ public function testExceptionsWithNestedDirectories(): void
193
227
rmdir (sprintf ('%s/vendor/somelib ' , $ tempPath ));
194
228
rmdir (sprintf ('%s/vendor ' , $ tempPath ));
195
229
rmdir ($ tempPath );
230
+ unlink (sprintf ('%s/solution.php ' , $ expectedBaseDir ));
231
+ unlink (sprintf ('%s/some-class.php ' , $ expectedBaseDir ));
232
+ unlink (sprintf ('%s/exclude.txt ' , $ expectedBaseDir ));
233
+ unlink (sprintf ('%s/nested/exclude.txt ' , $ expectedBaseDir ));
234
+ unlink (sprintf ('%s/nested/deep/exclude.txt ' , $ expectedBaseDir ));
235
+ unlink (sprintf ('%s/vendor/somelib/app.php ' , $ expectedBaseDir ));
236
+ rmdir (sprintf ('%s/nested/deep ' , $ expectedBaseDir ));
237
+ rmdir (sprintf ('%s/nested ' , $ expectedBaseDir ));
238
+ rmdir (sprintf ('%s/vendor/somelib ' , $ expectedBaseDir ));
239
+ rmdir (sprintf ('%s/vendor ' , $ expectedBaseDir ));
240
+ rmdir ($ expectedBaseDir );
196
241
}
197
242
}
0 commit comments