Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit b9d2f14

Browse files
committed
[GH-30] Fix tests
1 parent f29aa86 commit b9d2f14

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

features/fix_class_names.feature

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Feature: Fix Class Names
1818
| dir | src/ |
1919
Then the PHP File "src/Foo/Bar.php" should be refactored:
2020
"""
21-
--- a/Foo/Bar.php
22-
+++ b/Foo/Bar.php
21+
--- a/vfs://project/src/Foo/Bar.php
22+
+++ b/vfs://project/src/Foo/Bar.php
2323
@@ -2,5 +2,5 @@
2424
namespace Foo;
2525
@@ -44,8 +44,8 @@ Feature: Fix Class Names
4444
| dir | src/ |
4545
Then the PHP File "src/Foo/Bar.php" should be refactored:
4646
"""
47-
--- a/Foo/Bar.php
48-
+++ b/Foo/Bar.php
47+
--- a/vfs://project/src/Foo/Bar.php
48+
+++ b/vfs://project/src/Foo/Bar.php
4949
@@ -1,4 +1,4 @@
5050
<?php
5151
-namespace Baz;
@@ -73,17 +73,17 @@ Feature: Fix Class Names
7373
| dir | src/ |
7474
Then the PHP File "src/Foo.php" should be refactored:
7575
"""
76-
--- a/src/Foo/Bar.php
77-
+++ b/src/Foo/Bar.php
76+
--- a/vfs://project/src/src/Foo/Bar.php
77+
+++ b/vfs://project/src/src/Foo/Bar.php
7878
@@ -2,5 +2,5 @@
7979
namespace Foo;
8080
8181
-class Foo
8282
+class Bar
8383
{
8484
}
85-
--- a/Foo.php
86-
+++ b/Foo.php
85+
--- a/vfs://project/src/Foo.php
86+
+++ b/vfs://project/src/Foo.php
8787
@@ -1,2 +1,2 @@
8888
<?php
8989
-use Foo\Foo;
@@ -109,16 +109,16 @@ Feature: Fix Class Names
109109
| dir | src/ |
110110
Then the PHP File "src/Foo.php" should be refactored:
111111
"""
112-
--- a/src/Foo/Bar.php
113-
+++ b/src/Foo/Bar.php
112+
--- a/vfs://project/src/src/Foo/Bar.php
113+
+++ b/vfs://project/src/src/Foo/Bar.php
114114
@@ -1,4 +1,4 @@
115115
<?php
116116
-namespace Bar;
117117
+namespace Foo;
118118
119119
class Bar
120-
--- a/Foo.php
121-
+++ b/Foo.php
120+
--- a/vfs://project/src/Foo.php
121+
+++ b/vfs://project/src/Foo.php
122122
@@ -1,2 +1,2 @@
123123
<?php
124124
-use Bar\Bar;
@@ -145,17 +145,17 @@ Feature: Fix Class Names
145145
| dir | src/ |
146146
Then the PHP File "src/Foo.php" should be refactored:
147147
"""
148-
--- a/src/Foo/Bar.php
149-
+++ b/src/Foo/Bar.php
148+
--- a/vfs://project/src/src/Foo/Bar.php
149+
+++ b/vfs://project/src/src/Foo/Bar.php
150150
@@ -2,5 +2,5 @@
151151
namespace Foo;
152152
153153
-class Foo
154154
+class Bar
155155
{
156156
}
157-
--- a/Foo.php
158-
+++ b/Foo.php
157+
--- a/vfs://project/src/Foo.php
158+
+++ b/vfs://project/src/Foo.php
159159
@@ -1,2 +1,2 @@
160160
<?php
161161
-Foo\Foo::bar();
@@ -181,17 +181,17 @@ Feature: Fix Class Names
181181
| dir | src/ |
182182
Then the PHP File "src/Foo.php" should be refactored:
183183
"""
184-
--- a/src/Foo/Bar.php
185-
+++ b/src/Foo/Bar.php
184+
--- a/vfs://project/src/src/Foo/Bar.php
185+
+++ b/vfs://project/src/src/Foo/Bar.php
186186
@@ -2,5 +2,5 @@
187187
namespace Foo;
188188
189189
-class Foo
190190
+class Bar
191191
{
192192
}
193-
--- a/Foo.php
194-
+++ b/Foo.php
193+
--- a/vfs://project/src/Foo.php
194+
+++ b/vfs://project/src/Foo.php
195195
@@ -1,2 +1,2 @@
196196
<?php
197197
-new Foo\Foo();
@@ -221,26 +221,26 @@ Feature: Fix Class Names
221221
| dir | src/ |
222222
Then the PHP File "src/Foo.php" should be refactored:
223223
"""
224-
--- a/src/Foo/Bar.php
225-
+++ b/src/Foo/Bar.php
224+
--- a/vfs://project/src/src/Foo/Bar.php
225+
+++ b/vfs://project/src/src/Foo/Bar.php
226226
@@ -2,5 +2,5 @@
227227
namespace Foo;
228228
229229
-class Foo
230230
+class Bar
231231
{
232232
}
233-
--- a/Foo/src/Foo/Bar.php
234-
+++ b/Foo/src/Foo/Bar.php
233+
--- a/vfs://project/src/Foo/src/Foo/Bar.php
234+
+++ b/vfs://project/src/Foo/src/Foo/Bar.php
235235
@@ -2,5 +2,5 @@
236236
namespace Foo;
237237
238238
-class Foo
239239
+class Bar
240240
{
241241
}
242-
--- a/Foo/Baz.php
243-
+++ b/Foo/Baz.php
242+
--- a/vfs://project/src/Foo/Baz.php
243+
+++ b/vfs://project/src/Foo/Baz.php
244244
@@ -2,5 +2,5 @@
245245
namespace Foo;
246246
@@ -269,8 +269,8 @@ Feature: Fix Class Names
269269
| dir | src/ |
270270
Then the PHP File "src/Foo.php" should be refactored:
271271
"""
272-
--- a/src/Foo/Bar/Baz/Boing.php
273-
+++ b/src/Foo/Bar/Baz/Boing.php
272+
--- a/vfs://project/src/src/Foo/Bar/Baz/Boing.php
273+
+++ b/vfs://project/src/src/Foo/Bar/Baz/Boing.php
274274
@@ -1,6 +1,6 @@
275275
<?php
276276
-namespace Foo\Foo;
@@ -280,8 +280,8 @@ Feature: Fix Class Names
280280
+class Boing
281281
{
282282
}
283-
--- a/index.php
284-
+++ b/index.php
283+
--- a/vfs://project/src/index.php
284+
+++ b/vfs://project/src/index.php
285285
@@ -1,2 +1,2 @@
286286
<?php
287287
-$foo = new \Foo\Foo\Foo();
@@ -308,8 +308,8 @@ Feature: Fix Class Names
308308
| dir | src/ |
309309
Then the PHP File "src/Foo.php" should be refactored:
310310
"""
311-
--- a/src/Foo/Boing.php
312-
+++ b/src/Foo/Boing.php
311+
--- a/vfs://project/src/src/Foo/Boing.php
312+
+++ b/vfs://project/src/src/Foo/Boing.php
313313
@@ -1,6 +1,6 @@
314314
<?php
315315
-namespace Foo\Foo;
@@ -319,8 +319,8 @@ Feature: Fix Class Names
319319
+class Boing
320320
{
321321
}
322-
--- a/index.php
323-
+++ b/index.php
322+
--- a/vfs://project/src/index.php
323+
+++ b/vfs://project/src/index.php
324324
@@ -1,2 +1,2 @@
325325
<?php
326326
-$foo = new \Foo\Foo\Foo();

src/main/QafooLabs/Refactoring/Domain/Model/File.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ private function parseFileForPsr0ClassShortName()
9292

9393
private function parseFileForPsr0NamespaceName()
9494
{
95+
$file = ltrim($this->getRelativePath(), DIRECTORY_SEPARATOR);
96+
97+
if (preg_match('(^([a-z]+:\/\/))', $file, $matches)) {
98+
$file = substr($file, strlen($matches[1]));
99+
}
100+
95101
$parts = explode(DIRECTORY_SEPARATOR, ltrim($this->getRelativePath(), DIRECTORY_SEPARATOR));
96102
$namespace = array();
97103

@@ -111,7 +117,7 @@ private function parseFileForPsr0NamespaceName()
111117

112118
private function startsWithLowerCase($string)
113119
{
114-
return strtolower($string[0]) === $string[0];
120+
return isset($string[0]) && strtolower($string[0]) === $string[0];
115121
}
116122
}
117123

src/test/QafooLabs/Refactoring/Domain/Model/DirectoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
66
{
77
public function testFindAllPhpFilesRecursivly()
88
{
9-
$directory = new Directory(__DIR__);
9+
$directory = new Directory(__DIR__, __DIR__);
1010
$files = $directory->findAllPhpFilesRecursivly();
1111

1212
$this->assertContainsOnly('QafooLabs\Refactoring\Domain\Model\File', $files);

0 commit comments

Comments
 (0)