public function redis(UnitTester $I) { $I->wantTo('fetch metadata from memory'); /** @var \Phalcon\Mvc\Model\MetaDataInterface $md */ $md = $I->grabServiceFromDi('modelsMetadata'); $md->reset(); $I->assertTrue($md->isEmpty()); Robots::findFirst(); $I->assertFalse($md->isEmpty()); $md->reset(); $I->assertTrue($md->isEmpty()); }
public function memcached(UnitTester $I) { $I->wantTo('fetch metadata from memcached cache'); /** @var \Phalcon\Mvc\Model\MetaDataInterface $md */ $md = $I->grabServiceFromDi('modelsMetadata'); $md->reset(); $I->assertTrue($md->isEmpty()); Robots::findFirst(); $I->assertEquals($this->data['meta-robots-robots'], $md->read("meta-phalcon\\test\\models\\robots-robots")); $I->assertEquals($this->data['map-robots'], $md->read("map-phalcon\\test\\models\\robots")); $I->assertFalse($md->isEmpty()); $md->reset(); $I->assertTrue($md->isEmpty()); }
public function redis(UnitTester $I) { $I->wantTo('fetch metadata from session'); /** @var \Phalcon\Mvc\Model\MetaDataInterface $md */ $md = $I->grabServiceFromDi('modelsMetadata'); $md->reset(); $I->assertTrue($md->isEmpty()); Robots::findFirst(); $I->assertEquals($this->data['meta-robots-robots'], $_SESSION['$PMM$app']["meta-phalcon\\test\\models\\robots-robots"]); $I->assertEquals($this->data['map-robots'], $_SESSION['$PMM$app']["map-phalcon\\test\\models\\robots"]); $I->assertFalse($md->isEmpty()); $md->reset(); $I->assertTrue($md->isEmpty()); }
public function files(UnitTester $I) { $I->wantTo('fetch metadata from file cache'); /** @var \Phalcon\Mvc\Model\MetaDataInterface $md */ $md = $I->grabServiceFromDi('modelsMetadata'); $md->reset(); $I->assertTrue($md->isEmpty()); Robots::findFirst(); $I->amInPath(PATH_CACHE); $I->seeFileFound('meta-phalcon_test_models_robots-robots.php'); $I->assertEquals($this->data['meta-robots-robots'], require PATH_CACHE . 'meta-phalcon_test_models_robots-robots.php'); $I->seeFileFound('map-phalcon_test_models_robots.php'); $I->assertEquals($this->data['map-robots'], require PATH_CACHE . 'map-phalcon_test_models_robots.php'); $I->assertFalse($md->isEmpty()); $md->reset(); $I->assertTrue($md->isEmpty()); $I->deleteFile('meta-phalcon_test_models_robots-robots.php'); $I->deleteFile('map-phalcon_test_models_robots.php'); }
public function testJsonSerialize() { $this->specify("Single models aren't JSON serialized or JSON unserialized properly", function () { // Single model object json serialization $robot = Robots::findFirst(); $json = json_encode($robot); expect(is_string($json))->true(); expect(strlen($json) > 10)->true(); // make sure result is not "{ }" expect($robot->toArray())->equals(json_decode($json, true)); }); $this->specify("Model resultsets aren't JSON serialized or JSON unserialized properly", function () { // Result-set serialization $robots = Robots::find(); $json = json_encode($robots); expect(is_string($json))->true(); expect(strlen($json) > 50)->true(); // make sure result is not "{ }" expect($robots->toArray())->equals(json_decode($json, true)); }); $this->specify("Single row resultsets aren't JSON serialized or JSON unserialized properly", function () { $robot = Robots::findFirst(); // Single row serialization $result = $this->modelsManager->executeQuery("SELECT id FROM " . Robots::class . " LIMIT 1"); expect($result)->isInstanceOf('Phalcon\\Mvc\\Model\\Resultset\\Simple'); foreach ($result as $row) { expect($row)->isInstanceOf('Phalcon\\Mvc\\Model\\Row'); expect($row->id)->equals($robot->id); $json = json_encode($row); expect(is_string($json))->true(); expect(strlen($json) > 5)->true(); // make sure result is not "{ }" expect($row->toArray())->equals(json_decode($json, true)); } }); }