Skip to content

Commit

Permalink
Duplicate removal testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Feb 14, 2024
1 parent 5d7912b commit dd449e9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
31 changes: 31 additions & 0 deletions tests/TestCase/Annotator/EntityAnnotatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_app/src/Model/Entity/PHP/Duplicates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace TestApp\Model\Entity\PHP;

use Cake\ORM\Entity;

/**
* @property int $id
* @property string $name
* @property string $content
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime|null $modified
* @property \Cake\I18n\Date $offer_date
* @property int $content
*/
class Duplicates extends Entity {
}
2 changes: 1 addition & 1 deletion tests/test_app/src/Model/Entity/PHP/Generics.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace TestApp\Model\Entity\PHP7;
namespace TestApp\Model\Entity\PHP;

use Cake\ORM\Entity;

Expand Down
15 changes: 15 additions & 0 deletions tests/test_files/Model/Entity/PHP/Duplicates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace TestApp\Model\Entity\PHP;

use Cake\ORM\Entity;

/**
* @property int $id
* @property string $name
* @property string $content
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime|null $modified
* @property \Cake\I18n\Date $offer_date
*/
class Duplicates extends Entity {
}
2 changes: 1 addition & 1 deletion tests/test_files/Model/Entity/PHP/Generics.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace TestApp\Model\Entity\PHP7;
namespace TestApp\Model\Entity\PHP;

use Cake\ORM\Entity;

Expand Down

0 comments on commit dd449e9

Please sign in to comment.