Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several missing APC and XCache tests #865

Merged
merged 3 commits into from Jul 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions unit-tests/AnnotationsAdaptersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

require_once 'annotations/TestClass.php';
require_once 'annotations/TestClassNs.php';
require_once 'helpers/xcache.php';

class AnnotationsAdaptersTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -79,4 +80,65 @@ public function testFilesAdapter()
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');
}

public function testApcAdapter()
{
if (!function_exists('apc_fetch')) {
$this->markTestSkipped('apc not loaded');
return;
}

$adapter = new Phalcon\Annotations\Adapter\Apc();

$classAnnotations = $adapter->get('TestClass');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('TestClass');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('User\TestClassNs');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('User\TestClassNs');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');
}


public function testXcacheAdapter()
{
if (!function_exists('xcache_get')) {
$this->markTestSkipped('xcache not loaded');
return;
}

$adapter = new Phalcon\Annotations\Adapter\Xcache();

$classAnnotations = $adapter->get('TestClass');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('TestClass');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('User\TestClassNs');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');

$classAnnotations = $adapter->get('User\TestClassNs');
$this->assertTrue(is_object($classAnnotations));
$this->assertEquals(get_class($classAnnotations), 'Phalcon\Annotations\Reflection');
$this->assertEquals(get_class($classAnnotations->getClassAnnotations()), 'Phalcon\Annotations\Collection');
}

}
10 changes: 6 additions & 4 deletions unit-tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
+------------------------------------------------------------------------+
*/

require_once 'helpers/xcache.php';

class CacheTest extends PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -356,7 +358,7 @@ public function testDataMemcachedCache()
protected function _prepareApc()
{

if (!extension_loaded('apc')) {
if (!function_exists('apc_fetch')) {
$this->markTestSkipped('apc extension is not loaded');
return false;
}
Expand Down Expand Up @@ -585,6 +587,9 @@ public function _testDataMongoCache()

protected function _prepareXcache()
{
if (function_exists('xcache_emulation')) {
return true;
}

if (!extension_loaded('xcache') || 'cli' == PHP_SAPI) {
$this->markTestSkipped('xcache extension is not loaded');
Expand Down Expand Up @@ -647,12 +652,10 @@ public function testOutputXcache()

//Delete entry from cache
$this->assertTrue($cache->delete('test-output'));

}

public function testDataXcache()
{

$ready = $this->_prepareXcache();
if (!$ready) {
return false;
Expand All @@ -677,6 +680,5 @@ public function testDataXcache()
$this->assertEquals($cachedContent, "sure, nothing interesting");

$this->assertTrue($cache->delete('test-data'));

}
}
40 changes: 39 additions & 1 deletion unit-tests/ModelsMetadataAdaptersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
+------------------------------------------------------------------------+
*/

require_once 'helpers/xcache.php';

class ModelsMetadataAdaptersTest extends PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -164,7 +166,7 @@ public function testMetadataSession()
public function testMetadataApc()
{

if (!extension_loaded('apc')) {
if (!function_exists('apc_fetch')) {
$this->markTestSkipped('apc extension is not loaded');
return false;
}
Expand Down Expand Up @@ -197,6 +199,42 @@ public function testMetadataApc()

}

public function testMetadataXcache()
{

if (!function_exists('xcache_get')) {
$this->markTestSkipped('xcache extension is not loaded');
return false;
}

xcache_unset('$PMM$my-local-app');

$di = $this->_getDI();

$di->set('modelsMetadata', function(){
return new Phalcon\Mvc\Model\Metadata\Xcache(array(
'prefix' => 'my-local-app',
'lifetime' => 60
));
});

$metaData = $di->getShared('modelsMetadata');

$metaData->reset();

$this->assertTrue($metaData->isEmpty());

Robots::findFirst();

$this->assertEquals(apc_fetch('$PMM$my-local-appmeta-robots-robots'), $this->_data['meta-robots-robots']);
$this->assertEquals(apc_fetch('$PMM$my-local-appmap-robots'), $this->_data['map-robots']);

$this->assertFalse($metaData->isEmpty());

Robots::findFirst();

}

public function testMetadataFiles()
{

Expand Down
29 changes: 29 additions & 0 deletions unit-tests/helpers/xcache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

if (!function_exists('xcache_get') && function_exists('apc_fetch')) :

function xcache_get($key)
{
$ok = false;
$result = apc_fetch($key, $ok);
return $ok ? $result : null;
}

function xcache_set($key, $value, $ttl = 0)
{
return apc_store($key, $value, $ttl);
}

function xcache_isset($key)
{
return apc_exists($key);
}

function xcache_unset($key)
{
return apc_delete($key);
}

function xcache_emulation() {}

endif;