-
-
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
6 changed files
with
269 additions
and
0 deletions.
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
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 <team@phalcon.io> | ||
* | ||
* 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 <team@phalcon.io> | ||
* | ||
* 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 <team@phalcon.io> | ||
* @since 2023-08-11 | ||
* | ||
* @issue https://github.com/phalcon/cphalcon/issues/16343 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function DynamicUpdateSystemWideEnabled(DatabaseTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Model - DynamicUpdate Systeam 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, $connection) use ($collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLStatement() . json_encode($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 = 'UPDATE `co_customers` SET `cst_name_last` = ? WHERE `cst_id` = ?["cst_test_lastName","' . $customer->cst_id . '"]'; | ||
$actual = $collection->get('0'); | ||
$I->assertSame($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: save() with DynamicUpdate Disabled | ||
* | ||
* @author Phalcon Team <team@phalcon.io> | ||
* @since 2023-08-11 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function DynamicUpdateSystemWideDisabled(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, $connection) use ($collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLStatement() . json_encode($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 = 'UPDATE `co_customers` SET `cst_status_flag` = null, `cst_name_last` = ?, `cst_name_first` = ? WHERE `cst_id` = ?["cst_test_lastName","cst_test_firstName","' . $customer->cst_id . '"]'; | ||
$actual = $collection->get('0'); | ||
$I->assertSame($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: save() with DynamicUpdate Disabled Cherry pick | ||
* | ||
* @author Phalcon Team <team@phalcon.io> | ||
* @since 2023-08-11 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function DynamicUpdateSystemWideDisabledCherryPick(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, $connection) use ($collection) { | ||
$key = (string) $collection->count(); | ||
$collection->set($key, $connection->getSQLStatement() . json_encode($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(); | ||
|
||
$expected = 'UPDATE `co_customers` SET `cst_name_last` = ? WHERE `cst_id` = ?["cst_test_lastName","' . $customer->cst_id . '"]'; | ||
$actual = $collection->get('0'); | ||
$I->assertSame($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