-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #16343, DynamicUpdate is now enabled system wide
- Loading branch information
Showing
7 changed files
with
270 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Tests\Models; | ||
|
||
use Phalcon\Mvc\Model; | ||
|
||
/** | ||
* Class CustomersKeepSnapshots | ||
* | ||
* @property int $cst_id; | ||
* @property int $cst_status_flag; | ||
* @property string $cst_name_last; | ||
* @property string $cst_name_first; | ||
*/ | ||
class CustomersDymanicUpdate extends Model | ||
{ | ||
public $cst_id; | ||
public $cst_status_flag; | ||
public $cst_name_last; | ||
public $cst_name_first; | ||
|
||
public function initialize() | ||
{ | ||
$this->useDynamicUpdate(true); | ||
$this->setSource('co_customers'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Tests\Integration\Mvc\Model; | ||
|
||
use DatabaseTester; | ||
use Phalcon\Events\Event; | ||
use Phalcon\Events\Manager; | ||
use Phalcon\Support\Collection; | ||
use Phalcon\Tests\Fixtures\Traits\DiTrait; | ||
use Phalcon\Tests\Models\Customers; | ||
use Phalcon\Tests\Models\CustomersDymanicUpdate; | ||
|
||
class DynamicUpdateCest | ||
{ | ||
use DiTrait; | ||
|
||
public function _before(DatabaseTester $I) | ||
{ | ||
$this->setNewFactoryDefault(); | ||
$this->setDatabase($I); | ||
} | ||
|
||
public function _after(DatabaseTester $I) | ||
{ | ||
$this->container['db']->close(); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: save() With DynamicUpdate Enabled | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2023-08-11 | ||
* | ||
* @issue https://github.com/phalcon/cphalcon/issues/16343 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function enableDynamicUpdate(DatabaseTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Model - DynamicUpdate System Wide Enabled'); | ||
|
||
/** | ||
* Check system wide Dynamic update | ||
*/ | ||
$actual = ini_get('phalcon.orm.dynamic_update'); | ||
$I->assertEquals("1", $actual); | ||
|
||
|
||
$collection = new Collection(); | ||
$connection = $this->container->get('db'); | ||
$manager = new Manager(); | ||
$modelsManager = $this->container->get('modelsManager'); | ||
$manager->attach( | ||
'db:beforeQuery', function (Event $event) use ($connection, $collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLVariables()); | ||
} | ||
); | ||
|
||
$connection->setEventsManager($manager); | ||
|
||
/** | ||
* New model | ||
*/ | ||
$customer = new Customers(); | ||
$I->assertTrue($modelsManager->isUsingDynamicUpdate($customer)); | ||
$customer->cst_name_first = 'cst_test_firstName'; | ||
|
||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
$collection->clear(); | ||
|
||
$customer->cst_name_last = 'cst_test_lastName'; | ||
|
||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
|
||
$expected = 2; | ||
$actual = count($collection->get('0')); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: save() with DynamicUpdate Disabled | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2023-08-11 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function disableDynamicUpdate(DatabaseTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Model - DynamicUpdate Systeam Wide Disabled'); | ||
$collection = new Collection(); | ||
|
||
$connection = $this->container->get('db'); | ||
$manager = new Manager(); | ||
$modelsManager = $this->container->get('modelsManager'); | ||
$manager->attach( | ||
'db:beforeQuery', function (Event $event) use ($connection, $collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLVariables()); | ||
} | ||
); | ||
|
||
$connection->setEventsManager($manager); | ||
|
||
/** | ||
* Disable system wide dynamic update | ||
*/ | ||
ini_set('phalcon.orm.dynamic_update', 0); | ||
|
||
/** | ||
* Check system wide Dynamic update | ||
*/ | ||
$actual = ini_get('phalcon.orm.dynamic_update'); | ||
|
||
$I->assertEquals("0", $actual); | ||
|
||
/** | ||
* New model | ||
*/ | ||
$customer = new Customers(); | ||
|
||
$I->assertFalse($modelsManager->isUsingDynamicUpdate($customer)); | ||
$customer->cst_name_first = 'cst_test_firstName'; | ||
|
||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
$collection->clear(); | ||
|
||
$customer->cst_name_last = 'cst_test_lastName'; | ||
|
||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
|
||
$expected = 3; | ||
$actual = count($collection->get('0')); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: save() with DynamicUpdate Disabled Cherry pick | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2023-08-11 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function disabledCherryPickDynamicUpdate(DatabaseTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Model - DynamicUpdate Systeam Wide Disabled Cherry pick'); | ||
|
||
$collection = new Collection(); | ||
$connection = $this->container->get('db'); | ||
$manager = new Manager(); | ||
$modelsManager = $this->container->get('modelsManager'); | ||
$manager->attach( | ||
'db:beforeQuery', function (Event $event) use ($connection, $collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLVariables()); | ||
} | ||
); | ||
|
||
$connection->setEventsManager($manager); | ||
|
||
/** | ||
* Disable system wide dynamic update | ||
*/ | ||
ini_set('phalcon.orm.dynamic_update', 0); | ||
|
||
/** | ||
* Check system wide Dynamic update | ||
*/ | ||
$actual = ini_get('phalcon.orm.dynamic_update'); | ||
$I->assertEquals("0", $actual); | ||
|
||
/** | ||
* New model | ||
*/ | ||
$customer = new CustomersDymanicUpdate(); | ||
$I->assertTrue($modelsManager->isUsingDynamicUpdate($customer)); | ||
$customer->cst_name_first = 'cst_test_firstName'; | ||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
$collection->clear(); | ||
|
||
$customer->cst_name_last = 'cst_test_lastName'; | ||
$actual = $customer->save(); | ||
$I->assertTrue($actual); | ||
|
||
$expected = 2; | ||
$actual = count($collection->get('0')); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters