diff --git a/tests/TestCase/Annotator/EntityAnnotatorTest.php b/tests/TestCase/Annotator/EntityAnnotatorTest.php index 0b77700d..e9943216 100644 --- a/tests/TestCase/Annotator/EntityAnnotatorTest.php +++ b/tests/TestCase/Annotator/EntityAnnotatorTest.php @@ -432,6 +432,37 @@ public function testAnnotateWithGenericUsage() { $this->assertTextContains(' -> 1 annotation added, 1 annotation updated', $output); } + /** + * @return void + */ + public function testAnnotateWithDuplicates() { + /** @var \TestApp\Model\Table\FoosTable $Table */ + $Table = TableRegistry::getTableLocator()->get('Foos'); + + $schema = $Table->getSchema(); + $associations = $Table->associations(); + $annotator = $this->_getAnnotatorMock(['schema' => $schema, 'associations' => $associations]); + + $expectedContent = str_replace(["\r\n", "\r"], "\n", file_get_contents(TEST_FILES . 'Model/Entity/PHP/Duplicates.php')); + $callback = function ($value) use ($expectedContent) { + $value = str_replace(["\r\n", "\r"], "\n", $value); + if ($value !== $expectedContent) { + $this->_displayDiff($expectedContent, $value); + } + + return $value === $expectedContent; + }; + $annotator->expects($this->once())->method('storeFile')->with($this->anything(), $this->callback($callback)); + + $path = APP . 'Model/Entity/PHP/Duplicates.php'; + + $annotator->annotate($path); + + $output = $this->out->output(); + + $this->assertTextContains(' -> 1 annotation removed', $output); + } + /** * @param array $params * @return \IdeHelper\Annotator\EntityAnnotator|\PHPUnit\Framework\MockObject\MockObject diff --git a/tests/test_app/src/Model/Entity/PHP/Duplicates.php b/tests/test_app/src/Model/Entity/PHP/Duplicates.php new file mode 100644 index 00000000..aad8e058 --- /dev/null +++ b/tests/test_app/src/Model/Entity/PHP/Duplicates.php @@ -0,0 +1,16 @@ +