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

Commit 0a48b2a

Browse files
committed
First attempt to fix #19
1 parent cd82368 commit 0a48b2a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function change(PhpName $from, PhpName $to)
6565
return $this;
6666
}
6767

68+
if ($this->equals($from)) {
69+
return $to;
70+
}
71+
6872
$toParts = explode("\\", $to->fullyQualifiedName);
6973
$thisParts = explode("\\", $this->fullyQualifiedName);
7074

@@ -100,4 +104,10 @@ public function relativeName()
100104
{
101105
return $this->relativeName;
102106
}
107+
108+
public function equals(PhpName $other)
109+
{
110+
return $this->fullyQualifiedName === $other->fullyQualifiedName &&
111+
$this->relativeName === $other->relativeName;
112+
}
103113
}

src/test/QafooLabs/Refactoring/Adapters/PHPParser/ParserPhpNameScannerTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ public function testFindNames()
1717
array(
1818
new PhpName('QafooLabs\Refactoring\Domain\Model\File', 'QafooLabs\Refactoring\Domain\Model\File', $file, 5),
1919
new PhpName('QafooLabs\Refactoring\Domain\Model\PhpName', 'QafooLabs\Refactoring\Domain\Model\PhpName', $file, 6),
20+
new PhpName('QafooLabs\Refactoring\Adapters\PHPParser\PHPUnit_Framework_TestCase', 'PHPUnit_Framework_TestCase', $file, 8),
2021
new PhpName('QafooLabs\Refactoring\Domain\Model\File', 'File', $file, 12),
2122
new PhpName('QafooLabs\Refactoring\Adapters\PHPParser\ParserPhpNameScanner', 'ParserPhpNameScanner', $file, 13),
2223
),
23-
array_slice($names, 0, 4)
24+
array_slice($names, 0, 5)
2425
);
2526
}
2627
}
28+

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

+12
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,16 @@ public function testRegression2()
6969
$this->assertEquals('Foo\\Bar', $changed->fullyQualifiedName());
7070
$this->assertEquals('Foo\\Bar', $changed->relativeName());
7171
}
72+
73+
public function testRegression3()
74+
{
75+
$name = new PhpName("Foo\\Foo", "Foo\\Foo", null, null);
76+
$from = new PhpName("Foo\\Foo", "Foo\\Foo", null, null);
77+
$to = new PhpName("Foo\\Bar\\Foo", "Foo\\Bar\\Foo", null, null);
78+
79+
$changed = $name->change($from, $to);
80+
81+
$this->assertEquals('Foo\\Bar\\Foo', $changed->fullyQualifiedName());
82+
$this->assertEquals('Foo\\Bar\\Foo', $changed->relativeName());
83+
}
7284
}

0 commit comments

Comments
 (0)