the whole shebang
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
|
||||
abstract class AbstractProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testStore()
|
||||
{
|
||||
for ($i = 0; $i < 10; $i ++) {
|
||||
$profile = new Profile('token_'.$i);
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
}
|
||||
$this->assertCount(10, $this->getStorage()->find('127.0.0.1', 'http://foo.bar', 20, 'GET'), '->write() stores data in the storage');
|
||||
}
|
||||
|
||||
public function testChildren()
|
||||
{
|
||||
$parentProfile = new Profile('token_parent');
|
||||
$parentProfile->setIp('127.0.0.1');
|
||||
$parentProfile->setUrl('http://foo.bar/parent');
|
||||
|
||||
$childProfile = new Profile('token_child');
|
||||
$childProfile->setIp('127.0.0.1');
|
||||
$childProfile->setUrl('http://foo.bar/child');
|
||||
|
||||
$parentProfile->addChild($childProfile);
|
||||
|
||||
$this->getStorage()->write($parentProfile);
|
||||
$this->getStorage()->write($childProfile);
|
||||
|
||||
// Load them from storage
|
||||
$parentProfile = $this->getStorage()->read('token_parent');
|
||||
$childProfile = $this->getStorage()->read('token_child');
|
||||
|
||||
// Check child has link to parent
|
||||
$this->assertNotNull($childProfile->getParent());
|
||||
$this->assertEquals($parentProfile->getToken(), $childProfile->getParentToken());
|
||||
|
||||
// Check parent has child
|
||||
$children = $parentProfile->getChildren();
|
||||
$this->assertCount(1, $children);
|
||||
$this->assertEquals($childProfile->getToken(), $children[0]->getToken());
|
||||
}
|
||||
|
||||
public function testStoreSpecialCharsInUrl()
|
||||
{
|
||||
// The storage accepts special characters in URLs (Even though URLs are not
|
||||
// supposed to contain them)
|
||||
$profile = new Profile('simple_quote');
|
||||
$profile->setUrl('http://foo.bar/\'');
|
||||
$this->getStorage()->write($profile);
|
||||
$this->assertTrue(false !== $this->getStorage()->read('simple_quote'), '->write() accepts single quotes in URL');
|
||||
|
||||
$profile = new Profile('double_quote');
|
||||
$profile->setUrl('http://foo.bar/"');
|
||||
$this->getStorage()->write($profile);
|
||||
$this->assertTrue(false !== $this->getStorage()->read('double_quote'), '->write() accepts double quotes in URL');
|
||||
|
||||
$profile = new Profile('backslash');
|
||||
$profile->setUrl('http://foo.bar/\\');
|
||||
$this->getStorage()->write($profile);
|
||||
$this->assertTrue(false !== $this->getStorage()->read('backslash'), '->write() accepts backslash in URL');
|
||||
|
||||
$profile = new Profile('comma');
|
||||
$profile->setUrl('http://foo.bar/,');
|
||||
$this->getStorage()->write($profile);
|
||||
$this->assertTrue(false !== $this->getStorage()->read('comma'), '->write() accepts comma in URL');
|
||||
}
|
||||
|
||||
public function testStoreDuplicateToken()
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
$profile->setUrl('http://example.com/');
|
||||
|
||||
$this->assertTrue($this->getStorage()->write($profile), '->write() returns true when the token is unique');
|
||||
|
||||
$profile->setUrl('http://example.net/');
|
||||
|
||||
$this->assertTrue($this->getStorage()->write($profile), '->write() returns true when the token is already present in the storage');
|
||||
$this->assertEquals('http://example.net/', $this->getStorage()->read('token')->getUrl(), '->write() overwrites the current profile data');
|
||||
|
||||
$this->assertCount(1, $this->getStorage()->find('', '', 1000, ''), '->find() does not return the same profile twice');
|
||||
}
|
||||
|
||||
public function testRetrieveByIp()
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'), '->find() retrieve a record by IP');
|
||||
$this->assertCount(0, $this->getStorage()->find('127.0.%.1', '', 10, 'GET'), '->find() does not interpret a "%" as a wildcard in the IP');
|
||||
$this->assertCount(0, $this->getStorage()->find('127.0._.1', '', 10, 'GET'), '->find() does not interpret a "_" as a wildcard in the IP');
|
||||
}
|
||||
|
||||
public function testRetrieveByUrl()
|
||||
{
|
||||
$profile = new Profile('simple_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/\'');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$profile = new Profile('double_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/"');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$profile = new Profile('backslash');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo\\bar/');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$profile = new Profile('percent');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/%');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$profile = new Profile('underscore');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/_');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$profile = new Profile('semicolon');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/;');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET'), '->find() accepts single quotes in URLs');
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET'), '->find() accepts double quotes in URLs');
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET'), '->find() accepts backslash in URLs');
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo.bar/;', 10, 'GET'), '->find() accepts semicolon in URLs');
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET'), '->find() does not interpret a "%" as a wildcard in the URL');
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET'), '->find() does not interpret a "_" as a wildcard in the URL');
|
||||
}
|
||||
|
||||
public function testStoreTime()
|
||||
{
|
||||
$dt = new \DateTime('now');
|
||||
$start = $dt->getTimestamp();
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$dt->modify('+1 minute');
|
||||
$profile = new Profile('time_'.$i);
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar');
|
||||
$profile->setTime($dt->getTimestamp());
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
}
|
||||
|
||||
$records = $this->getStorage()->find('', '', 3, 'GET', $start, time() + 3 * 60);
|
||||
$this->assertCount(3, $records, '->find() returns all previously added records');
|
||||
$this->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order');
|
||||
$this->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order');
|
||||
$this->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order');
|
||||
|
||||
$records = $this->getStorage()->find('', '', 3, 'GET', $start, time() + 2 * 60);
|
||||
$this->assertCount(2, $records, '->find() should return only first two of the previously added records');
|
||||
}
|
||||
|
||||
public function testRetrieveByEmptyUrlAndIp()
|
||||
{
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$profile = new Profile('token_'.$i);
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
}
|
||||
$this->assertCount(5, $this->getStorage()->find('', '', 10, 'GET'), '->find() returns all previously added records');
|
||||
$this->getStorage()->purge();
|
||||
}
|
||||
|
||||
public function testRetrieveByMethodAndLimit()
|
||||
{
|
||||
foreach (array('POST', 'GET') as $method) {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$profile = new Profile('token_'.$i.$method);
|
||||
$profile->setMethod($method);
|
||||
$this->getStorage()->write($profile);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertCount(5, $this->getStorage()->find('', '', 5, 'POST'));
|
||||
|
||||
$this->getStorage()->purge();
|
||||
}
|
||||
|
||||
public function testPurge()
|
||||
{
|
||||
$profile = new Profile('token1');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://example.com/');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$this->assertTrue(false !== $this->getStorage()->read('token1'));
|
||||
$this->assertCount(1, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'));
|
||||
|
||||
$profile = new Profile('token2');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://example.net/');
|
||||
$profile->setMethod('GET');
|
||||
$this->getStorage()->write($profile);
|
||||
|
||||
$this->assertTrue(false !== $this->getStorage()->read('token2'));
|
||||
$this->assertCount(2, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'));
|
||||
|
||||
$this->getStorage()->purge();
|
||||
|
||||
$this->assertEmpty($this->getStorage()->read('token'), '->purge() removes all data stored by profiler');
|
||||
$this->assertCount(0, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'), '->purge() removes all items from index');
|
||||
}
|
||||
|
||||
public function testDuplicates()
|
||||
{
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
$profile = new Profile('foo'.$i);
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://example.net/');
|
||||
$profile->setMethod('GET');
|
||||
|
||||
///three duplicates
|
||||
$this->getStorage()->write($profile);
|
||||
$this->getStorage()->write($profile);
|
||||
$this->getStorage()->write($profile);
|
||||
}
|
||||
$this->assertCount(3, $this->getStorage()->find('127.0.0.1', 'http://example.net/', 3, 'GET'), '->find() method returns incorrect number of entries');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
abstract protected function getStorage();
|
||||
}
|
100
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php
vendored
Normal file
100
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
|
||||
class FileProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $tmpDir;
|
||||
protected static $storage;
|
||||
|
||||
protected static function cleanDir()
|
||||
{
|
||||
$flags = \FilesystemIterator::SKIP_DOTS;
|
||||
$iterator = new \RecursiveDirectoryIterator(self::$tmpDir, $flags);
|
||||
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$tmpDir = sys_get_temp_dir().'/sf2_profiler_file_storage';
|
||||
if (is_dir(self::$tmpDir)) {
|
||||
self::cleanDir();
|
||||
}
|
||||
self::$storage = new FileProfilerStorage('file:'.self::$tmpDir);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::cleanDir();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::$storage->purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
|
||||
public function testMultiRowIndexFile()
|
||||
{
|
||||
$iteration = 3;
|
||||
for ($i = 0; $i < $iteration; $i++) {
|
||||
$profile = new Profile('token'.$i);
|
||||
$profile->setIp('127.0.0.'.$i);
|
||||
$profile->setUrl('http://foo.bar/'.$i);
|
||||
$storage = $this->getStorage();
|
||||
|
||||
$storage->write($profile);
|
||||
$storage->write($profile);
|
||||
$storage->write($profile);
|
||||
}
|
||||
|
||||
$handle = fopen(self::$tmpDir.'/index.csv', 'r');
|
||||
for ($i = 0; $i < $iteration; $i++) {
|
||||
$row = fgetcsv($handle);
|
||||
$this->assertEquals('token'.$i, $row[0]);
|
||||
$this->assertEquals('127.0.0.'.$i, $row[1]);
|
||||
$this->assertEquals('http://foo.bar/'.$i, $row[3]);
|
||||
}
|
||||
$this->assertFalse(fgetcsv($handle));
|
||||
}
|
||||
|
||||
public function testReadLineFromFile()
|
||||
{
|
||||
$r = new \ReflectionMethod(self::$storage, 'readLineFromFile');
|
||||
|
||||
$r->setAccessible(true);
|
||||
|
||||
$h = tmpfile();
|
||||
|
||||
fwrite($h, "line1\n\n\nline2\n");
|
||||
fseek($h, 0, SEEK_END);
|
||||
|
||||
$this->assertEquals("line2", $r->invoke(self::$storage, $h));
|
||||
$this->assertEquals("line1", $r->invoke(self::$storage, $h));
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\MemcacheProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Tests\Profiler\Mock\MemcacheMock;
|
||||
|
||||
class MemcacheProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$memcacheMock = new MemcacheMock();
|
||||
$memcacheMock->addServer('127.0.0.1', 11211);
|
||||
|
||||
self::$storage = new MemcacheProfilerStorage('memcache://127.0.0.1:11211', '', '', 86400);
|
||||
self::$storage->setMemcache($memcacheMock);
|
||||
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
self::$storage = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\MemcachedProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Tests\Profiler\Mock\MemcachedMock;
|
||||
|
||||
class MemcachedProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$memcachedMock = new MemcachedMock();
|
||||
$memcachedMock->addServer('127.0.0.1', 11211);
|
||||
|
||||
self::$storage = new MemcachedProfilerStorage('memcached://127.0.0.1:11211', '', '', 86400);
|
||||
self::$storage->setMemcached($memcachedMock);
|
||||
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
self::$storage = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
}
|
260
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/MemcacheMock.php
vendored
Normal file
260
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/MemcacheMock.php
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler\Mock;
|
||||
|
||||
/**
|
||||
* MemcacheMock for simulating Memcache extension in tests.
|
||||
*
|
||||
* @author Andrej Hudec <pulzarraider@gmail.com>
|
||||
*/
|
||||
class MemcacheMock
|
||||
{
|
||||
private $connected;
|
||||
private $storage;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connected = false;
|
||||
$this->storage = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open memcached server connection
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param integer $timeout
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function connect($host, $port = null, $timeout = null)
|
||||
{
|
||||
if ('127.0.0.1' == $host && 11211 == $port) {
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open memcached server persistent connection
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param integer $timeout
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function pconnect($host, $port = null, $timeout = null)
|
||||
{
|
||||
if ('127.0.0.1' == $host && 11211 == $port) {
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a memcached server to connection pool
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param boolean $persistent
|
||||
* @param integer $weight
|
||||
* @param integer $timeout
|
||||
* @param integer $retry_interval
|
||||
* @param boolean $status
|
||||
* @param callable $failure_callback
|
||||
* @param integer $timeoutms
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function addServer($host, $port = 11211, $persistent = null, $weight = null, $timeout = null, $retry_interval = null, $status = null, $failure_callback = null, $timeoutms = null)
|
||||
{
|
||||
if ('127.0.0.1' == $host && 11211 == $port) {
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the server only if such key doesn't exist at the server yet.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $var
|
||||
* @param integer $flag
|
||||
* @param integer $expire
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function add($key, $var, $flag = null, $expire = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->storage[$key])) {
|
||||
$this->storeData($key, $var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $var
|
||||
* @param integer $flag
|
||||
* @param integer $expire
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function set($key, $var, $flag = null, $expire = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storeData($key, $var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace value of the existing item.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $var
|
||||
* @param integer $flag
|
||||
* @param integer $expire
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function replace($key, $var, $flag = null, $expire = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
$this->storeData($key, $var);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param integer|array $flags
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, &$flags = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($key)) {
|
||||
$result = array();
|
||||
foreach ($key as $k) {
|
||||
if (isset($this->storage[$k])) {
|
||||
$result[] = $this->getData($k);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $this->getData($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
unset($this->storage[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items at the server
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storage = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close memcached server connection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->connected = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getData($key)
|
||||
{
|
||||
if (isset($this->storage[$key])) {
|
||||
return unserialize($this->storage[$key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function storeData($key, $value)
|
||||
{
|
||||
$this->storage[$key] = serialize($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
225
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/MemcachedMock.php
vendored
Normal file
225
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/MemcachedMock.php
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler\Mock;
|
||||
|
||||
/**
|
||||
* MemcachedMock for simulating Memcached extension in tests.
|
||||
*
|
||||
* @author Andrej Hudec <pulzarraider@gmail.com>
|
||||
*/
|
||||
class MemcachedMock
|
||||
{
|
||||
private $connected;
|
||||
private $storage;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connected = false;
|
||||
$this->storage = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Memcached option
|
||||
*
|
||||
* @param integer $option
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setOption($option, $value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a memcached server to connection pool
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param integer $weight
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function addServer($host, $port = 11211, $weight = 0)
|
||||
{
|
||||
if ('127.0.0.1' == $host && 11211 == $port) {
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the server only if such key doesn't exist at the server yet.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param integer $expiration
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function add($key, $value, $expiration = 0)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->storage[$key])) {
|
||||
$this->storeData($key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param integer $expiration
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function set($key, $value, $expiration = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storeData($key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace value of the existing item.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param integer $expiration
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function replace($key, $value, $expiration = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
$this->storeData($key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server.
|
||||
*
|
||||
* @param string $key
|
||||
* @param callable $cache_cb
|
||||
* @param float $cas_token
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get($key, $cache_cb = null, &$cas_token = null)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getData($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to an existing item
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function append($key, $value)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
$this->storeData($key, $this->getData($key).$value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
unset($this->storage[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items at the server
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storage = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getData($key)
|
||||
{
|
||||
if (isset($this->storage[$key])) {
|
||||
return unserialize($this->storage[$key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function storeData($key, $value)
|
||||
{
|
||||
$this->storage[$key] = serialize($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
254
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/RedisMock.php
vendored
Normal file
254
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/Mock/RedisMock.php
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler\Mock;
|
||||
|
||||
/**
|
||||
* RedisMock for simulating Redis extension in tests.
|
||||
*
|
||||
* @author Andrej Hudec <pulzarraider@gmail.com>
|
||||
*/
|
||||
class RedisMock
|
||||
{
|
||||
|
||||
private $connected;
|
||||
private $storage;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connected = false;
|
||||
$this->storage = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a server to connection pool
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param float $timeout
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function connect($host, $port = 6379, $timeout = 0)
|
||||
{
|
||||
if ('127.0.0.1' == $host && 6379 == $port) {
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set client option.
|
||||
*
|
||||
* @param integer $name
|
||||
* @param integer $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the specified key exists.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset($this->storage[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server with expiration time.
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $ttl
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setex($key, $ttl, $value)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storeData($key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an expiration time on an item.
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $ttl
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setTimeout($key, $ttl)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getData($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to an existing item
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return integer Size of the value after the append.
|
||||
*/
|
||||
public function append($key, $value)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
$this->storeData($key, $this->getData($key).$value);
|
||||
|
||||
return strlen($this->storage[$key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove specified keys.
|
||||
*
|
||||
* @param string|array $key
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($key)) {
|
||||
$result = 0;
|
||||
foreach ($key as $k) {
|
||||
if (isset($this->storage[$k])) {
|
||||
unset($this->storage[$k]);
|
||||
++$result;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (isset($this->storage[$key])) {
|
||||
unset($this->storage[$key]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items from all databases at the server.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flushAll()
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storage = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Redis server connection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->connected = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getData($key)
|
||||
{
|
||||
if (isset($this->storage[$key])) {
|
||||
return unserialize($this->storage[$key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function storeData($key, $value)
|
||||
{
|
||||
$this->storage[$key] = serialize($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function select($dbnum)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 > $dbnum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DummyMongoDbProfilerStorage extends MongoDbProfilerStorage
|
||||
{
|
||||
public function getMongo()
|
||||
{
|
||||
return parent::getMongo();
|
||||
}
|
||||
}
|
||||
|
||||
class MongoDbProfilerStorageTestDataCollector extends DataCollector
|
||||
{
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'test_data_collector';
|
||||
}
|
||||
}
|
||||
|
||||
class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $storage;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (extension_loaded('mongo')) {
|
||||
self::$storage = new DummyMongoDbProfilerStorage('mongodb://localhost/symfony_tests/profiler_data', '', '', 86400);
|
||||
try {
|
||||
self::$storage->getMongo();
|
||||
} catch (\MongoConnectionException $e) {
|
||||
self::$storage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
self::$storage = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testCleanup()
|
||||
{
|
||||
$dt = new \DateTime('-2 day');
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$dt->modify('-1 day');
|
||||
$profile = new Profile('time_'.$i);
|
||||
$profile->setTime($dt->getTimestamp());
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
}
|
||||
$records = self::$storage->find('', '', 3, 'GET');
|
||||
$this->assertCount(1, $records, '->find() returns only one record');
|
||||
$this->assertEquals($records[0]['token'], 'time_2', '->find() returns the latest added record');
|
||||
self::$storage->purge();
|
||||
}
|
||||
|
||||
public function testUtf8()
|
||||
{
|
||||
$profile = new Profile('utf8_test_profile');
|
||||
|
||||
$data = 'HЁʃʃϿ, ϢorЃd!';
|
||||
$nonUtf8Data = mb_convert_encoding($data, 'UCS-2');
|
||||
|
||||
$collector = new MongoDbProfilerStorageTestDataCollector();
|
||||
$collector->setData($nonUtf8Data);
|
||||
|
||||
$profile->setCollectors(array($collector));
|
||||
|
||||
self::$storage->write($profile);
|
||||
|
||||
$readProfile = self::$storage->read('utf8_test_profile');
|
||||
$collectors = $readProfile->getCollectors();
|
||||
|
||||
$this->assertCount(1, $collectors);
|
||||
$this->assertArrayHasKey('test_data_collector', $collectors);
|
||||
$this->assertEquals($nonUtf8Data, $collectors['test_data_collector']->getData(), 'Non-UTF8 data is properly encoded/decoded');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
} else {
|
||||
$this->markTestSkipped('MongoDbProfilerStorageTest requires the mongo PHP extension and a MongoDB server on localhost');
|
||||
}
|
||||
}
|
||||
}
|
56
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php
vendored
Normal file
56
vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
||||
use Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ProfilerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
|
||||
$this->markTestSkipped('The "HttpFoundation" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCollect()
|
||||
{
|
||||
if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
|
||||
$this->markTestSkipped('This test requires SQLite support in your environment');
|
||||
}
|
||||
|
||||
$request = new Request();
|
||||
$request->query->set('foo', 'bar');
|
||||
$response = new Response();
|
||||
$collector = new RequestDataCollector();
|
||||
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
|
||||
if (file_exists($tmp)) {
|
||||
@unlink($tmp);
|
||||
}
|
||||
$storage = new SqliteProfilerStorage('sqlite:'.$tmp);
|
||||
$storage->purge();
|
||||
|
||||
$profiler = new Profiler($storage);
|
||||
$profiler->add($collector);
|
||||
$profile = $profiler->collect($request, $response);
|
||||
|
||||
$profile = $profiler->loadProfile($profile->getToken());
|
||||
$this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
|
||||
|
||||
@unlink($tmp);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\RedisProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Tests\Profiler\Mock\RedisMock;
|
||||
|
||||
class RedisProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$redisMock = new RedisMock();
|
||||
$redisMock->connect('127.0.0.1', 6379);
|
||||
|
||||
self::$storage = new RedisProfilerStorage('redis://127.0.0.1:6379', '', '', 86400);
|
||||
self::$storage->setRedis($redisMock);
|
||||
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (self::$storage) {
|
||||
self::$storage->purge();
|
||||
self::$storage = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage;
|
||||
|
||||
class SqliteProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
protected static $dbFile;
|
||||
protected static $storage;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_storage');
|
||||
if (file_exists(self::$dbFile)) {
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
self::$storage = new SqliteProfilerStorage('sqlite:'.self::$dbFile);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
@unlink(self::$dbFile);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
|
||||
$this->markTestSkipped('This test requires SQLite support in your environment');
|
||||
}
|
||||
self::$storage->purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user