-
-
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.
Merge pull request #16421 from rudiservo/i16420
Fix #16420, fixed metadata get column from cache adapters, added tests
- Loading branch information
Showing
11 changed files
with
479 additions
and
24 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
namespace Phalcon\Tests\Database\Mvc\Model\MetaData; | ||
|
||
use Codeception\Example; | ||
use DatabaseTester; | ||
use Phalcon\Mvc\Model\MetaData; | ||
use Phalcon\Tests\Fixtures\Traits\DiTrait; | ||
|
@@ -34,17 +35,34 @@ public function _before(DatabaseTester $I) | |
/** | ||
* Tests Phalcon\Mvc\Model\MetaData :: getAttributes() | ||
* | ||
* @dataProvider getExamples | ||
* | ||
* @param DatabaseTester $I | ||
* @param Example $example | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2020-02-01 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function mvcModelMetadataGetAttributes(DatabaseTester $I) | ||
{ | ||
public function mvcModelMetadataGetAttributes( | ||
DatabaseTester $I, | ||
Example $example | ||
) { | ||
$I->wantToTest('Mvc\Model\MetaData - getAttributes()'); | ||
|
||
$service = $example['service']; | ||
|
||
$adapter = $this->newService($service); | ||
$connection = $I->getConnection(); | ||
$adapter->setDi($this->container); | ||
|
||
$adapter->reset(); | ||
|
||
$this->container->setShared('modelsMetadata', $adapter); | ||
|
||
/** @var MetaData $metadata */ | ||
$metadata = $this->container->get('modelsMetadata'); | ||
|
||
|
@@ -59,5 +77,39 @@ public function mvcModelMetadataGetAttributes(DatabaseTester $I) | |
]; | ||
$actual = $metadata->getAttributes($model); | ||
$I->assertEquals($expected, $actual); | ||
|
||
$adapter = $this->newService($service); | ||
$this->container->setShared('modelsMetadata', $adapter); | ||
$adapter->setDi($this->container); | ||
|
||
$I->assertNotEquals($adapter, $metadata); | ||
|
||
$actual = $adapter->getAttributes($model); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
private function getExamples(): array | ||
{ | ||
return [ | ||
[ | ||
'service' => 'metadataMemory', | ||
'className' => 'Memory', | ||
], | ||
[ | ||
'service' => 'metadataApcu', | ||
'className' => 'Apcu', | ||
], | ||
[ | ||
'service' => 'metadataRedis', | ||
'className' => 'Redis', | ||
], | ||
[ | ||
'service' => 'metadataLibmemcached', | ||
'className' => 'Libmemcached', | ||
], | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
namespace Phalcon\Tests\Database\Mvc\Model\MetaData; | ||
|
||
use Codeception\Example; | ||
use DatabaseTester; | ||
use Phalcon\Mvc\Model\MetaData; | ||
use Phalcon\Storage\Exception; | ||
|
@@ -47,7 +48,10 @@ public function _before(DatabaseTester $I): void | |
/** | ||
* Tests Phalcon\Mvc\Model\MetaData :: getColumnMap() | ||
* | ||
* @param DatabaseTester $I | ||
* @dataProvider getExamples | ||
* | ||
* @param DatabaseTester $I | ||
* @param Example $example | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2020-02-01 | ||
|
@@ -56,10 +60,22 @@ public function _before(DatabaseTester $I): void | |
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function mvcModelMetadataGetColumnMap(DatabaseTester $I) | ||
{ | ||
public function mvcModelMetadataGetColumnMap( | ||
DatabaseTester $I, | ||
Example $example | ||
) { | ||
$I->wantToTest('Mvc\Model\MetaData - getColumnMap()'); | ||
|
||
$service = $example['service']; | ||
|
||
$adapter = $this->newService($service); | ||
$adapter->setDi($this->container); | ||
$connection = $I->getConnection(); | ||
|
||
$adapter->reset(); | ||
|
||
$this->container->setShared('modelsMetadata', $adapter); | ||
|
||
/** @var MetaData $metadata */ | ||
$metadata = $this->container->get('modelsMetadata'); | ||
$model = new Invoices(); | ||
|
@@ -77,5 +93,45 @@ public function mvcModelMetadataGetColumnMap(DatabaseTester $I) | |
]; | ||
|
||
$I->assertEquals($expected, $metadata->getColumnMap($model)); | ||
|
||
$I->assertTrue($adapter->isEmpty()); | ||
|
||
/** | ||
* Double check it can get from cache systems and not memory | ||
*/ | ||
$adapter = $this->newService($service); | ||
$this->container->setShared('modelsMetadata', $adapter); | ||
$adapter->setDi($this->container); | ||
|
||
$I->assertNotEquals($adapter, $metadata); | ||
|
||
$I->assertTrue($adapter->isEmpty()); | ||
|
||
$I->assertEquals($expected, $adapter->getColumnMap($model)); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
private function getExamples(): array | ||
{ | ||
return [ | ||
[ | ||
'service' => 'metadataMemory', | ||
'className' => 'Memory', | ||
], | ||
[ | ||
'service' => 'metadataApcu', | ||
'className' => 'Apcu', | ||
], | ||
[ | ||
'service' => 'metadataRedis', | ||
'className' => 'Redis', | ||
], | ||
[ | ||
'service' => 'metadataLibmemcached', | ||
'className' => 'Libmemcached', | ||
], | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
namespace Phalcon\Tests\Database\Mvc\Model\MetaData; | ||
|
||
use Codeception\Example; | ||
use DatabaseTester; | ||
use Phalcon\Mvc\Model\MetaData; | ||
use Phalcon\Tests\Fixtures\Traits\DiTrait; | ||
|
@@ -34,24 +35,58 @@ public function _before(DatabaseTester $I) | |
/** | ||
* Tests Phalcon\Mvc\Model\MetaData :: getDataTypes() | ||
* | ||
* @dataProvider getExamples | ||
* | ||
* @param DatabaseTester $I | ||
* @param Example $example | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2020-02-01 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function mvcModelMetadataGetDataTypes(DatabaseTester $I) | ||
{ | ||
public function mvcModelMetadataGetDataTypes( | ||
DatabaseTester $I, | ||
Example $example | ||
) { | ||
$I->wantToTest('Mvc\Model\MetaData - getDataTypes()'); | ||
|
||
$service = $example['service']; | ||
|
||
$adapter = $this->newService($service); | ||
$adapter->setDi($this->container); | ||
$connection = $I->getConnection(); | ||
|
||
$adapter->reset(); | ||
$I->assertTrue($adapter->isEmpty()); | ||
|
||
$this->container->setShared('modelsMetadata', $adapter); | ||
|
||
/** @var MetaData $metadata */ | ||
$metadata = $this->container->get('modelsMetadata'); | ||
|
||
$model = new Invoices(); | ||
$expected = $this->getTypes($I); | ||
$actual = $metadata->getDataTypes($model); | ||
$I->assertEquals($expected, $actual); | ||
|
||
$I->assertFalse($adapter->isEmpty()); | ||
|
||
/** | ||
* Double check it can get from cache systems and not memory | ||
*/ | ||
$adapter = $this->newService($service); | ||
$this->container->setShared('modelsMetadata', $adapter); | ||
$adapter->setDi($this->container); | ||
|
||
$I->assertNotEquals($adapter, $metadata); | ||
|
||
$I->assertTrue($adapter->isEmpty()); | ||
|
||
$actual = $adapter->getDataTypes($model); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
private function getTypes(DatabaseTester $I) | ||
|
@@ -87,4 +122,29 @@ private function getTypes(DatabaseTester $I) | |
]; | ||
} | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
private function getExamples(): array | ||
{ | ||
return [ | ||
[ | ||
'service' => 'metadataMemory', | ||
'className' => 'Memory', | ||
], | ||
[ | ||
'service' => 'metadataApcu', | ||
'className' => 'Apcu', | ||
], | ||
[ | ||
'service' => 'metadataRedis', | ||
'className' => 'Redis', | ||
], | ||
[ | ||
'service' => 'metadataLibmemcached', | ||
'className' => 'Libmemcached', | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.