Phalcon\Test\Unit\Mvc\ModelTest::testSerializeSnapshotCache PHP Method

testSerializeSnapshotCache() public method

The snapshot should be saved while using cache
Since: 2016-08-26
Author: Wojciech Ĺšlawski ([email protected])
    public function testSerializeSnapshotCache()
    {
        if (!extension_loaded('apc')) {
            $this->markTestSkipped('Warning: apc extension is not loaded');
        }
        if (!ini_get('apc.enabled') || PHP_SAPI === 'cli' && !ini_get('apc.enable_cli')) {
            $this->markTestSkipped('Warning: apc.enable_cli must be set to "On"');
        }
        if (extension_loaded('apcu') && version_compare(phpversion('apcu'), '5.1.6', '=')) {
            throw new \PHPUnit_Framework_SkippedTestError('Warning: APCu v5.1.6 was broken. See: https://github.com/krakjoe/apcu/issues/203');
        }
        $this->specify('Snapshot data should be saved while saving model to cache', function () {
            $cache = new Apc(new Data(['lifetime' => 20]));
            $robot = Robots::findFirst();
            expect($robot)->isInstanceOf(Robots::class);
            expect($robot->getSnapshotData())->notEmpty();
            $cache->save('robot', $robot);
            /** @var Robots $robot */
            $robot = $cache->get('robot');
            expect($robot)->isInstanceOf(Robots::class);
            expect($robot->getSnapshotData())->notEmpty();
            expect($robot->getSnapshotData())->equals($robot->toArray());
            $robot->text = 'abc';
            $cache->save('robot', $robot);
            /** @var Robots $robot */
            $robot = $cache->get('robot');
            expect($robot)->isInstanceOf(Robots::class);
            expect($robot->getSnapshotData())->notEmpty();
            expect($robot->getSnapshotData())->notEquals($robot->toArray());
        });
    }