From dd449e952ef3eea74f2f5b70381af4e376de3ed6 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 14 Feb 2024 14:43:11 +0100 Subject: [PATCH] Duplicate removal testing. --- .../Annotator/EntityAnnotatorTest.php | 31 +++++++++++++++++++ .../src/Model/Entity/PHP/Duplicates.php | 16 ++++++++++ .../src/Model/Entity/PHP/Generics.php | 2 +- .../Model/Entity/PHP/Duplicates.php | 15 +++++++++ .../test_files/Model/Entity/PHP/Generics.php | 2 +- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/test_app/src/Model/Entity/PHP/Duplicates.php create mode 100644 tests/test_files/Model/Entity/PHP/Duplicates.php 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 @@ +