Skip to content

Commit

Permalink
Merge branch '4.0.x' into model-callstatic-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
zsilbi authored Oct 14, 2019
2 parents b9d3602 + a26ad41 commit 6298372
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Changed
- Changed all calls to `new <object>` 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)
- Changed `Phalcon\Mvc\Model::__callStatic()` to throw an exception if the called method is unknown. [#14467](https://github.com/phalcon/cphalcon/pull/14467)
- Changed `Phalcon\Mvc\Model` to accept `0`, `null` and `""` as valid parameter for `findByField()`, `findFirstByField()` and `countByField()`. [#14467](https://github.com/phalcon/cphalcon/pull/14467)

Expand Down
6 changes: 3 additions & 3 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,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 @@ -1872,13 +1872,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();
}
);
}
}
23 changes: 19 additions & 4 deletions tests/integration/Mvc/Model/GetUpdatedFieldsCest.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 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();
}
);
}
}
25 changes: 0 additions & 25 deletions tests/integration/Mvc/Model/Refactor-SnapshotCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,31 +505,6 @@ public function testNewInstanceUpdate(IntegrationTester $I)
);
}

/**
* Tests get updated fields new instance exception
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @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
*
Expand Down

0 comments on commit 6298372

Please sign in to comment.