Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add more tests for patchEntity and patchEntities.
Include an integration test with the marshaller as only having mocks
isn't quite as thorough.

Refs #11556
  • Loading branch information
markstory committed Dec 18, 2017
1 parent 36b0890 commit c12ae0a
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -5654,7 +5654,7 @@ public function testGetExceptionOnTooMuchData()
*
* @return void
*/
public function testPatchEntity()
public function testPatchEntityMarshallerUsage()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['marshaller'])
Expand All @@ -5676,13 +5676,30 @@ public function testPatchEntity()
$table->patchEntity($entity, $data);
}

/**
* Tests patchEntity in a simple scenario. The tests for Marshaller cover
* patch scenarios in more depth.
*
* @return void
*/
public function testPatchEntity()
{
$table = TableRegistry::get('Articles');
$entity = new Entity(['title' => 'old title'], ['markNew' => false]);
$data = ['title' => 'new title'];
$entity = $table->patchEntity($entity, $data);

$this->assertSame($data['title'], $entity->title);
$this->assertFalse($entity->isNew(), 'entity should not be new.');
}

/**
* Tests that patchEntities delegates the task to the marshaller and passed
* all associations
*
* @return void
*/
public function testPatchEntities()
public function testPatchEntitiesMarshallerUsage()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['marshaller'])
Expand All @@ -5704,6 +5721,28 @@ public function testPatchEntities()
$table->patchEntities($entities, $data);
}

/**
* Tests patchEntities in a simple scenario. The tests for Marshaller cover
* patch scenarios in more depth.
*
* @return void
*/
public function testPatchEntities()
{
$table = TableRegistry::get('Articles');
$entities = $table->find()->limit(2)->toArray();

$data = [
['id' => $entities[0]->id, 'title' => 'new title'],
['id' => $entities[1]->id, 'title' => 'new title2'],
];
$entities = $table->patchEntities($entities, $data);
foreach ($entities as $i => $entity) {
$this->assertFalse($entity->isNew(), 'entities should not be new.');
$this->assertSame($data[$i]['title'], $entity->title);
}
}

/**
* Tests __debugInfo
*
Expand Down

0 comments on commit c12ae0a

Please sign in to comment.