From 31d678a9fabffdc56b20ec9c8a1a7ac649417b1f Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Mon, 14 Oct 2019 09:07:43 -0400 Subject: [PATCH 1/4] [#14466] - Changed the exception text; Added tests --- phalcon/Mvc/Model.zep | 6 ++--- .../Mvc/Model/GetChangedFieldsCest.php | 23 ++++++++++++++---- .../Mvc/Model/GetUpdatedFieldsCest.php | 24 +++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/phalcon/Mvc/Model.zep b/phalcon/Mvc/Model.zep index 3cacc0fa703..93153933e3e 100644 --- a/phalcon/Mvc/Model.zep +++ b/phalcon/Mvc/Model.zep @@ -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" ); } @@ -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" ); } diff --git a/tests/integration/Mvc/Model/GetChangedFieldsCest.php b/tests/integration/Mvc/Model/GetChangedFieldsCest.php index 76841a8671d..5023457ac42 100644 --- a/tests/integration/Mvc/Model/GetChangedFieldsCest.php +++ b/tests/integration/Mvc/Model/GetChangedFieldsCest.php @@ -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 * @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(); + } + ); } } diff --git a/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php b/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php index 72962c92983..57d7770e3b4 100644 --- a/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php +++ b/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php @@ -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 * @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(); + } + ); + } } From badb43af10252423c628c7242df5c01c599270e1 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Mon, 14 Oct 2019 10:19:51 -0400 Subject: [PATCH 2/4] [#14466] - Corrected test --- .../Mvc/Model/Refactor-SnapshotCest.php | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/tests/integration/Mvc/Model/Refactor-SnapshotCest.php b/tests/integration/Mvc/Model/Refactor-SnapshotCest.php index 11f660e27a1..9a5e3d767d5 100644 --- a/tests/integration/Mvc/Model/Refactor-SnapshotCest.php +++ b/tests/integration/Mvc/Model/Refactor-SnapshotCest.php @@ -505,31 +505,6 @@ public function testNewInstanceUpdate(IntegrationTester $I) ); } - /** - * Tests get updated fields new instance exception - * - * @author Wojciech Ĺšlawski - * @since 2017-03-28 - */ - public function testUpdatedFieldsNewException(IntegrationTester $I) - { - $I->expectThrowable( - new Exception("The record doesn't have a valid data snapshot"), - function () { - $robots = new Robots( - [ - 'name' => 'test', - 'year' => 2017, - 'datetime' => (new DateTime())->format('Y-m-d'), - 'text' => 'asd', - ] - ); - - $robots->getUpdatedFields(); - } - ); - } - /** * Tests get updated fields deleted instance exception * From 052deb35ca6e8d4d8c6f5744387e09ffb52b864c Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Mon, 14 Oct 2019 10:36:25 -0400 Subject: [PATCH 3/4] [#14466] - Updated the changelog [ci-skip] --- CHANGELOG-4.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md index b5c2f3cd75c..b142a882672 100644 --- a/CHANGELOG-4.0.md +++ b/CHANGELOG-4.0.md @@ -4,6 +4,7 @@ ## Changed - Changed all calls to `new ` to use the `create_instance` or `create_instance_params` for better performance. [#14419](https://github.com/phalcon/cphalcon/pull/14419) +- Changed the exception text for `Phalcon\Mvc\Model::getChangedFields` and `Phalcon\Mvc\Model::getUpdatedFields` when there is no snapshot setup [#14468](https://github.com/phalcon/cphalcon/pull/14468) ## Fixed - Fixed `Phalcon\Mvc\View\Engine\Volt\Compiler::parse()` Corrected syntax recognize for "set" keyword. [#14288](https://github.com/phalcon/cphalcon/issues/14288) From a26ad417465a34fcfb8929eb08e9018e5a956717 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Mon, 14 Oct 2019 11:09:26 -0400 Subject: [PATCH 4/4] [#14466] - PHPCS fix --- tests/integration/Mvc/Model/GetUpdatedFieldsCest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php b/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php index 57d7770e3b4..55fcd539bb3 100644 --- a/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php +++ b/tests/integration/Mvc/Model/GetUpdatedFieldsCest.php @@ -44,6 +44,5 @@ function () { $fields = $robot ->getUpdatedFields(); } ); - } }