Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
60
vendor/stack/builder/tests/functional/SilexApplicationTest.php
vendored
Normal file
60
vendor/stack/builder/tests/functional/SilexApplicationTest.php
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace functional;
|
||||
|
||||
use Silex\Application;
|
||||
use Stack\Builder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class SilexApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testWithAppendMiddlewares()
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
$app->get('/foo', function () {
|
||||
return 'bar';
|
||||
});
|
||||
|
||||
$finished = false;
|
||||
|
||||
$app->finish(function () use (&$finished) {
|
||||
$finished = true;
|
||||
});
|
||||
|
||||
$stack = new Builder();
|
||||
$stack
|
||||
->push('functional\Append', '.A')
|
||||
->push('functional\Append', '.B');
|
||||
|
||||
$app = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/foo');
|
||||
$response = $app->handle($request);
|
||||
$app->terminate($request, $response);
|
||||
|
||||
$this->assertSame('bar.B.A', $response->getContent());
|
||||
$this->assertTrue($finished);
|
||||
}
|
||||
}
|
||||
|
||||
class Append implements HttpKernelInterface
|
||||
{
|
||||
private $app;
|
||||
private $appendix;
|
||||
|
||||
public function __construct(HttpKernelInterface $app, $appendix)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->appendix = $appendix;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
$response = clone $this->app->handle($request, $type, $catch);
|
||||
$response->setContent($response->getContent().$this->appendix);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
215
vendor/stack/builder/tests/unit/Stack/BuilderTest.php
vendored
Normal file
215
vendor/stack/builder/tests/unit/Stack/BuilderTest.php
vendored
Normal file
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace Stack;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\TerminableInterface;
|
||||
|
||||
/** @covers Stack\Builder */
|
||||
class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function withoutMiddlewaresItShouldReturnOriginalResponse()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertInstanceOf('Stack\StackedHttpKernel', $resolved);
|
||||
$this->assertSame('ok', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function resolvedKernelShouldDelegateTerminateCalls()
|
||||
{
|
||||
$app = $this->getTerminableMock();
|
||||
|
||||
$stack = new Builder();
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = new Response('ok');
|
||||
|
||||
$resolved->handle($request);
|
||||
$resolved->terminate($request, $response);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function pushShouldReturnSelf()
|
||||
{
|
||||
$stack = new Builder();
|
||||
$this->assertSame($stack, $stack->push('Stack\AppendA'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function pushShouldThrowOnInvalidInput()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException', 'Missing argument(s) when calling push');
|
||||
$stack = new Builder();
|
||||
$stack->push();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unshiftShouldReturnSelf()
|
||||
{
|
||||
$stack = new Builder();
|
||||
$this->assertSame($stack, $stack->unshift('Stack\AppendA'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unshiftShouldThrowOnInvalidInput()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException', 'Missing argument(s) when calling unshift');
|
||||
$stack = new Builder();
|
||||
$stack->unshift();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function appendMiddlewareShouldAppendToBody()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$stack->push('Stack\AppendA');
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertSame('ok.A', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unshiftMiddlewareShouldPutMiddlewareBeforePushed()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$stack->push('Stack\Append', '2.');
|
||||
$stack->unshift('Stack\Append', '1.');
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertSame('ok2.1.', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function stackedMiddlewaresShouldWrapInReverseOrder()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$stack->push('Stack\AppendA');
|
||||
$stack->push('Stack\AppendB');
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertSame('ok.B.A', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function resolveShouldPassPushArgumentsToMiddlewareConstructor()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$stack->push('Stack\Append', '.foo');
|
||||
$stack->push('Stack\Append', '.bar');
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertSame('ok.bar.foo', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function resolveShouldCallSpecFactories()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
|
||||
$stack = new Builder();
|
||||
$stack->push(function ($app) { return new Append($app, '.foo'); });
|
||||
$stack->push(function ($app) { return new Append($app, '.bar'); });
|
||||
$resolved = $stack->resolve($app);
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $resolved->handle($request);
|
||||
|
||||
$this->assertSame('ok.bar.foo', $response->getContent());
|
||||
}
|
||||
|
||||
private function getHttpKernelMock(Response $response)
|
||||
{
|
||||
$app = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$app->expects($this->any())
|
||||
->method('handle')
|
||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||
->will($this->returnValue($response));
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
private function getTerminableMock()
|
||||
{
|
||||
$app = $this->getMock('Stack\TerminableHttpKernel');
|
||||
$app->expects($this->once())
|
||||
->method('terminate')
|
||||
->with(
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Request'),
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response')
|
||||
);
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TerminableHttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
{
|
||||
}
|
||||
|
||||
class Append implements HttpKernelInterface
|
||||
{
|
||||
private $app;
|
||||
private $appendix;
|
||||
|
||||
public function __construct(HttpKernelInterface $app, $appendix)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->appendix = $appendix;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
$response = clone $this->app->handle($request, $type, $catch);
|
||||
$response->setContent($response->getContent().$this->appendix);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
class AppendA extends Append
|
||||
{
|
||||
public function __construct(HttpKernelInterface $app)
|
||||
{
|
||||
parent::__construct($app, '.A');
|
||||
}
|
||||
}
|
||||
|
||||
class AppendB extends Append
|
||||
{
|
||||
public function __construct(HttpKernelInterface $app)
|
||||
{
|
||||
parent::__construct($app, '.B');
|
||||
}
|
||||
}
|
155
vendor/stack/builder/tests/unit/Stack/StackedHttpKernelTest.php
vendored
Normal file
155
vendor/stack/builder/tests/unit/Stack/StackedHttpKernelTest.php
vendored
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
|
||||
namespace Stack;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\TerminableInterface;
|
||||
|
||||
class StackedHttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function handleShouldDelegateToApp()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
$kernel = new StackedHttpKernel($app, array($app));
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $kernel->handle($request);
|
||||
|
||||
$this->assertSame('ok', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function handleShouldStillDelegateToAppWithMiddlewares()
|
||||
{
|
||||
$app = $this->getHttpKernelMock(new Response('ok'));
|
||||
$bar = $this->getHttpKernelMock(new Response('bar'));
|
||||
$foo = $this->getHttpKernelMock(new Response('foo'));
|
||||
$kernel = new StackedHttpKernel($app, array($foo, $bar, $app));
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $kernel->handle($request);
|
||||
|
||||
$this->assertSame('ok', $response->getContent());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function terminateShouldDelegateToMiddlewares()
|
||||
{
|
||||
$first = new TerminableKernelSpy();
|
||||
$second = new TerminableKernelSpy($first);
|
||||
$third = new KernelSpy($second);
|
||||
$fourth = new TerminableKernelSpy($third);
|
||||
$fifth = new TerminableKernelSpy($fourth);
|
||||
|
||||
$kernel = new StackedHttpKernel($fifth, $middlewares = array($fifth, $fourth, $third, $second, $first));
|
||||
|
||||
$request = Request::create('/');
|
||||
$response = $kernel->handle($request);
|
||||
$kernel->terminate($request, $response);
|
||||
|
||||
$this->assertTerminablesCalledOnce($middlewares);
|
||||
}
|
||||
|
||||
private function assertTerminablesCalledOnce(array $middlewares)
|
||||
{
|
||||
foreach ($middlewares as $kernel) {
|
||||
if ($kernel instanceof TerminableInterface) {
|
||||
$this->assertEquals(1, $kernel->terminateCallCount(), "Terminate was called {$kernel->terminateCallCount()} times");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getHttpKernelMock(Response $response)
|
||||
{
|
||||
$app = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$app->expects($this->any())
|
||||
->method('handle')
|
||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||
->will($this->returnValue($response));
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
private function getTerminableMock(Response $response = null)
|
||||
{
|
||||
$app = $this->getMock('Stack\TerminableHttpKernel');
|
||||
if ($response) {
|
||||
$app->expects($this->any())
|
||||
->method('handle')
|
||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||
->will($this->returnValue($response));
|
||||
}
|
||||
$app->expects($this->once())
|
||||
->method('terminate')
|
||||
->with(
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Request'),
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response')
|
||||
);
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
private function getDelegatingTerminableMock(TerminableInterface $next)
|
||||
{
|
||||
$app = $this->getMock('Stack\TerminableHttpKernel');
|
||||
$app->expects($this->once())
|
||||
->method('terminate')
|
||||
->with(
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Request'),
|
||||
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response')
|
||||
)
|
||||
->will($this->returnCallback(function ($request, $response) use ($next) {
|
||||
$next->terminate($request, $response);
|
||||
}));
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
|
||||
class KernelSpy implements HttpKernelInterface
|
||||
{
|
||||
private $handleCallCount = 0;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel = null)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
$this->handleCallCount++;
|
||||
|
||||
if ($this->kernel) {
|
||||
return $this->kernel->handle($request, $type, $catch);
|
||||
}
|
||||
|
||||
return new Response('OK');
|
||||
}
|
||||
|
||||
public function handleCallCount()
|
||||
{
|
||||
return $this->handleCallCount;
|
||||
}
|
||||
}
|
||||
|
||||
class TerminableKernelSpy extends KernelSpy implements TerminableInterface
|
||||
{
|
||||
private $terminateCallCount = 0;
|
||||
|
||||
public function terminate(Request $request, Response $response)
|
||||
{
|
||||
$this->terminateCallCount++;
|
||||
|
||||
if ($this->kernel && $this->kernel instanceof TerminableInterface) {
|
||||
return $this->kernel->terminate($request, $response);
|
||||
}
|
||||
}
|
||||
|
||||
public function terminateCallCount()
|
||||
{
|
||||
return $this->terminateCallCount;
|
||||
}
|
||||
}
|
Reference in a new issue