Skip to content

Commit

Permalink
Test for phalcon#13781
Browse files Browse the repository at this point in the history
  • Loading branch information
Németh Balázs committed May 17, 2019
1 parent e9b36c8 commit bea9220
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/integration/Mvc/Model/SaveCest.php
Expand Up @@ -21,6 +21,7 @@
use Phalcon\Test\Models\Robots;
use Phalcon\Test\Models\RobotsParts;
use Phalcon\Test\Models\Users;
use Phalcon\Mvc\Model\MetaData;

class SaveCest
{
Expand Down Expand Up @@ -247,4 +248,64 @@ public function mvcModelSaveAfterUsingRelatedGetters(IntegrationTester $I)

$I->assertTrue($album->save());
}

/**
* Tests Phalcon\Mvc\Model :: save() when default values are not set
*
* @see https://github.com/phalcon/cphalcon/issues/13781
*
* @author Balázs Németh <https://github.com/zsilbi>
* @since 2019-05-17
*/
public function mvcModelSaveAfterWithoutDefaultValues(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model - save() when default values are not set');

$robot = new Robots();

/**
* Default values are not set:
* 'year' => 1900,
* 'type' => "mechanical"
*/
$testData = [
'name' => 'Default Robot',
'datetime' => (new \DateTime())->format('Y-m-d'),
'text' => 'Test text',
];

$robot->assign($testData);

/**
* Verify that default values are not present
*/
$I->assertEquals(
$testData,
$robot->toArray()
);

$I->asserTrue($robot->save());

/**
* @var MetaData
*/
$metaData = $robot->getModelsMetaData();

/**
* @var array
*/
$defaultData = $metaData->getDefaultValues($robot);

$completeData = array_merge($defaultData, $testData);

$I->assertEquals(
$completeData,
$robot->toArray()
);

/**
* Cleanup
*/
$I->assertTrue($robot->delete());
}
}

0 comments on commit bea9220

Please sign in to comment.