composer updated

propel installed but not integrated yet
new autoload process including classMap
This commit is contained in:
Manuel Raynaud
2012-12-11 11:00:04 +01:00
parent 43ec85bb1e
commit e0e5c58c1b
1821 changed files with 267545 additions and 34496 deletions

View File

@@ -0,0 +1,2 @@
/Tests export-ignore
phpunit.xml.dist export-ignore

View File

@@ -179,6 +179,11 @@ EOF;
$headers['Set-Cookie'] = $cookies;
}
return new DomResponse($response->getContent(), $response->getStatusCode(), $headers);
// this is needed to support StreamedResponse
ob_start();
$response->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response->getStatusCode(), $headers);
}
}

View File

@@ -31,4 +31,45 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable
{
$this->data = unserialize($data);
}
/**
* Converts a PHP variable to a string.
*
* @param mixed $var A PHP variable
*
* @return string The string representation of the variable
*/
protected function varToString($var)
{
if (is_object($var)) {
return sprintf('Object(%s)', get_class($var));
}
if (is_array($var)) {
$a = array();
foreach ($var as $k => $v) {
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
}
return sprintf("Array(%s)", implode(', ', $a));
}
if (is_resource($var)) {
return sprintf('Resource(%s)', get_resource_type($var));
}
if (null === $var) {
return 'null';
}
if (false === $var) {
return 'false';
}
if (true === $var) {
return 'true';
}
return (string) $var;
}
}

View File

@@ -14,7 +14,6 @@ namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
/**
* ExceptionDataCollector.

View File

@@ -11,7 +11,6 @@
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
@@ -51,14 +50,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if (is_object($value)) {
$attributes[$key] = sprintf('Object(%s)', get_class($value));
if (is_callable(array($value, '__toString'))) {
$attributes[$key] .= sprintf(' = %s', (string) $value);
}
} else {
$attributes[$key] = $value;
}
$attributes[$key] = $this->varToString($value);
}
$content = null;

View File

@@ -43,6 +43,8 @@ class ExceptionHandler
/**
* Register the exception handler.
*
* @param Boolean $debug
*
* @return ExceptionHandler The registered exception handler
*/
public static function register($debug = true)

View File

@@ -30,7 +30,7 @@ class FilterResponseEvent extends KernelEvent
{
/**
* The current response object
* @var Symfony\Component\HttpFoundation\Response
* @var Response
*/
private $response;
@@ -44,7 +44,7 @@ class FilterResponseEvent extends KernelEvent
/**
* Returns the current response object
*
* @return Symfony\Component\HttpFoundation\Response
* @return Response
*
* @api
*/
@@ -56,7 +56,7 @@ class FilterResponseEvent extends KernelEvent
/**
* Sets a new response object
*
* @param Symfony\Component\HttpFoundation\Response $response
* @param Response $response
*
* @api
*/

View File

@@ -28,14 +28,14 @@ class GetResponseEvent extends KernelEvent
{
/**
* The response object
* @var Symfony\Component\HttpFoundation\Response
* @var Response
*/
private $response;
/**
* Returns the response object
*
* @return Symfony\Component\HttpFoundation\Response
* @return Response
*
* @api
*/
@@ -47,7 +47,7 @@ class GetResponseEvent extends KernelEvent
/**
* Sets a response and stops event propagation
*
* @param Symfony\Component\HttpFoundation\Response $response
* @param Response $response
*
* @api
*/

View File

@@ -26,13 +26,13 @@ class KernelEvent extends Event
{
/**
* The kernel in which this event was thrown
* @var Symfony\Component\HttpKernel\HttpKernelInterface
* @var HttpKernelInterface
*/
private $kernel;
/**
* The request the kernel is currently processing
* @var Symfony\Component\HttpFoundation\Request
* @var Request
*/
private $request;
@@ -53,7 +53,7 @@ class KernelEvent extends Event
/**
* Returns the kernel in which this event was thrown
*
* @return Symfony\Component\HttpKernel\HttpKernelInterface
* @return HttpKernelInterface
*
* @api
*/
@@ -65,7 +65,7 @@ class KernelEvent extends Event
/**
* Returns the request the kernel is currently processing
*
* @return Symfony\Component\HttpFoundation\Request
* @return Request
*
* @api
*/

View File

@@ -22,9 +22,9 @@ class AccessDeniedHttpException extends HttpException
/**
* Constructor.
*
* @param string $message The internal exception message
* @param Exception $previous The previous exception
* @param integer $code The internal exception code
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
*/
public function __construct($message = null, \Exception $previous = null, $code = 0)
{

View File

@@ -21,10 +21,10 @@ class MethodNotAllowedHttpException extends HttpException
/**
* Constructor.
*
* @param array $allow An array of allowed methods
* @param string $message The internal exception message
* @param Exception $previous The previous exception
* @param integer $code The internal exception code
* @param array $allow An array of allowed methods
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
*/
public function __construct(array $allow, $message = null, \Exception $previous = null, $code = 0)
{

View File

@@ -21,9 +21,9 @@ class NotFoundHttpException extends HttpException
/**
* Constructor.
*
* @param string $message The internal exception message
* @param Exception $previous The previous exception
* @param integer $code The internal exception code
* @param string $message The internal exception message
* @param \Exception $previous The previous exception
* @param integer $code The internal exception code
*/
public function __construct($message = null, \Exception $previous = null, $code = 0)
{

View File

@@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
*/
class Store implements StoreInterface
{
private $root;
protected $root;
private $keyCache;
private $locks;
@@ -86,10 +86,14 @@ class Store implements StoreInterface
* Releases the lock for the given Request.
*
* @param Request $request A Request instance
*
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request)
{
return @unlink($this->getPath($this->getCacheKey($request).'.lck'));
$file = $this->getPath($this->getCacheKey($request).'.lck');
return is_file($file) ? @unlink($file) : false;
}
/**
@@ -150,7 +154,7 @@ class Store implements StoreInterface
// write the response body to the entity store if this is the original response
if (!$response->headers->has('X-Content-Digest')) {
$digest = 'en'.sha1($response->getContent());
$digest = $this->generateContentDigest($response);
if (false === $this->save($digest, $response->getContent())) {
throw new \RuntimeException('Unable to store the entity.');
@@ -188,6 +192,18 @@ class Store implements StoreInterface
return $key;
}
/**
* Returns content digest for $response.
*
* @param Response $response
*
* @return string
*/
protected function generateContentDigest(Response $response)
{
return 'en'.sha1($response->getContent());
}
/**
* Invalidates all cache entries that match the request.
*

View File

@@ -66,6 +66,8 @@ interface StoreInterface
* Releases the lock for the given Request.
*
* @param Request $request A Request instance
*
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request);

View File

@@ -58,11 +58,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface
protected $classes;
protected $errorReportingLevel;
const VERSION = '2.1.2';
const VERSION_ID = '20100';
const VERSION = '2.1.4';
const VERSION_ID = '20104';
const MAJOR_VERSION = '2';
const MINOR_VERSION = '1';
const RELEASE_VERSION = '2';
const RELEASE_VERSION = '4';
const EXTRA_VERSION = '';
/**

View File

@@ -34,7 +34,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
public function __construct($dsn)
{
if (0 !== strpos($dsn, 'file:')) {
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $this->dsn));
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $dsn));
}
$this->folder = substr($dsn, 5);

View File

@@ -95,7 +95,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$record = array(
'_id' => $profile->getToken(),
'parent' => $profile->getParentToken(),
'data' => serialize($profile->getCollectors()),
'data' => base64_encode(serialize($profile->getCollectors())),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
@@ -220,7 +220,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setTime($data['time']);
$profile->setCollectors(unserialize($data['data']));
$profile->setCollectors(unserialize(base64_decode($data['data'])));
return $profile;
}

View File

@@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.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\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
class BundleTest extends \PHPUnit_Framework_TestCase
{
public function testRegisterCommands()
{
if (!class_exists('Symfony\Component\Console\Application')) {
$this->markTestSkipped('The "Console" component is not available');
}
if (!interface_exists('Symfony\Component\DependencyInjection\ContainerAwareInterface')) {
$this->markTestSkipped('The "DependencyInjection" component is not available');
}
if (!class_exists('Symfony\Component\Finder\Finder')) {
$this->markTestSkipped('The "Finder" component is not available');
}
$cmd = new FooCommand();
$app = $this->getMock('Symfony\Component\Console\Application');
$app->expects($this->once())->method('add')->with($this->equalTo($cmd));
$bundle = new ExtensionPresentBundle();
$bundle->registerCommands($app);
$bundle2 = new ExtensionAbsentBundle();
$this->assertNull($bundle2->registerCommands($app));
}
}

View File

@@ -1,58 +0,0 @@
<?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\CacheClearer;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
class ChainCacheClearerTest extends \PHPUnit_Framework_TestCase
{
protected static $cacheDir;
public static function setUpBeforeClass()
{
self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_clearer_dir');
}
public static function tearDownAfterClass()
{
@unlink(self::$cacheDir);
}
public function testInjectClearersInConstructor()
{
$clearer = $this->getMockClearer();
$clearer
->expects($this->once())
->method('clear');
$chainClearer = new ChainCacheClearer(array($clearer));
$chainClearer->clear(self::$cacheDir);
}
public function testInjectClearerUsingAdd()
{
$clearer = $this->getMockClearer();
$clearer
->expects($this->once())
->method('clear');
$chainClearer = new ChainCacheClearer();
$chainClearer->add($clearer);
$chainClearer->clear(self::$cacheDir);
}
protected function getMockClearer()
{
return $this->getMock('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface');
}
}

View File

@@ -1,102 +0,0 @@
<?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\CacheWarmer;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
class CacheWarmerAggregateTest extends \PHPUnit_Framework_TestCase
{
protected static $cacheDir;
public static function setUpBeforeClass()
{
self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
}
public static function tearDownAfterClass()
{
@unlink(self::$cacheDir);
}
public function testInjectWarmersUsingConstructor()
{
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate->warmUp(self::$cacheDir);
}
public function testInjectWarmersUsingAdd()
{
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate();
$aggregate->add($warmer);
$aggregate->warmUp(self::$cacheDir);
}
public function testInjectWarmersUsingSetWarmers()
{
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate();
$aggregate->setWarmers(array($warmer));
$aggregate->warmUp(self::$cacheDir);
}
public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
{
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->never())
->method('isOptional');
$warmer
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate->enableOptionalWarmers();
$aggregate->warmUp(self::$cacheDir);
}
public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled()
{
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->once())
->method('isOptional')
->will($this->returnValue(true));
$warmer
->expects($this->never())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate->warmUp(self::$cacheDir);
}
protected function getCacheWarmerMock()
{
$warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface')
->disableOriginalConstructor()
->getMock();
return $warmer;
}
}

View File

@@ -1,67 +0,0 @@
<?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\CacheWarmer;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
class CacheWarmerTest extends \PHPUnit_Framework_TestCase
{
protected static $cacheFile;
public static function setUpBeforeClass()
{
self::$cacheFile = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
}
public static function tearDownAfterClass()
{
@unlink(self::$cacheFile);
}
public function testWriteCacheFileCreatesTheFile()
{
$warmer = new TestCacheWarmer(self::$cacheFile);
$warmer->warmUp(dirname(self::$cacheFile));
$this->assertTrue(file_exists(self::$cacheFile));
}
/**
* @expectedException \RuntimeException
*/
public function testWriteNonWritableCacheFileThrowsARuntimeException()
{
$nonWritableFile = '/this/file/is/very/probably/not/writable';
$warmer = new TestCacheWarmer($nonWritableFile);
$warmer->warmUp(dirname($nonWritableFile));
}
}
class TestCacheWarmer extends CacheWarmer
{
protected $file;
public function __construct($file)
{
$this->file = $file;
}
public function warmUp($cacheDir)
{
$this->writeCacheFile($this->file, 'content');
}
public function isOptional()
{
return false;
}
}

View File

@@ -1,159 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
class ClientTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\BrowserKit\Client')) {
$this->markTestSkipped('The "BrowserKit" component is not available');
}
}
public function testDoRequest()
{
$client = new Client(new TestHttpKernel());
$client->request('GET', '/');
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
$client->request('GET', 'http://www.example.com/');
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
$this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
$client->request('GET', 'http://www.example.com/?parameter=http://google.com');
$this->assertEquals('http://www.example.com/?parameter='.urlencode('http://google.com'), $client->getRequest()->getUri(), '->doRequest() uses the request handler to make the request');
}
public function testGetScript()
{
if (!class_exists('Symfony\Component\Process\Process')) {
$this->markTestSkipped('The "Process" component is not available');
}
if (!class_exists('Symfony\Component\ClassLoader\UniversalClassLoader')) {
$this->markTestSkipped('The "ClassLoader" component is not available');
}
$client = new TestClient(new TestHttpKernel());
$client->insulate();
$client->request('GET', '/');
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->getScript() returns a script that uses the request handler to make the request');
}
public function testFilterResponseConvertsCookies()
{
$client = new Client(new TestHttpKernel());
$r = new \ReflectionObject($client);
$m = $r->getMethod('filterResponse');
$m->setAccessible(true);
$expected = array(
'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly'
);
$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
}
public function testUploadedFile()
{
$source = tempnam(sys_get_temp_dir(), 'source');
$target = sys_get_temp_dir().'/sf.moved.file';
@unlink($target);
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$files = array(
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 123, 'error' => UPLOAD_ERR_OK),
new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK),
);
foreach ($files as $file) {
$client->request('POST', '/', array(), array('foo' => $file));
$files = $client->getRequest()->files->all();
$this->assertCount(1, $files);
$file = $files['foo'];
$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('123', $file->getClientSize());
$this->assertTrue($file->isValid());
}
$file->move(dirname($target), basename($target));
$this->assertFileExists($target);
unlink($target);
}
public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
{
$source = tempnam(sys_get_temp_dir(), 'source');
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$file = $this
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK))
->setMethods(array('getSize'))
->getMock()
;
$file->expects($this->once())
->method('getSize')
->will($this->returnValue(INF))
;
$client->request('POST', '/', array(), array($file));
$files = $client->getRequest()->files->all();
$this->assertCount(1, $files);
$file = $files[0];
$this->assertFalse($file->isValid());
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals(0, $file->getClientSize());
unlink($source);
}
}

View File

@@ -1,180 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpFoundation\Request;
class ControllerResolverTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
public function testGetController()
{
$logger = new Logger();
$resolver = new ControllerResolver($logger);
$request = Request::create('/');
$this->assertFalse($resolver->getController($request), '->getController() returns false when the request has no _controller attribute');
$this->assertEquals(array('Unable to look for the controller as the "_controller" parameter is missing'), $logger->getLogs('warn'));
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\ControllerResolverTest::testGetController');
$controller = $resolver->getController($request);
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
$request->attributes->set('_controller', $lambda = function () {});
$controller = $resolver->getController($request);
$this->assertSame($lambda, $controller);
$request->attributes->set('_controller', $this);
$controller = $resolver->getController($request);
$this->assertSame($this, $controller);
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\ControllerResolverTest');
$controller = $resolver->getController($request);
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\ControllerResolverTest', $controller);
$request->attributes->set('_controller', array($this, 'controllerMethod1'));
$controller = $resolver->getController($request);
$this->assertSame(array($this, 'controllerMethod1'), $controller);
$request->attributes->set('_controller', array('Symfony\Component\HttpKernel\Tests\ControllerResolverTest', 'controllerMethod4'));
$controller = $resolver->getController($request);
$this->assertSame(array('Symfony\Component\HttpKernel\Tests\ControllerResolverTest', 'controllerMethod4'), $controller);
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\some_controller_function');
$controller = $resolver->getController($request);
$this->assertSame('Symfony\Component\HttpKernel\Tests\some_controller_function', $controller);
$request->attributes->set('_controller', 'foo');
try {
$resolver->getController($request);
$this->fail('->getController() throws an \InvalidArgumentException if the _controller attribute is not well-formatted');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getController() throws an \InvalidArgumentException if the _controller attribute is not well-formatted');
}
$request->attributes->set('_controller', 'foo::bar');
try {
$resolver->getController($request);
$this->fail('->getController() throws an \InvalidArgumentException if the _controller attribute contains a non-existent class');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getController() throws an \InvalidArgumentException if the _controller attribute contains a non-existent class');
}
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\ControllerResolverTest::bar');
try {
$resolver->getController($request);
$this->fail('->getController() throws an \InvalidArgumentException if the _controller attribute contains a non-existent method');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getController() throws an \InvalidArgumentException if the _controller attribute contains a non-existent method');
}
}
public function testGetArguments()
{
$resolver = new ControllerResolver();
$request = Request::create('/');
$controller = array(new self(), 'testGetArguments');
$this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerMethod1');
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerMethod2');
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
$request->attributes->set('bar', 'bar');
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = function ($foo) {};
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = function ($foo, $bar = 'bar') {};
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = new self();
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
$request->attributes->set('bar', 'bar');
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('foobar', 'foobar');
$controller = 'Symfony\Component\HttpKernel\Tests\some_controller_function';
$this->assertEquals(array('foo', 'foobar'), $resolver->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('foobar', 'foobar');
$controller = array(new self(), 'controllerMethod3');
if (version_compare(PHP_VERSION, '5.3.16', '==')) {
$this->markTestSkipped('PHP 5.3.16 has a major bug in the Reflection sub-system');
} else {
try {
$resolver->getArguments($request, $controller);
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
}
}
$request = Request::create('/');
$controller = array(new self(), 'controllerMethod5');
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
}
public function __invoke($foo, $bar = null)
{
}
protected function controllerMethod1($foo)
{
}
protected function controllerMethod2($foo, $bar = null)
{
}
protected function controllerMethod3($foo, $bar = null, $foobar)
{
}
protected static function controllerMethod4()
{
}
protected function controllerMethod5(Request $request)
{
}
}
function some_controller_function($foo, $foobar)
{
}

View File

@@ -1,87 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ConfigDataCollectorTest 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()
{
$kernel = new KernelForTest('test', true);
$c = new ConfigDataCollector();
$c->setKernel($kernel);
$c->collect(new Request(), new Response());
$this->assertSame('test',$c->getEnv());
$this->assertTrue($c->isDebug());
$this->assertSame('config',$c->getName());
$this->assertSame('testkernel',$c->getAppName());
$this->assertSame(PHP_VERSION,$c->getPhpVersion());
$this->assertSame(Kernel::VERSION,$c->getSymfonyVersion());
$this->assertNull($c->getToken());
// if else clause because we don't know it
if (extension_loaded('xdebug')) {
$this->assertTrue($c->hasXdebug());
} else {
$this->assertFalse($c->hasXdebug());
}
// if else clause because we don't know it
if (((extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'))
||
(extension_loaded('apc') && ini_get('apc.enabled'))
||
(extension_loaded('xcache') && ini_get('xcache.cacher')))) {
$this->assertTrue($c->hasAccelerator());
} else {
$this->assertFalse($c->hasAccelerator());
}
}
}
class KernelForTest extends Kernel
{
public function getName()
{
return 'testkernel';
}
public function registerBundles()
{
}
public function init()
{
}
public function getBundles()
{
return array();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
}

View File

@@ -1,45 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\EventDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\Tests\Fixtures\TestEventDispatcher;
class EventDataCollectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
public function testCollect()
{
$c = new EventDataCollector();
$c->setEventDispatcher(new TestEventDispatcher());
$c->collect(new Request(), new Response());
$this->assertSame('events',$c->getName());
$this->assertSame(array('foo'),$c->getCalledListeners());
$this->assertSame(array('bar'),$c->getNotCalledListeners());
}
}

View File

@@ -1,47 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ExceptionDataCollectorTest 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()
{
$e = new \Exception('foo',500);
$c = new ExceptionDataCollector();
$flattened = FlattenException::create($e);
$trace = $flattened->getTrace();
$this->assertFalse($c->hasException());
$c->collect(new Request(), new Response(),$e);
$this->assertTrue($c->hasException());
$this->assertEquals($flattened,$c->getException());
$this->assertSame('foo',$c->getMessage());
$this->assertSame(500,$c->getCode());
$this->assertSame('exception',$c->getName());
$this->assertSame($trace,$c->getTrace());
}
}

View File

@@ -1,64 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
/**
* @dataProvider getCollectTestData
*/
public function testCollect($nb, $logs, $expected)
{
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface');
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
$logger->expects($this->once())->method('getLogs')->will($this->returnValue($logs));
$c = new LoggerDataCollector($logger);
$c->collect(new Request(), new Response());
$this->assertSame('logger', $c->getName());
$this->assertSame($nb, $c->countErrors());
$this->assertSame($expected ? $expected : $logs, $c->getLogs());
}
public function getCollectTestData()
{
return array(
array(
1,
array(array('message' => 'foo', 'context' => array())),
null,
),
array(
1,
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))),
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))),
),
array(
1,
array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()))),
array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'))),
),
);
}
}

View File

@@ -1,37 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class MemoryDataCollectorTest 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()
{
$c = new MemoryDataCollector();
$c->collect(new Request(), new Response());
$this->assertInternalType('integer',$c->getMemory());
$this->assertSame('memory',$c->getName());
}
}

View File

@@ -1,73 +0,0 @@
<?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\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
/**
* @dataProvider provider
*/
public function testCollect(Request $request, Response $response)
{
$c = new RequestDataCollector();
$c->collect($request, $response);
$this->assertSame('request',$c->getName());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getRequestHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestServer());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestCookies());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestRequest());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestQuery());
$this->assertEquals('html',$c->getFormat());
$this->assertEquals(array(),$c->getSessionAttributes());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getResponseHeaders());
$this->assertEquals(200,$c->getStatusCode());
$this->assertEquals('application/json',$c->getContentType());
}
public function provider()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
return array(array(null, null));
}
$request = Request::create('http://test.com/foo?bar=baz');
$request->attributes->set('foo', 'bar');
$response = new Response();
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'application/json');
$response->headers->setCookie(new Cookie('foo','bar',1,'/foo','localhost',true,true));
$response->headers->setCookie(new Cookie('bar','foo',new \DateTime('@946684800')));
$response->headers->setCookie(new Cookie('bazz','foo','2000-12-12'));
return array(
array($request, $response)
);
}
}

View File

@@ -1,80 +0,0 @@
<?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\Debug;
use Symfony\Component\HttpKernel\Debug\ContainerAwareTraceableEventDispatcher;
use Symfony\Component\HttpKernel\Debug\Stopwatch;
class ContainerAwareTraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\DependencyInjection\Container')) {
$this->markTestSkipped('The "DependencyInjection" component is not available');
}
if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
$this->markTestSkipped('The "HttpKernel" component is not available');
}
}
/**
* @expectedException \RuntimeException
*/
public function testThrowsAnExceptionWhenAListenerMethodIsNotCallable()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$dispatcher = new ContainerAwareTraceableEventDispatcher($container, new Stopwatch());
$dispatcher->addListener('onFooEvent', new \stdClass());
}
public function testClosureDoesNotTriggerErrorNotice()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$dispatcher = new ContainerAwareTraceableEventDispatcher($container, new StopWatch());
$triggered = false;
$dispatcher->addListener('onFooEvent', function() use (&$triggered) {
$triggered = true;
});
try {
$dispatcher->dispatch('onFooEvent');
} catch (\PHPUnit_Framework_Error_Notice $e) {
$this->fail($e->getMessage());
}
$this->assertTrue($triggered, 'Closure should have been executed upon dispatch');
}
public function testStaticCallable()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$dispatcher = new ContainerAwareTraceableEventDispatcher($container, new StopWatch());
$dispatcher->addListener('onFooEvent', array(__NAMESPACE__.'\StaticClassFixture', 'staticListener'));
$dispatcher->dispatch('onFooEvent');
$this->assertTrue(StaticClassFixture::$called);
}
}
class StaticClassFixture
{
public static $called = false;
public static function staticListener($event)
{
self::$called = true;
}
}

View File

@@ -1,61 +0,0 @@
<?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\Debug;
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ErrorException;
/**
* ErrorHandlerTest
*
* @author Robert Schönthal <seroscho@googlemail.com>
*/
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$handler = ErrorHandler::register(3);
$level = new \ReflectionProperty($handler, 'level');
$level->setAccessible(true);
$this->assertEquals(3, $level->getValue($handler));
restore_error_handler();
}
public function testHandle()
{
$handler = ErrorHandler::register(0);
$this->assertFalse($handler->handle(0, 'foo', 'foo.php', 12, 'foo'));
restore_error_handler();
$handler = ErrorHandler::register(3);
$this->assertFalse($handler->handle(4, 'foo', 'foo.php', 12, 'foo'));
restore_error_handler();
$handler = ErrorHandler::register(3);
try {
$handler->handle(1, 'foo', 'foo.php', 12, 'foo');
} catch (\ErrorException $e) {
$this->assertSame('1: foo in foo.php line 12', $e->getMessage());
$this->assertSame(1, $e->getSeverity());
$this->assertSame('foo.php', $e->getFile());
$this->assertSame(12, $e->getLine());
}
restore_error_handler();
}
}

View File

@@ -1,69 +0,0 @@
<?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\Debug;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
public function testDebug()
{
$handler = new ExceptionHandler(false);
$response = $handler->createResponse(new \RuntimeException('Foo'));
$this->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response->getContent());
$this->assertNotContains('<div class="block_exception clear_fix">', $response->getContent());
$handler = new ExceptionHandler(true);
$response = $handler->createResponse(new \RuntimeException('Foo'));
$this->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response->getContent());
$this->assertContains('<div class="block_exception clear_fix">', $response->getContent());
}
public function testStatusCode()
{
$handler = new ExceptionHandler(false);
$response = $handler->createResponse(new \RuntimeException('Foo'));
$this->assertEquals('500', $response->getStatusCode());
$this->assertContains('<title>Whoops, looks like something went wrong.</title>', $response->getContent());
$response = $handler->createResponse(new NotFoundHttpException('Foo'));
$this->assertEquals('404', $response->getStatusCode());
$this->assertContains('<title>Sorry, the page you are looking for could not be found.</title>', $response->getContent());
}
public function testHeaders()
{
$handler = new ExceptionHandler(false);
$response = $handler->createResponse(new MethodNotAllowedHttpException(array('POST')));
$this->assertEquals('405', $response->getStatusCode());
$this->assertEquals('POST', $response->headers->get('Allow'));
}
public function testNestedExceptions()
{
$handler = new ExceptionHandler(true);
$response = $handler->createResponse(new \RuntimeException('Foo', null, new \RuntimeException('Bar')));
}
}

View File

@@ -1,152 +0,0 @@
<?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\Debug;
use Symfony\Component\HttpKernel\Debug\StopwatchEvent;
/**
* StopwatchEventTest
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class StopwatchEventTest extends \PHPUnit_Framework_TestCase
{
public function testGetOrigin()
{
$event = new StopwatchEvent(12);
$this->assertEquals(12, $event->getOrigin());
}
public function testGetCategory()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$this->assertEquals('default', $event->getCategory());
$event = new StopwatchEvent(microtime(true) * 1000, 'cat');
$this->assertEquals('cat', $event->getCategory());
}
public function testGetPeriods()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$this->assertEquals(array(), $event->getPeriods());
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
$event->stop();
$this->assertCount(1, $event->getPeriods());
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
$event->stop();
$event->start();
$event->stop();
$this->assertCount(2, $event->getPeriods());
}
public function testLap()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
$event->lap();
$event->stop();
$this->assertCount(2, $event->getPeriods());
}
public function testTotalTime()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(20000);
$event->stop();
$total = $event->getTotalTime();
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(10000);
$event->stop();
$event->start();
usleep(10000);
$event->stop();
$total = $event->getTotalTime();
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
}
/**
* @expectedException \LogicException
*/
public function testStopWithoutStart()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$event->stop();
}
public function testEnsureStopped()
{
// this also test overlap between two periods
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(10000);
$event->start();
usleep(10000);
$event->ensureStopped();
$total = $event->getTotalTime();
$this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)');
}
public function testStartTime()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$this->assertTrue($event->getStartTime() < 0.5);
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
$event->stop();
$this->assertTrue($event->getStartTime() < 1);
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(10000);
$event->stop();
$start = $event->getStartTime();
$this->assertTrue($start >= 0 && $start <= 20);
}
public function testEndTime()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$this->assertEquals(0, $event->getEndTime());
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
$this->assertEquals(0, $event->getEndTime());
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(10000);
$event->stop();
$event->start();
usleep(10000);
$event->stop();
$end = $event->getEndTime();
$this->assertTrue($end >= 11 && $end <= 29, $end.' should be 20 (between 11 and 29)');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidOriginThrowsAnException()
{
new StopwatchEvent("abc");
}
}

View File

@@ -1,120 +0,0 @@
<?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\Debug;
use Symfony\Component\HttpKernel\Debug\Stopwatch;
/**
* StopwatchTest
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class StopwatchTest extends \PHPUnit_Framework_TestCase
{
public function testStart()
{
$stopwatch = new Stopwatch();
$event = $stopwatch->start('foo', 'cat');
$this->assertInstanceof('Symfony\Component\HttpKernel\Debug\StopwatchEvent', $event);
$this->assertEquals('cat', $event->getCategory());
}
public function testStop()
{
$stopwatch = new Stopwatch();
$stopwatch->start('foo', 'cat');
usleep(20000);
$event = $stopwatch->stop('foo');
$this->assertInstanceof('Symfony\Component\HttpKernel\Debug\StopwatchEvent', $event);
$total = $event->getTotalTime();
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
}
public function testLap()
{
$stopwatch = new Stopwatch();
$stopwatch->start('foo', 'cat');
usleep(10000);
$event = $stopwatch->lap('foo');
usleep(10000);
$stopwatch->stop('foo');
$this->assertInstanceof('Symfony\Component\HttpKernel\Debug\StopwatchEvent', $event);
$total = $event->getTotalTime();
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
}
/**
* @expectedException \LogicException
*/
public function testStopWithoutStart()
{
$stopwatch = new Stopwatch();
$stopwatch->stop('foo');
}
public function testSection()
{
$stopwatch = new Stopwatch();
$stopwatch->openSection();
$stopwatch->start('foo', 'cat');
$stopwatch->stop('foo');
$stopwatch->start('bar', 'cat');
$stopwatch->stop('bar');
$stopwatch->stopSection('1');
$stopwatch->openSection();
$stopwatch->start('foobar', 'cat');
$stopwatch->stop('foobar');
$stopwatch->stopSection('2');
$stopwatch->openSection();
$stopwatch->start('foobar', 'cat');
$stopwatch->stop('foobar');
$stopwatch->stopSection('0');
// the section is an event by itself
$this->assertCount(3, $stopwatch->getSectionEvents('1'));
$this->assertCount(2, $stopwatch->getSectionEvents('2'));
$this->assertCount(2, $stopwatch->getSectionEvents('0'));
}
public function testReopenASection()
{
$stopwatch = new Stopwatch();
$stopwatch->openSection();
$stopwatch->start('foo', 'cat');
$stopwatch->stopSection('section');
$stopwatch->openSection('section');
$stopwatch->start('bar', 'cat');
$stopwatch->stopSection('section');
$events = $stopwatch->getSectionEvents('section');
$this->assertCount(3, $events);
$this->assertCount(2, $events['__section__']->getPeriods());
}
/**
* @expectedException \LogicException
*/
public function testReopenANewSectionShouldThrowAnException()
{
$stopwatch = new Stopwatch();
$stopwatch->openSection('section');
}
}

View File

@@ -1,65 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\DependencyInjection\Container')) {
$this->markTestSkipped('The "DependencyInjection" component is not available');
}
if (!class_exists('Symfony\Component\Config\FileLocator')) {
$this->markTestSkipped('The "Config" component is not available');
}
}
public function testAutoloadMainExtension()
{
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder');
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');
$container->expects($this->at(0))
->method('getExtensionConfig')
->with('loaded')
->will($this->returnValue(array(array())));
$container->expects($this->at(1))
->method('getExtensionConfig')
->with('notloaded')
->will($this->returnValue(array()));
$container->expects($this->once())
->method('loadFromExtension')
->with('notloaded', array());
$container->expects($this->any())
->method('getParameterBag')
->will($this->returnValue($params));
$params->expects($this->any())
->method('all')
->will($this->returnValue(array()));
$container->expects($this->any())
->method('getDefinitions')
->will($this->returnValue(array()));
$container->expects($this->any())
->method('getAliases')
->will($this->returnValue(array()));
$container->expects($this->any())
->method('getExtensions')
->will($this->returnValue(array()));
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'notloaded'));
$configPass->process($container);
}
}

View File

@@ -1,73 +0,0 @@
<?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\EventListener;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\EventListener\EsiListener;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcher;
class EsiListenerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
}
public function testFilterDoesNothingForSubRequests()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new Response('foo <esi:include src="" />');
$listener = new EsiListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
}
public function testFilterWhenThereIsSomeEsiIncludes()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new Response('foo <esi:include src="" />');
$listener = new EsiListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control'));
}
public function testFilterWhenThereIsNoEsiIncludes()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new Response('foo');
$listener = new EsiListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
}
}

View File

@@ -1,139 +0,0 @@
<?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\EventListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Logger;
/**
* ExceptionListenerTest
*
* @author Robert Schönthal <seroscho@googlemail.com>
*/
class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
public function testConstruct()
{
$logger = new TestLogger();
$l = new ExceptionListener('foo', $logger);
$_logger = new \ReflectionProperty(get_class($l), 'logger');
$_logger->setAccessible(true);
$_controller = new \ReflectionProperty(get_class($l), 'controller');
$_controller->setAccessible(true);
$this->assertSame($logger, $_logger->getValue($l));
$this->assertSame('foo', $_controller->getValue($l));
}
/**
* @dataProvider provider
*/
public function testHandleWithoutLogger($event, $event2)
{
// store the current error_log, and disable it temporarily
$errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
$l = new ExceptionListener('foo');
$l->onKernelException($event);
$this->assertEquals(new Response('foo'), $event->getResponse());
try {
$l->onKernelException($event2);
} catch (\Exception $e) {
$this->assertSame('foo', $e->getMessage());
}
// restore the old error_log
ini_set('error_log', $errorLog);
}
/**
* @dataProvider provider
*/
public function testHandleWithLogger($event, $event2)
{
$logger = new TestLogger();
$l = new ExceptionListener('foo', $logger);
$l->onKernelException($event);
$this->assertEquals(new Response('foo'), $event->getResponse());
try {
$l->onKernelException($event2);
} catch (\Exception $e) {
$this->assertSame('foo', $e->getMessage());
}
$this->assertEquals(3, $logger->countErrors());
$this->assertCount(3, $logger->getLogs('crit'));
}
public function provider()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
return array(array(null, null));
}
$request = new Request();
$exception = new \Exception('foo');
$event = new GetResponseForExceptionEvent(new TestKernel(), $request, 'foo', $exception);
$event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, 'foo', $exception);
return array(
array($event, $event2)
);
}
}
class TestLogger extends Logger implements DebugLoggerInterface
{
public function countErrors()
{
return count($this->logs['crit']);
}
}
class TestKernel implements HttpKernelInterface
{
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
return new Response('foo');
}
}
class TestKernelThatThrowsException implements HttpKernelInterface
{
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
throw new \Exception('bar');
}
}

View File

@@ -1,75 +0,0 @@
<?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\EventListener;
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class LocaleListenerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
}
public function testDefaultLocaleWithoutSession()
{
$listener = new LocaleListener('fr');
$event = $this->getEvent($request = Request::create('/'));
$listener->onKernelRequest($event);
$this->assertEquals('fr', $request->getLocale());
}
public function testLocaleFromRequestAttribute()
{
$request = Request::create('/');
session_name('foo');
$request->cookies->set('foo', 'value');
$request->attributes->set('_locale', 'es');
$listener = new LocaleListener('fr');
$event = $this->getEvent($request);
$listener->onKernelRequest($event);
$this->assertEquals('es', $request->getLocale());
}
public function testLocaleSetForRoutingContext()
{
if (!class_exists('Symfony\Component\Routing\Router')) {
$this->markTestSkipped('The "Routing" component is not available');
}
// the request context is updated
$context = $this->getMock('Symfony\Component\Routing\RequestContext');
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
$router = $this->getMock('Symfony\Component\Routing\Router', array('getContext'), array(), '', false);
$router->expects($this->once())->method('getContext')->will($this->returnValue($context));
$request = Request::create('/');
$request->attributes->set('_locale', 'es');
$listener = new LocaleListener('fr', $router);
$listener->onKernelRequest($this->getEvent($request));
}
private function getEvent(Request $request)
{
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
}
}

View File

@@ -1,99 +0,0 @@
<?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\EventListener;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
class ResponseListenerTest extends \PHPUnit_Framework_TestCase
{
private $dispatcher;
private $kernel;
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$this->dispatcher = new EventDispatcher();
$listener = new ResponseListener('UTF-8');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
}
protected function tearDown()
{
$this->dispatcher = null;
$this->kernel = null;
}
public function testFilterDoesNothingForSubRequests()
{
$response = new Response('foo');
$event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('', $event->getResponse()->headers->get('content-type'));
}
public function testFilterSetsNonDefaultCharsetIfNotOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$response = new Response('foo');
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('ISO-8859-15', $response->getCharset());
}
public function testFilterDoesNothingIfCharsetIsOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$response = new Response('foo');
$response->setCharset('ISO-8859-1');
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('ISO-8859-1', $response->getCharset());
}
public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$response = new Response('foo');
$request = Request::create('/');
$request->setRequestFormat('application/json');
$event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->assertEquals('ISO-8859-15', $response->getCharset());
}
}

View File

@@ -1,134 +0,0 @@
<?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\EventListener;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\RequestContext;
class RouterListenerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
if (!class_exists('Symfony\Component\Routing\Router')) {
$this->markTestSkipped('The "Routing" component is not available');
}
}
/**
* @dataProvider getPortData
*/
public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort)
{
$urlMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface')
->disableOriginalConstructor()
->getMock();
$context = new RequestContext();
$context->setHttpPort($defaultHttpPort);
$context->setHttpsPort($defaultHttpsPort);
$urlMatcher->expects($this->any())
->method('getContext')
->will($this->returnValue($context));
$listener = new RouterListener($urlMatcher);
$event = $this->createGetResponseEventForUri($uri);
$listener->onKernelRequest($event);
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
$this->assertEquals($expectedHttpsPort, $context->getHttpsPort());
$this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme());
}
public function getPortData()
{
return array(
array(80, 443, 'http://localhost/', 80, 443),
array(80, 443, 'http://localhost:90/', 90, 443),
array(80, 443, 'https://localhost/', 80, 443),
array(80, 443, 'https://localhost:90/', 80, 90),
);
}
/**
* @param string $uri
*
* @return GetResponseEvent
*/
private function createGetResponseEventForUri($uri)
{
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$request = Request::create($uri);
$request->attributes->set('_controller', null); // Prevents going in to routing process
return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidMatcher()
{
new RouterListener(new \stdClass());
}
public function testRequestMatcher()
{
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$request = Request::create('http://localhost/');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$requestMatcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface');
$requestMatcher->expects($this->once())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue(array()));
$listener = new RouterListener($requestMatcher, new RequestContext());
$listener->onKernelRequest($event);
}
public function testSubRequestWithDifferentMethod()
{
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$request = Request::create('http://localhost/', 'post');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$requestMatcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface');
$requestMatcher->expects($this->any())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue(array()));
$context = new RequestContext();
$requestMatcher->expects($this->any())
->method('getContext')
->will($this->returnValue($context));
$listener = new RouterListener($requestMatcher, new RequestContext());
$listener->onKernelRequest($event);
// sub-request with another HTTP method
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$request = Request::create('http://localhost/', 'get');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
$listener->onKernelRequest($event);
$this->assertEquals('GET', $context->getMethod());
}
}

View File

@@ -1,128 +0,0 @@
<?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\Exception;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testStatusCode()
{
$flattened = FlattenException::create(new \RuntimeException(), 403);
$this->assertEquals('403', $flattened->getStatusCode());
$flattened = FlattenException::create(new \RuntimeException());
$this->assertEquals('500', $flattened->getStatusCode());
$flattened = FlattenException::create(new NotFoundHttpException());
$this->assertEquals('404', $flattened->getStatusCode());
}
public function testHeadersForHttpException()
{
$flattened = FlattenException::create(new MethodNotAllowedHttpException(array('POST')));
$this->assertEquals(array('Allow' => 'POST'), $flattened->getHeaders());
}
/**
* @dataProvider flattenDataProvider
*/
public function testFlattenHttpException(\Exception $exception, $statusCode)
{
$flattened = FlattenException::create($exception);
$flattened2 = FlattenException::create($exception);
$flattened->setPrevious($flattened2);
$this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
$this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
$this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
}
/**
* @dataProvider flattenDataProvider
*/
public function testPrevious(\Exception $exception, $statusCode)
{
$flattened = FlattenException::create($exception);
$flattened2 = FlattenException::create($exception);
$flattened->setPrevious($flattened2);
$this->assertSame($flattened2,$flattened->getPrevious());
$this->assertSame(array($flattened2),$flattened->getAllPrevious());
}
/**
* @dataProvider flattenDataProvider
*/
public function testLine(\Exception $exception)
{
$flattened = FlattenException::create($exception);
$this->assertSame($exception->getLine(), $flattened->getLine());
}
/**
* @dataProvider flattenDataProvider
*/
public function testFile(\Exception $exception)
{
$flattened = FlattenException::create($exception);
$this->assertSame($exception->getFile(), $flattened->getFile());
}
/**
* @dataProvider flattenDataProvider
*/
public function testToArray(\Exception $exception, $statusCode)
{
$flattened = FlattenException::create($exception);
$flattened->setTrace(array(),'foo.php',123);
$this->assertEquals(array(
array(
'message'=> 'test',
'class'=>'Exception',
'trace'=>array(array(
'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '', 'file' => 'foo.php','line' => 123,
'args' => array()
)),
)
),$flattened->toArray());
}
public function flattenDataProvider()
{
return array(
array(new \Exception('test', 123), 500),
);
}
public function testRecursionInArguments()
{
$a = array('foo', array(2, &$a));
$exception = $this->createException($a);
$flattened = FlattenException::create($exception);
$trace = $flattened->getTrace();
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
}
private function createException($foo)
{
return new \Exception();
}
}

View File

@@ -1,18 +0,0 @@
<?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\Fixtures\ExtensionAbsentBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ExtensionAbsentBundle extends Bundle
{
}

View File

@@ -1,22 +0,0 @@
<?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\Fixtures\ExtensionLoadedBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class ExtensionLoadedExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
}
}

View File

@@ -1,18 +0,0 @@
<?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\Fixtures\ExtensionLoadedBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ExtensionLoadedBundle extends Bundle
{
}

View File

@@ -1,23 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.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\Fixtures\ExtensionPresentBundle\Command;
use Symfony\Component\Console\Command\Command;
class FooCommand extends Command
{
protected function configure()
{
$this->setName('foo');
}
}

View File

@@ -1,22 +0,0 @@
<?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\Fixtures\ExtensionPresentBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class ExtensionPresentExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
}
}

View File

@@ -1,18 +0,0 @@
<?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\Fixtures\ExtensionPresentBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ExtensionPresentBundle extends Bundle
{
}

View File

@@ -1,19 +0,0 @@
<?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\Fixtures;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class FooBarBundle extends Bundle
{
// We need a full namespaced bundle instance to test isClassInActiveBundle
}

View File

@@ -1,30 +0,0 @@
<?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\Fixtures;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class KernelForOverrideName extends Kernel
{
protected $name = 'overridden';
public function registerBundles()
{
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
}

View File

@@ -1,54 +0,0 @@
<?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\Fixtures;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class KernelForTest extends Kernel
{
public function getBundleMap()
{
return $this->bundleMap;
}
public function registerBundles()
{
}
public function init()
{
}
public function registerBundleDirs()
{
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
public function initializeBundles()
{
parent::initializeBundles();
}
public function isBooted()
{
return $this->booted;
}
public function setIsBooted($value)
{
$this->booted = (Boolean) $value;
}
}

View File

@@ -1,26 +0,0 @@
<?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\Fixtures;
use Symfony\Component\HttpKernel\Client;
class TestClient extends Client
{
protected function getScript($request)
{
$script = parent::getScript($request);
$script = preg_replace('/(\->register\(\);)/', "$0\nrequire_once '".__DIR__."/../bootstrap.php';", $script);
return $script;
}
}

View File

@@ -1,28 +0,0 @@
<?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\Fixtures;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
class TestEventDispatcher extends EventDispatcher implements TraceableEventDispatcherInterface
{
public function getCalledListeners()
{
return array('foo');
}
public function getNotCalledListeners()
{
return array('bar');
}
}

View File

@@ -1,227 +0,0 @@
<?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\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class EsiTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
public function testHasSurrogateEsiCapability()
{
$esi = new Esi();
$request = Request::create('/');
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$this->assertTrue($esi->hasSurrogateEsiCapability($request));
$request = Request::create('/');
$request->headers->set('Surrogate-Capability', 'foobar');
$this->assertFalse($esi->hasSurrogateEsiCapability($request));
$request = Request::create('/');
$this->assertFalse($esi->hasSurrogateEsiCapability($request));
}
public function testAddSurrogateEsiCapability()
{
$esi = new Esi();
$request = Request::create('/');
$esi->addSurrogateEsiCapability($request);
$this->assertEquals('symfony2="ESI/1.0"', $request->headers->get('Surrogate-Capability'));
$esi->addSurrogateEsiCapability($request);
$this->assertEquals('symfony2="ESI/1.0", symfony2="ESI/1.0"', $request->headers->get('Surrogate-Capability'));
}
public function testAddSurrogateControl()
{
$esi = new Esi();
$response = new Response('foo <esi:include src="" />');
$esi->addSurrogateControl($response);
$this->assertEquals('content="ESI/1.0"', $response->headers->get('Surrogate-Control'));
$response = new Response('foo');
$esi->addSurrogateControl($response);
$this->assertEquals('', $response->headers->get('Surrogate-Control'));
}
public function testNeedsEsiParsing()
{
$esi = new Esi();
$response = new Response();
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
$this->assertTrue($esi->needsEsiParsing($response));
$response = new Response();
$this->assertFalse($esi->needsEsiParsing($response));
}
public function testRenderIncludeTag()
{
$esi = new Esi();
$this->assertEquals('<esi:include src="/" onerror="continue" alt="/alt" />', $esi->renderIncludeTag('/', '/alt', true));
$this->assertEquals('<esi:include src="/" alt="/alt" />', $esi->renderIncludeTag('/', '/alt', false));
$this->assertEquals('<esi:include src="/" onerror="continue" />', $esi->renderIncludeTag('/'));
$this->assertEquals('<esi:comment text="some comment" />'."\n".'<esi:include src="/" onerror="continue" alt="/alt" />', $esi->renderIncludeTag('/', '/alt', true, 'some comment'));
}
public function testProcessDoesNothingIfContentTypeIsNotHtml()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
$esi->process($request, $response);
$this->assertFalse($response->headers->has('x-body-eval'));
}
public function testProcess()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response('foo <esi:comment text="some comment" /><esi:include src="..." alt="alt" onerror="continue" />');
$esi->process($request, $response);
$this->assertEquals('foo <?php echo $this->esi->handle($this, \'...\', \'alt\', true) ?>'."\n", $response->getContent());
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$response = new Response('foo <esi:include src="..." />');
$esi->process($request, $response);
$this->assertEquals('foo <?php echo $this->esi->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
$response = new Response('foo <esi:include src="..."></esi:include>');
$esi->process($request, $response);
$this->assertEquals('foo <?php echo $this->esi->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
}
public function testProcessEscapesPhpTags()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response('foo <?php die("foo"); ?><%= "lala" %>');
$esi->process($request, $response);
$this->assertEquals('foo <?php echo "<?"; ?>php die("foo"); ?><?php echo "<%"; ?>= "lala" %>', $response->getContent());
}
/**
* @expectedException RuntimeException
*/
public function testProcessWhenNoSrcInAnEsi()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response('foo <esi:include />');
$esi->process($request, $response);
}
public function testProcessRemoveSurrogateControlHeader()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response('foo <esi:include src="..." />');
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
$esi->process($request, $response);
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$response->headers->set('Surrogate-Control', 'no-store, content="ESI/1.0"');
$esi->process($request, $response);
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$this->assertEquals('no-store', $response->headers->get('surrogate-control'));
$response->headers->set('Surrogate-Control', 'content="ESI/1.0", no-store');
$esi->process($request, $response);
$this->assertEquals('ESI', $response->headers->get('x-body-eval'));
$this->assertEquals('no-store', $response->headers->get('surrogate-control'));
}
public function testHandle()
{
$esi = new Esi();
$cache = $this->getCache(Request::create('/'), new Response('foo'));
$this->assertEquals('foo', $esi->handle($cache, '/', '/alt', true));
}
/**
* @expectedException RuntimeException
*/
public function testHandleWhenResponseIsNot200()
{
$esi = new Esi();
$response = new Response('foo');
$response->setStatusCode(404);
$cache = $this->getCache(Request::create('/'), $response);
$esi->handle($cache, '/', '/alt', false);
}
public function testHandleWhenResponseIsNot200AndErrorsAreIgnored()
{
$esi = new Esi();
$response = new Response('foo');
$response->setStatusCode(404);
$cache = $this->getCache(Request::create('/'), $response);
$this->assertEquals('', $esi->handle($cache, '/', '/alt', true));
}
public function testHandleWhenResponseIsNot200AndAltIsPresent()
{
$esi = new Esi();
$response1 = new Response('foo');
$response1->setStatusCode(404);
$response2 = new Response('bar');
$cache = $this->getCache(Request::create('/'), array($response1, $response2));
$this->assertEquals('bar', $esi->handle($cache, '/', '/alt', false));
}
protected function getCache($request, $response)
{
$cache = $this->getMock('Symfony\Component\HttpKernel\HttpCache\HttpCache', array('getRequest', 'handle'), array(), '', false);
$cache->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
;
if (is_array($response)) {
$cache->expects($this->any())
->method('handle')
->will(call_user_func_array(array($this, 'onConsecutiveCalls'), $response))
;
} else {
$cache->expects($this->any())
->method('handle')
->will($this->returnValue($response))
;
}
return $cache;
}
}

View File

@@ -1,179 +0,0 @@
<?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\HttpCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
{
protected $kernel;
protected $cache;
protected $caches;
protected $cacheConfig;
protected $request;
protected $response;
protected $responses;
protected $catch;
protected $esi;
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
$this->kernel = null;
$this->cache = null;
$this->esi = null;
$this->caches = array();
$this->cacheConfig = array();
$this->request = null;
$this->response = null;
$this->responses = array();
$this->catch = false;
$this->clearDirectory(sys_get_temp_dir().'/http_cache');
}
protected function tearDown()
{
$this->kernel = null;
$this->cache = null;
$this->caches = null;
$this->request = null;
$this->response = null;
$this->responses = null;
$this->cacheConfig = null;
$this->catch = null;
$this->esi = null;
$this->clearDirectory(sys_get_temp_dir().'/http_cache');
}
public function assertHttpKernelIsCalled()
{
$this->assertTrue($this->kernel->hasBeenCalled());
}
public function assertHttpKernelIsNotCalled()
{
$this->assertFalse($this->kernel->hasBeenCalled());
}
public function assertResponseOk()
{
$this->assertEquals(200, $this->response->getStatusCode());
}
public function assertTraceContains($trace)
{
$traces = $this->cache->getTraces();
$traces = current($traces);
$this->assertRegExp('/'.$trace.'/', implode(', ', $traces));
}
public function assertTraceNotContains($trace)
{
$traces = $this->cache->getTraces();
$traces = current($traces);
$this->assertNotRegExp('/'.$trace.'/', implode(', ', $traces));
}
public function assertExceptionsAreCaught()
{
$this->assertTrue($this->kernel->isCatchingExceptions());
}
public function assertExceptionsAreNotCaught()
{
$this->assertFalse($this->kernel->isCatchingExceptions());
}
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false)
{
if (null === $this->kernel) {
throw new \LogicException('You must call setNextResponse() before calling request().');
}
$this->kernel->reset();
$this->store = new Store(sys_get_temp_dir().'/http_cache');
$this->cacheConfig['debug'] = true;
$this->esi = $esi ? new Esi() : null;
$this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
$this->request = Request::create($uri, $method, array(), $cookies, array(), $server);
$this->response = $this->cache->handle($this->request, HttpKernelInterface::MASTER_REQUEST, $this->catch);
$this->responses[] = $this->response;
}
public function getMetaStorageValues()
{
$values = array();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(sys_get_temp_dir().'/http_cache/md', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
$values[] = file_get_contents($file);
}
return $values;
}
// A basic response with 200 status code and a tiny body.
public function setNextResponse($statusCode = 200, array $headers = array(), $body = 'Hello World', \Closure $customizer = null)
{
$this->kernel = new TestHttpKernel($body, $statusCode, $headers, $customizer);
}
public function setNextResponses($responses)
{
$this->kernel = new TestMultipleHttpKernel($responses);
}
public function catchExceptions($catch = true)
{
$this->catch = $catch;
}
public static function clearDirectory($directory)
{
if (!is_dir($directory)) {
return;
}
$fp = opendir($directory);
while (false !== $file = readdir($fp)) {
if (!in_array($file, array('.', '..'))) {
if (is_link($directory.'/'.$file)) {
unlink($directory.'/'.$file);
} elseif (is_dir($directory.'/'.$file)) {
self::clearDirectory($directory.'/'.$file);
rmdir($directory.'/'.$file);
} else {
unlink($directory.'/'.$file);
}
}
}
closedir($fp);
}
}

View File

@@ -1,232 +0,0 @@
<?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\HttpCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\Store;
class StoreTest extends \PHPUnit_Framework_TestCase
{
protected $request;
protected $response;
protected $store;
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
$this->request = Request::create('/');
$this->response = new Response('hello world', 200, array());
HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');
$this->store = new Store(sys_get_temp_dir().'/http_cache');
}
protected function tearDown()
{
$this->store = null;
$this->request = null;
$this->response = null;
HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');
}
public function testReadsAnEmptyArrayWithReadWhenNothingCachedAtKey()
{
$this->assertEmpty($this->getStoreMetadata('/nothing'));
}
public function testRemovesEntriesForKeyWithPurge()
{
$request = Request::create('/foo');
$this->store->write($request, new Response('foo'));
$this->assertNotEmpty($this->getStoreMetadata($request));
$this->assertTrue($this->store->purge('/foo'));
$this->assertEmpty($this->getStoreMetadata($request));
$this->assertFalse($this->store->purge('/bar'));
}
public function testStoresACacheEntry()
{
$cacheKey = $this->storeSimpleEntry();
$this->assertNotEmpty($this->getStoreMetadata($cacheKey));
}
public function testSetsTheXContentDigestResponseHeaderBeforeStoring()
{
$cacheKey = $this->storeSimpleEntry();
$entries = $this->getStoreMetadata($cacheKey);
list ($req, $res) = $entries[0];
$this->assertEquals('ena94a8fe5ccb19ba61c4c0873d391e987982fbbd3', $res['x-content-digest'][0]);
}
public function testFindsAStoredEntryWithLookup()
{
$this->storeSimpleEntry();
$response = $this->store->lookup($this->request);
$this->assertNotNull($response);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
}
public function testDoesNotFindAnEntryWithLookupWhenNoneExists()
{
$request = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$this->assertNull($this->store->lookup($request));
}
public function testCanonizesUrlsForCacheKeys()
{
$this->storeSimpleEntry($path = '/test?x=y&p=q');
$hitsReq = Request::create($path);
$missReq = Request::create('/test?p=x');
$this->assertNotNull($this->store->lookup($hitsReq));
$this->assertNull($this->store->lookup($missReq));
}
public function testDoesNotFindAnEntryWithLookupWhenTheBodyDoesNotExist()
{
$this->storeSimpleEntry();
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
$path = $this->getStorePath($this->response->headers->get('X-Content-Digest'));
@unlink($path);
$this->assertNull($this->store->lookup($this->request));
}
public function testRestoresResponseHeadersProperlyWithLookup()
{
$this->storeSimpleEntry();
$response = $this->store->lookup($this->request);
$this->assertEquals($response->headers->all(), array_merge(array('content-length' => 4, 'x-body-file' => array($this->getStorePath($response->headers->get('X-Content-Digest')))), $this->response->headers->all()));
}
public function testRestoresResponseContentFromEntityStoreWithLookup()
{
$this->storeSimpleEntry();
$response = $this->store->lookup($this->request);
$this->assertEquals($this->getStorePath('en'.sha1('test')), $response->getContent());
}
public function testInvalidatesMetaAndEntityStoreEntriesWithInvalidate()
{
$this->storeSimpleEntry();
$this->store->invalidate($this->request);
$response = $this->store->lookup($this->request);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertFalse($response->isFresh());
}
public function testSucceedsQuietlyWhenInvalidateCalledWithNoMatchingEntries()
{
$req = Request::create('/test');
$this->store->invalidate($req);
$this->assertNull($this->store->lookup($this->request));
}
public function testDoesNotReturnEntriesThatVaryWithLookup()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res = new Response('test', 200, array('Vary' => 'Foo Bar'));
$this->store->write($req1, $res);
$this->assertNull($this->store->lookup($req2));
}
public function testStoresMultipleResponsesForEachVaryCombination()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
$key = $this->store->write($req1, $res1);
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
$this->store->write($req2, $res2);
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Baz', 'HTTP_BAR' => 'Boom'));
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
$this->store->write($req3, $res3);
$this->assertEquals($this->getStorePath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
$this->assertEquals($this->getStorePath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
$this->assertEquals($this->getStorePath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
$this->assertCount(3, $this->getStoreMetadata($key));
}
public function testOverwritesNonVaryingResponseWithStore()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
$key = $this->store->write($req1, $res1);
$this->assertEquals($this->getStorePath('en'.sha1('test 1')), $this->store->lookup($req1)->getContent());
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
$this->store->write($req2, $res2);
$this->assertEquals($this->getStorePath('en'.sha1('test 2')), $this->store->lookup($req2)->getContent());
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
$key = $this->store->write($req3, $res3);
$this->assertEquals($this->getStorePath('en'.sha1('test 3')), $this->store->lookup($req3)->getContent());
$this->assertCount(2, $this->getStoreMetadata($key));
}
protected function storeSimpleEntry($path = null, $headers = array())
{
if (null === $path) {
$path = '/test';
}
$this->request = Request::create($path, 'get', array(), array(), array(), $headers);
$this->response = new Response('test', 200, array('Cache-Control' => 'max-age=420'));
return $this->store->write($this->request, $this->response);
}
protected function getStoreMetadata($key)
{
$r = new \ReflectionObject($this->store);
$m = $r->getMethod('getMetadata');
$m->setAccessible(true);
if ($key instanceof Request) {
$m1 = $r->getMethod('getCacheKey');
$m1->setAccessible(true);
$key = $m1->invoke($this->store, $key);
}
return $m->invoke($this->store, $key);
}
protected function getStorePath($key)
{
$r = new \ReflectionObject($this->store);
$m = $r->getMethod('getPath');
$m->setAccessible(true);
return $m->invoke($this->store, $key);
}
}

View File

@@ -1,86 +0,0 @@
<?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\HttpCache;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
{
protected $body;
protected $status;
protected $headers;
protected $called;
protected $customizer;
protected $catch;
public function __construct($body, $status, $headers, \Closure $customizer = null)
{
$this->body = $body;
$this->status = $status;
$this->headers = $headers;
$this->customizer = $customizer;
$this->called = false;
$this->catch = false;
parent::__construct(new EventDispatcher(), $this);
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
{
$this->catch = $catch;
return parent::handle($request, $type, $catch);
}
public function isCatchingExceptions()
{
return $this->catch;
}
public function getController(Request $request)
{
return array($this, 'callController');
}
public function getArguments(Request $request, $controller)
{
return array($request);
}
public function callController(Request $request)
{
$this->called = true;
$response = new Response($this->body, $this->status, $this->headers);
if (null !== $this->customizer) {
call_user_func($this->customizer, $request, $response);
}
return $response;
}
public function hasBeenCalled()
{
return $this->called;
}
public function reset()
{
$this->called = false;
}
}

View File

@@ -1,78 +0,0 @@
<?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\HttpCache;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface
{
protected $bodies;
protected $statuses;
protected $headers;
protected $catch;
protected $call;
public function __construct($responses)
{
$this->bodies = array();
$this->statuses = array();
$this->headers = array();
$this->call = false;
foreach ($responses as $response) {
$this->bodies[] = $response['body'];
$this->statuses[] = $response['status'];
$this->headers[] = $response['headers'];
}
parent::__construct(new EventDispatcher(), $this);
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
{
return parent::handle($request, $type, $catch);
}
public function getController(Request $request)
{
return array($this, 'callController');
}
public function getArguments(Request $request, $controller)
{
return array($request);
}
public function callController(Request $request)
{
$this->called = true;
$response = new Response(array_shift($this->bodies), array_shift($this->statuses), array_shift($this->headers));
return $response;
}
public function hasBeenCalled()
{
return $this->called;
}
public function reset()
{
$this->call = false;
}
}

View File

@@ -1,297 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\EventDispatcher\EventDispatcher;
class HttpKernelTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
/**
* @expectedException RuntimeException
*/
public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue()
{
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
}
/**
* @expectedException RuntimeException
*/
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalseAndNoListenerIsRegistered()
{
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
}
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalse()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
$event->setResponse(new Response($event->getException()->getMessage()));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
$response = $kernel->handle(new Request());
$this->assertEquals('500', $response->getStatusCode());
$this->assertEquals('foo', $response->getContent());
}
public function testHandleExceptionWithARedirectionResponse()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
$event->setResponse(new RedirectResponse('/login', 301));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new AccessDeniedHttpException(); }));
$response = $kernel->handle(new Request());
$this->assertEquals('301', $response->getStatusCode());
$this->assertEquals('/login', $response->headers->get('Location'));
}
public function testHandleHttpException()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
$event->setResponse(new Response($event->getException()->getMessage()));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new MethodNotAllowedHttpException(array('POST')); }));
$response = $kernel->handle(new Request());
$this->assertEquals('405', $response->getStatusCode());
$this->assertEquals('POST', $response->headers->get('Allow'));
}
/**
* @dataProvider getStatusCodes
*/
public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($responseStatusCode, $expectedStatusCode)
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) use ($responseStatusCode, $expectedStatusCode) {
$event->setResponse(new Response('', $responseStatusCode, array('X-Status-Code' => $expectedStatusCode)));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException(); }));
$response = $kernel->handle(new Request());
$this->assertEquals($expectedStatusCode, $response->getStatusCode());
$this->assertFalse($response->headers->has('X-Status-Code'));
}
public function getStatusCodes()
{
return array(
array(200, 404),
array(404, 200),
array(301, 200),
array(500, 200),
);
}
public function testHandleWhenAListenerReturnsAResponse()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::REQUEST, function ($event) {
$event->setResponse(new Response('hello'));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver());
$this->assertEquals('hello', $kernel->handle(new Request())->getContent());
}
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testHandleWhenNoControllerIsFound()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(false));
$kernel->handle(new Request());
}
/**
* @expectedException LogicException
*/
public function testHandleWhenTheControllerIsNotACallable()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver('foobar'));
$kernel->handle(new Request());
}
public function testHandleWhenTheControllerIsAClosure()
{
$response = new Response('foo');
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () use ($response) { return $response; }));
$this->assertSame($response, $kernel->handle(new Request()));
}
public function testHandleWhenTheControllerIsAnObjectWithInvoke()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(new Controller()));
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
public function testHandleWhenTheControllerIsAFunction()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver('Symfony\Component\HttpKernel\Tests\controller_func'));
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
public function testHandleWhenTheControllerIsAnArray()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(array(new Controller(), 'controller')));
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
public function testHandleWhenTheControllerIsAStaticArray()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(array('Symfony\Component\HttpKernel\Tests\Controller', 'staticcontroller')));
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
/**
* @expectedException LogicException
*/
public function testHandleWhenTheControllerDoesNotReturnAResponse()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));
$kernel->handle(new Request());
}
public function testHandleWhenTheControllerDoesNotReturnAResponseButAViewIsRegistered()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::VIEW, function ($event) {
$event->setResponse(new Response($event->getControllerResult()));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));
$this->assertEquals('foo', $kernel->handle(new Request())->getContent());
}
public function testHandleWithAResponseListener()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::RESPONSE, function ($event) {
$event->setResponse(new Response('foo'));
});
$kernel = new HttpKernel($dispatcher, $this->getResolver());
$this->assertEquals('foo', $kernel->handle(new Request())->getContent());
}
public function testTerminate()
{
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver());
$dispatcher->addListener(KernelEvents::TERMINATE, function ($event) use (&$called, &$capturedKernel, &$capturedRequest, &$capturedResponse) {
$called = true;
$capturedKernel = $event->getKernel();
$capturedRequest = $event->getRequest();
$capturedResponse = $event->getResponse();
});
$kernel->terminate($request = Request::create('/'), $response = new Response());
$this->assertTrue($called);
$this->assertEquals($kernel, $capturedKernel);
$this->assertEquals($request, $capturedRequest);
$this->assertEquals($response, $capturedResponse);
}
protected function getResolver($controller = null)
{
if (null === $controller) {
$controller = function() { return new Response('Hello'); };
}
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
$resolver->expects($this->any())
->method('getController')
->will($this->returnValue($controller));
$resolver->expects($this->any())
->method('getArguments')
->will($this->returnValue(array()));
return $resolver;
}
protected function assertResponseEquals(Response $expected, Response $actual)
{
$expected->setDate($actual->getDate());
$this->assertEquals($expected, $actual);
}
}
class Controller
{
public function __invoke()
{
return new Response('foo');
}
public function controller()
{
return new Response('foo');
}
public static function staticController()
{
return new Response('foo');
}
}
function controller_func()
{
return new Response('foo');
}

View File

@@ -1,784 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
use Symfony\Component\HttpKernel\Tests\Fixtures\FooBarBundle;
class KernelTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\DependencyInjection\Container')) {
$this->markTestSkipped('The "DependencyInjection" component is not available');
}
}
public function testConstructor()
{
$env = 'test_env';
$debug = true;
$kernel = new KernelForTest($env, $debug);
$this->assertEquals($env, $kernel->getEnvironment());
$this->assertEquals($debug, $kernel->isDebug());
$this->assertFalse($kernel->isBooted());
$this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());
$this->assertNull($kernel->getContainer());
}
public function testClone()
{
$env = 'test_env';
$debug = true;
$kernel = new KernelForTest($env, $debug);
$clone = clone $kernel;
$this->assertEquals($env, $clone->getEnvironment());
$this->assertEquals($debug, $clone->isDebug());
$this->assertFalse($clone->isBooted());
$this->assertLessThanOrEqual(microtime(true), $clone->getStartTime());
$this->assertNull($clone->getContainer());
}
public function testBootInitializesBundlesAndContainer()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles'))
->getMock();
$kernel->expects($this->once())
->method('initializeBundles');
$kernel->expects($this->once())
->method('initializeContainer');
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array()));
$kernel->boot();
}
public function testBootSetsTheContainerToTheBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')
->disableOriginalConstructor()
->getMock();
$bundle->expects($this->once())
->method('setContainer');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array($bundle)));
$kernel->boot();
}
public function testBootSetsTheBootedFlagToTrue()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array()));
$kernel->boot();
$this->assertTrue($kernel->isBooted());
}
public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array()));
$kernel->boot();
$kernel->boot();
}
public function testShutdownCallsShutdownOnAllBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')
->disableOriginalConstructor()
->getMock();
$bundle->expects($this->once())
->method('shutdown');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array($bundle)));
$kernel->shutdown();
}
public function testShutdownGivesNullContainerToAllBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')
->disableOriginalConstructor()
->getMock();
$bundle->expects($this->once())
->method('setContainer')
->with(null);
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array($bundle)));
$kernel->shutdown();
}
public function testHandleCallsHandleOnHttpKernel()
{
$type = HttpKernelInterface::MASTER_REQUEST;
$catch = true;
$request = new Request();
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->disableOriginalConstructor()
->getMock();
$httpKernelMock
->expects($this->once())
->method('handle')
->with($request, $type, $catch);
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getHttpKernel'))
->getMock();
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
$kernel->handle($request, $type, $catch);
}
public function testHandleBootsTheKernel()
{
$type = HttpKernelInterface::MASTER_REQUEST;
$catch = true;
$request = new Request();
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->disableOriginalConstructor()
->getMock();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getHttpKernel', 'boot'))
->getMock();
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
$kernel->expects($this->once())
->method('boot');
// required as this value is initialized
// in the kernel constructor, which we don't call
$kernel->setIsBooted(false);
$kernel->handle($request, $type, $catch);
}
public function testStripComments()
{
if (!function_exists('token_get_all')) {
$this->markTestSkipped('The function token_get_all() is not available.');
return;
}
$source = <<<EOF
<?php
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<EOF
<?php
class TestClass
{
public function doStuff()
{
}
}
EOF;
$this->assertEquals($expected, Kernel::stripComments($source));
}
public function testIsClassInActiveBundleFalse()
{
$kernel = $this->getKernelMockForIsClassInActiveBundleTest();
$this->assertFalse($kernel->isClassInActiveBundle('Not\In\Active\Bundle'));
}
public function testIsClassInActiveBundleFalseNoNamespace()
{
$kernel = $this->getKernelMockForIsClassInActiveBundleTest();
$this->assertFalse($kernel->isClassInActiveBundle('NotNamespacedClass'));
}
public function testIsClassInActiveBundleTrue()
{
$kernel = $this->getKernelMockForIsClassInActiveBundleTest();
$this->assertTrue($kernel->isClassInActiveBundle(__NAMESPACE__.'\Fixtures\FooBarBundle\SomeClass'));
}
protected function getKernelMockForIsClassInActiveBundleTest()
{
$bundle = new FooBarBundle();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getBundles'))
->getMock();
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array($bundle)));
return $kernel;
}
public function testGetRootDir()
{
$kernel = new KernelForTest('test', true);
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
}
public function testGetName()
{
$kernel = new KernelForTest('test', true);
$this->assertEquals('Fixtures', $kernel->getName());
}
public function testOverrideGetName()
{
$kernel = new KernelForOverrideName('test', true);
$this->assertEquals('overridden', $kernel->getName());
}
public function testSerialize()
{
$env = 'test_env';
$debug = true;
$kernel = new KernelForTest($env, $debug);
$expected = serialize(array($env, $debug));
$this->assertEquals($expected, $kernel->serialize());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testLocateResourceThrowsExceptionWhenNameIsNotValid()
{
$this->getKernelForInvalidLocateResource()->locateResource('Foo');
}
/**
* @expectedException \RuntimeException
*/
public function testLocateResourceThrowsExceptionWhenNameIsUnsafe()
{
$this->getKernelForInvalidLocateResource()->locateResource('@FooBundle/../bar');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist()
{
$this->getKernelForInvalidLocateResource()->locateResource('@FooBundle/config/routing.xml');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testLocateResourceThrowsExceptionWhenResourceDoesNotExist()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
;
$kernel->locateResource('@Bundle1Bundle/config/routing.xml');
}
public function testLocateResourceReturnsTheFirstThatMatches()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
}
public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
$child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle');
$kernel = $this->getKernel();
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(__DIR__.'/Fixtures/Bundle2Bundle/foo.txt', $kernel->locateResource('@ParentAABundle/foo.txt'));
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt'));
}
public function testLocateResourceReturnsAllMatches()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
$child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Bundle2Bundle/foo.txt',
__DIR__.'/Fixtures/Bundle1Bundle/foo.txt'),
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false));
}
public function testLocateResourceReturnsAllMatchesBis()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array(
$this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'),
$this->getBundle(__DIR__.'/Foobar')
)))
;
$this->assertEquals(
array(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt'),
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false)
);
}
public function testLocateResourceIgnoresDirOnNonResource()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))))
;
$this->assertEquals(
__DIR__.'/Fixtures/Bundle1Bundle/foo.txt',
$kernel->locateResource('@Bundle1Bundle/foo.txt', __DIR__.'/Fixtures')
);
}
public function testLocateResourceReturnsTheDirOneForResources()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))))
;
$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle/foo.txt',
$kernel->locateResource('@FooBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources')
);
}
public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
{
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Resources/Bundle1Bundle/foo.txt',
__DIR__.'/Fixtures/Bundle1Bundle/Resources/foo.txt'),
$kernel->locateResource('@Bundle1Bundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false)
);
}
public function testLocateResourceOverrideBundleAndResourcesFolders()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle');
$child = $this->getBundle(__DIR__.'/Fixtures/ChildBundle', 'ParentBundle', 'ChildBundle', 'ChildBundle');
$kernel = $this->getKernel();
$kernel
->expects($this->exactly(4))
->method('getBundle')
->will($this->returnValue(array($child, $parent)))
;
$this->assertEquals(array(
__DIR__.'/Fixtures/Resources/ChildBundle/foo.txt',
__DIR__.'/Fixtures/ChildBundle/Resources/foo.txt',
__DIR__.'/Fixtures/BaseBundle/Resources/foo.txt',
),
$kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false)
);
$this->assertEquals(
__DIR__.'/Fixtures/Resources/ChildBundle/foo.txt',
$kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources')
);
try {
$kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', false);
$this->fail('Hidden resources should raise an exception when returning an array of matching paths');
} catch (\RuntimeException $e) {
}
try {
$kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', true);
$this->fail('Hidden resources should raise an exception when returning the first matching path');
} catch (\RuntimeException $e) {
}
}
public function testLocateResourceOnDirectories()
{
$kernel = $this->getKernel();
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))))
;
$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle/',
$kernel->locateResource('@FooBundle/Resources/', __DIR__.'/Fixtures/Resources')
);
$this->assertEquals(
__DIR__.'/Fixtures/Resources/FooBundle',
$kernel->locateResource('@FooBundle/Resources', __DIR__.'/Fixtures/Resources')
);
$kernel = $this->getKernel();
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))))
;
$this->assertEquals(
__DIR__.'/Fixtures/Bundle1Bundle/Resources/',
$kernel->locateResource('@Bundle1Bundle/Resources/')
);
$this->assertEquals(
__DIR__.'/Fixtures/Bundle1Bundle/Resources',
$kernel->locateResource('@Bundle1Bundle/Resources')
);
}
public function testInitializeBundles()
{
$parent = $this->getBundle(null, null, 'ParentABundle');
$child = $this->getBundle(null, 'ParentABundle', 'ChildABundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($parent, $child)))
;
$kernel->initializeBundles();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent), $map['ParentABundle']);
}
public function testInitializeBundlesSupportInheritanceCascade()
{
$grandparent = $this->getBundle(null, null, 'GrandParentBBundle');
$parent = $this->getBundle(null, 'GrandParentBBundle', 'ParentBBundle');
$child = $this->getBundle(null, 'ParentBBundle', 'ChildBBundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($grandparent, $parent, $child)))
;
$kernel->initializeBundles();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentBBundle']);
$this->assertEquals(array($child, $parent), $map['ParentBBundle']);
$this->assertEquals(array($child), $map['ChildBBundle']);
}
/**
* @expectedException \LogicException
*/
public function testInitializeBundlesThrowsExceptionWhenAParentDoesNotExists()
{
$child = $this->getBundle(null, 'FooBar', 'ChildCBundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($child)))
;
$kernel->initializeBundles();
}
public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
{
$grandparent = $this->getBundle(null, null, 'GrandParentCCundle');
$parent = $this->getBundle(null, 'GrandParentCCundle', 'ParentCCundle');
$child = $this->getBundle(null, 'ParentCCundle', 'ChildCCundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($parent, $grandparent, $child)))
;
$kernel->initializeBundles();
$map = $kernel->getBundleMap();
$this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentCCundle']);
$this->assertEquals(array($child, $parent), $map['ParentCCundle']);
$this->assertEquals(array($child), $map['ChildCCundle']);
}
/**
* @expectedException \LogicException
*/
public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtendedByTwoBundles()
{
$parent = $this->getBundle(null, null, 'ParentCBundle');
$child1 = $this->getBundle(null, 'ParentCBundle', 'ChildC1Bundle');
$child2 = $this->getBundle(null, 'ParentCBundle', 'ChildC2Bundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($parent, $child1, $child2)))
;
$kernel->initializeBundles();
}
/**
* @expectedException \LogicException
*/
public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWithTheSameName()
{
$fooBundle = $this->getBundle(null, null, 'FooBundle', 'DuplicateName');
$barBundle = $this->getBundle(null, null, 'BarBundle', 'DuplicateName');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($fooBundle, $barBundle)))
;
$kernel->initializeBundles();
}
/**
* @expectedException \LogicException
*/
public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself()
{
$circularRef = $this->getBundle(null, 'CircularRefBundle', 'CircularRefBundle');
$kernel = $this->getKernel();
$kernel
->expects($this->once())
->method('registerBundles')
->will($this->returnValue(array($circularRef)))
;
$kernel->initializeBundles();
}
public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getHttpKernel'))
->getMock();
$kernel->expects($this->never())
->method('getHttpKernel');
$kernel->setIsBooted(false);
$kernel->terminate(Request::create('/'), new Response());
}
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
{
// does not implement TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
->disableOriginalConstructor()
->getMock();
$httpKernelMock
->expects($this->never())
->method('terminate');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getHttpKernel'))
->getMock();
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
$kernel->setIsBooted(true);
$kernel->terminate(Request::create('/'), new Response());
// implements TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->disableOriginalConstructor()
->setMethods(array('terminate'))
->getMock();
$httpKernelMock
->expects($this->once())
->method('terminate');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getHttpKernel'))
->getMock();
$kernel->expects($this->exactly(2))
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
$kernel->setIsBooted(true);
$kernel->terminate(Request::create('/'), new Response());
}
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)
{
$bundle = $this
->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')
->setMethods(array('getPath', 'getParent', 'getName'))
->disableOriginalConstructor()
;
if ($className) {
$bundle->setMockClassName($className);
}
$bundle = $bundle->getMockForAbstractClass();
$bundle
->expects($this->any())
->method('getName')
->will($this->returnValue(null === $bundleName ? get_class($bundle) : $bundleName))
;
$bundle
->expects($this->any())
->method('getPath')
->will($this->returnValue($dir))
;
$bundle
->expects($this->any())
->method('getParent')
->will($this->returnValue($parent))
;
return $bundle;
}
protected function getKernel()
{
return $this
->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->setMethods(array('getBundle', 'registerBundles'))
->disableOriginalConstructor()
->getMock()
;
}
protected function getKernelForInvalidLocateResource()
{
return $this
->getMockBuilder('Symfony\Component\HttpKernel\Kernel')
->disableOriginalConstructor()
->getMockForAbstractClass()
;
}
}

View File

@@ -1,88 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
class Logger implements LoggerInterface
{
protected $logs;
public function __construct()
{
$this->clear();
}
public function getLogs($priority = false)
{
return false === $priority ? $this->logs : $this->logs[$priority];
}
public function clear()
{
$this->logs = array(
'emerg' => array(),
'alert' => array(),
'crit' => array(),
'err' => array(),
'warn' => array(),
'notice' => array(),
'info' => array(),
'debug' => array(),
);
}
public function log($message, $priority)
{
$this->logs[$priority][] = $message;
}
public function emerg($message, array $context = array())
{
$this->log($message, 'emerg');
}
public function alert($message, array $context = array())
{
$this->log($message, 'alert');
}
public function crit($message, array $context = array())
{
$this->log($message, 'crit');
}
public function err($message, array $context = array())
{
$this->log($message, 'err');
}
public function warn($message, array $context = array())
{
$this->log($message, 'warn');
}
public function notice($message, array $context = array())
{
$this->log($message, 'notice');
}
public function info($message, array $context = array())
{
$this->log($message, 'info');
}
public function debug($message, array $context = array())
{
$this->log($message, 'debug');
}
}

View File

@@ -1,232 +0,0 @@
<?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');
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');
$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');
}
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 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();
}

View File

@@ -1,85 +0,0 @@
<?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));
}
}

View File

@@ -1,49 +0,0 @@
<?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;
}
}

View File

@@ -1,49 +0,0 @@
<?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;
}
}

View File

@@ -1,260 +0,0 @@
<?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;
}
}

View File

@@ -1,225 +0,0 @@
<?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;
}
}

View File

@@ -1,241 +0,0 @@
<?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 memcached 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;
}
}

View File

@@ -1,81 +0,0 @@
<?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;
class DummyMongoDbProfilerStorage extends MongoDbProfilerStorage
{
public function getMongo()
{
return parent::getMongo();
}
}
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();
}
/**
* @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');
}
}
}

View File

@@ -1,56 +0,0 @@
<?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);
}
}

View File

@@ -1,49 +0,0 @@
<?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;
}
}

View File

@@ -1,50 +0,0 @@
<?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;
}
}

View File

@@ -1,41 +0,0 @@
<?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;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
{
public function __construct()
{
parent::__construct(new EventDispatcher(), $this);
}
public function getController(Request $request)
{
return array($this, 'callController');
}
public function getArguments(Request $request, $controller)
{
return array($request);
}
public function callController(Request $request)
{
return new Response('Request: '.$request->getRequestUri());
}
}

View File

@@ -1,22 +0,0 @@
<?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.
*/
spl_autoload_register(function ($class) {
if (0 === strpos(ltrim($class, '/'), 'Symfony\Component\HttpKernel')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\HttpKernel')).'.php')) {
require_once $file;
}
}
});
if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="Tests/bootstrap.php"
>
<testsuites>
<testsuite name="Symfony HttpKernel Component Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>