Skip to content

Commit

Permalink
[#14466] - Changed the exception text; Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Oct 14, 2019
1 parent 86ed6b2 commit 31d678a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
6 changes: 3 additions & 3 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,

if unlikely typeof snapshot != "array" {
throw new Exception(
"The record doesn't have a valid data snapshot"
"The 'keepSnapshots' option must be enabled to track changes"
);
}

Expand Down Expand Up @@ -1855,13 +1855,13 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,

if unlikely !globals_get("orm.update_snapshot_on_save") {
throw new Exception(
"Update snapshot on save must be enabled for this method to work properly"
"The 'updateSnapshotOnSave' option must be enabled for this method to work properly"
);
}

if unlikely typeof snapshot != "array" {
throw new Exception(
"The record doesn't have a valid data snapshot"
"The 'keepSnapshots' option must be enabled to track changes"
);
}

Expand Down
23 changes: 19 additions & 4 deletions tests/integration/Mvc/Model/GetChangedFieldsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,36 @@
namespace Phalcon\Test\Integration\Mvc\Model;

use IntegrationTester;
use Phalcon\Mvc\Model\Exception;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\Robots;

/**
* Class GetChangedFieldsCest
*/
class GetChangedFieldsCest
{
use DiTrait;

/**
* Tests Phalcon\Mvc\Model :: getChangedFields()
* Tests Phalcon\Mvc\Model :: getChangedFields() - keepSnapshots
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
*/
public function mvcModelGetChangedFields(IntegrationTester $I)
public function mvcModelGetChangedFieldsKeepSnapshots(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model - getChangedFields()');
$I->skipTest('Need implementation');
$I->wantToTest('Mvc\Model - getChangedFields() - keepSnapshots');
$this->setNewFactoryDefault();
$this->setDiMysql();
$I->expectThrowable(
new Exception(
"The 'keepSnapshots' option must be enabled to track changes"
),
function () {
$robot = Robots::findFirst();
$fields = $robot->getChangedFields();
}
);
}
}
24 changes: 20 additions & 4 deletions tests/integration/Mvc/Model/GetUpdatedFieldsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,37 @@
namespace Phalcon\Test\Integration\Mvc\Model;

use IntegrationTester;
use Phalcon\Mvc\Model\Exception;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\Robots;

/**
* Class GetUpdatedFieldsCest
*/
class GetUpdatedFieldsCest
{
use DiTrait;

/**
* Tests Phalcon\Mvc\Model :: getUpdatedFields()
* Tests Phalcon\Mvc\Model :: getUpdatedFields() - keepSnapshots
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
*/
public function mvcModelGetUpdatedFields(IntegrationTester $I)
public function mvcModelGetUpdatedFieldsKeepSnapshots(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model - getUpdatedFields()');
$I->skipTest('Need implementation');
$I->wantToTest('Mvc\Model - getUpdatedFields() - keepSnapshots');
$this->setNewFactoryDefault();
$this->setDiMysql();
$I->expectThrowable(
new Exception(
"The 'keepSnapshots' option must be enabled to track changes"
),
function () {
$robot = Robots::findFirst();
$fields = $robot ->getUpdatedFields();
}
);

}
}

0 comments on commit 31d678a

Please sign in to comment.