Added Laravel project
This commit is contained in:
67
Laravel/vendor/symfony/http-kernel/Tests/Debug/FileLinkFormatterTest.php
vendored
Normal file
67
Laravel/vendor/symfony/http-kernel/Tests/Debug/FileLinkFormatterTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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 PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||
|
||||
class FileLinkFormatterTest extends TestCase
|
||||
{
|
||||
public function testWhenNoFileLinkFormatAndNoRequest()
|
||||
{
|
||||
$sut = new FileLinkFormatter();
|
||||
|
||||
$this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
|
||||
}
|
||||
|
||||
public function testWhenFileLinkFormatAndNoRequest()
|
||||
{
|
||||
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
|
||||
|
||||
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
|
||||
|
||||
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
|
||||
}
|
||||
|
||||
public function testWhenFileLinkFormatAndRequest()
|
||||
{
|
||||
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
|
||||
$baseDir = __DIR__;
|
||||
$requestStack = new RequestStack();
|
||||
$request = new Request();
|
||||
$requestStack->push($request);
|
||||
|
||||
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
|
||||
|
||||
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
|
||||
}
|
||||
|
||||
public function testWhenNoFileLinkFormatAndRequest()
|
||||
{
|
||||
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
|
||||
$requestStack = new RequestStack();
|
||||
$request = new Request();
|
||||
$requestStack->push($request);
|
||||
|
||||
$request->server->set('SERVER_NAME', 'www.example.org');
|
||||
$request->server->set('SERVER_PORT', 80);
|
||||
$request->server->set('SCRIPT_NAME', '/app.php');
|
||||
$request->server->set('SCRIPT_FILENAME', '/web/app.php');
|
||||
$request->server->set('REQUEST_URI', '/app.php/example');
|
||||
|
||||
$sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
|
||||
|
||||
$this->assertSame('http://www.example.org/app.php/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
|
||||
}
|
||||
}
|
121
Laravel/vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php
vendored
Normal file
121
Laravel/vendor/symfony/http-kernel/Tests/Debug/TraceableEventDispatcherTest.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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 PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
class TraceableEventDispatcherTest extends TestCase
|
||||
{
|
||||
public function testStopwatchSections()
|
||||
{
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch = new Stopwatch());
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
|
||||
$request = Request::create('/');
|
||||
$response = $kernel->handle($request);
|
||||
$kernel->terminate($request, $response);
|
||||
|
||||
$events = $stopwatch->getSectionEvents($response->headers->get('X-Debug-Token'));
|
||||
$this->assertEquals(array(
|
||||
'__section__',
|
||||
'kernel.request',
|
||||
'kernel.controller',
|
||||
'kernel.controller_arguments',
|
||||
'controller',
|
||||
'kernel.response',
|
||||
'kernel.terminate',
|
||||
), array_keys($events));
|
||||
}
|
||||
|
||||
public function testStopwatchCheckControllerOnRequestEvent()
|
||||
{
|
||||
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
|
||||
->setMethods(array('isStarted'))
|
||||
->getMock();
|
||||
$stopwatch->expects($this->once())
|
||||
->method('isStarted')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
|
||||
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
|
||||
$request = Request::create('/');
|
||||
$kernel->handle($request);
|
||||
}
|
||||
|
||||
public function testStopwatchStopControllerOnRequestEvent()
|
||||
{
|
||||
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
|
||||
->setMethods(array('isStarted', 'stop', 'stopSection'))
|
||||
->getMock();
|
||||
$stopwatch->expects($this->once())
|
||||
->method('isStarted')
|
||||
->will($this->returnValue(true));
|
||||
$stopwatch->expects($this->once())
|
||||
->method('stop');
|
||||
$stopwatch->expects($this->once())
|
||||
->method('stopSection');
|
||||
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
|
||||
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
|
||||
$request = Request::create('/');
|
||||
$kernel->handle($request);
|
||||
}
|
||||
|
||||
public function testAddListenerNested()
|
||||
{
|
||||
$called1 = false;
|
||||
$called2 = false;
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$dispatcher->addListener('my-event', function () use ($dispatcher, &$called1, &$called2) {
|
||||
$called1 = true;
|
||||
$dispatcher->addListener('my-event', function () use (&$called2) {
|
||||
$called2 = true;
|
||||
});
|
||||
});
|
||||
$dispatcher->dispatch('my-event');
|
||||
$this->assertTrue($called1);
|
||||
$this->assertFalse($called2);
|
||||
$dispatcher->dispatch('my-event');
|
||||
$this->assertTrue($called2);
|
||||
}
|
||||
|
||||
public function testListenerCanRemoveItselfWhenExecuted()
|
||||
{
|
||||
$eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$listener1 = function () use ($eventDispatcher, &$listener1) {
|
||||
$eventDispatcher->removeListener('foo', $listener1);
|
||||
};
|
||||
$eventDispatcher->addListener('foo', $listener1);
|
||||
$eventDispatcher->addListener('foo', function () {});
|
||||
$eventDispatcher->dispatch('foo');
|
||||
|
||||
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
|
||||
}
|
||||
|
||||
protected function getHttpKernel($dispatcher, $controller)
|
||||
{
|
||||
$controllerResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();
|
||||
$controllerResolver->expects($this->once())->method('getController')->will($this->returnValue($controller));
|
||||
$argumentResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface')->getMock();
|
||||
$argumentResolver->expects($this->once())->method('getArguments')->will($this->returnValue(array()));
|
||||
|
||||
return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user