Skip to content

Commit

Permalink
Add support for Symfony 4
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 6, 2018
1 parent 1a7cf5f commit 6f192da
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 95 deletions.
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
],
"require": {
"php": "^5.6||^7.0",
"symfony/http-foundation": "~2.1||~3.0",
"symfony/http-kernel": "~2.4||~3.0",
"symfony/http-foundation": "^2.1||^3.0||^4.0",
"symfony/http-kernel": "^2.4||^3.0||^4.0",
"nocarrier/hal": "^0.9.4"
},
"suggest": {
Expand All @@ -25,20 +25,20 @@
"symfony/serializer": "For using RequestBodyDecoder"
},
"require-dev": {
"psr/log": "~1.0",
"psr/log": "^1.0",

"symfony/event-dispatcher": "~2.5||~3.0",
"symfony/event-dispatcher": "^2.5||^3.0||^4.0",

"symfony/config": "~2.5||~3.0",
"symfony/dependency-injection": "~2.5||~3.0",
"symfony/config": "^2.5||^3.0||^4.0",
"symfony/dependency-injection": "^2.5||^3.0||^4.0",

"symfony/form": "~2.8||~3.0",
"symfony/translation": "~2.5||~3.0",
"symfony/validator": "~2.6||~3.0",
"symfony/security-core": "~2.5||~3.0",
"symfony/serializer": "~2.1||~3.0",
"symfony/form": "^2.8||^3.0||^4.0",
"symfony/translation": "^2.5||^3.0||^4.0",
"symfony/validator": "^2.6||^3.0||^4.0",
"symfony/security-core": "^2.5||^3.0||^4.0",
"symfony/serializer": "^2.1||^3.0||^4.0",

"willdurand/negotiation": "^2.0.0",
"willdurand/negotiation": "^2.0",
"phpunit/phpunit": "^5.7"
},
"autoload": {
Expand Down
49 changes: 7 additions & 42 deletions tests/Integration/HttpKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernel;

class HttpKernelTest extends \PHPUnit_Framework_TestCase
{
/** @test */
public function it_intercepts_not_acceptable_format()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->never())
->method('getController');

$resolver
->expects($this->never())
->method('getArguments');

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher);

$dispatcher->addSubscriber(new RequestFormatNegotiationListener());
$dispatcher->addSubscriber(new RequestFormatValidationListener());
Expand All @@ -50,22 +39,10 @@ public function it_intercepts_not_acceptable_format()
/** @test */
public function it_converts_response_to_json()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function () {
return new Hal('/');
}));

$resolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue([]));

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher, function () {
return new Hal('/');
});

$dispatcher->addSubscriber(new RequestFormatNegotiationListener());
$dispatcher->addSubscriber(new RequestFormatValidationListener());
Expand Down Expand Up @@ -98,28 +75,16 @@ public function it_converts_response_to_json()
/** @test */
public function it_converts_exception_to_json()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function () {
throw new NotFoundHttpException();
}));

$resolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue([]));

$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();

$logger
->expects($this->once())
->method('error');

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher, function () {
throw new NotFoundHttpException();
});

$dispatcher->addSubscriber(new RequestFormatNegotiationListener());
$dispatcher->addSubscriber(new RequestFormatValidationListener());
Expand Down
48 changes: 7 additions & 41 deletions tests/Integration/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ class KernelTest extends \PHPUnit_Framework_TestCase
/** @test */
public function it_intercepts_not_acceptable_format()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->never())
->method('getController');

$resolver
->expects($this->never())
->method('getArguments');

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher);

$kernel = new KernelForTest('test', true);
$kernel->boot();
Expand All @@ -55,22 +45,10 @@ public function it_intercepts_not_acceptable_format()
/** @test */
public function it_converts_response_to_json()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function () {
return new Hal('/');
}));

$resolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue([]));

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher, function () {
return new Hal('/');
});

$kernel = new KernelForTest('test', true);
$kernel->boot();
Expand Down Expand Up @@ -107,28 +85,16 @@ public function it_converts_response_to_json()
/** @test */
public function it_converts_exception_to_json()
{
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();

$resolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function () {
throw new NotFoundHttpException();
}));

$resolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue([]));

$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();

$logger
->expects($this->once())
->method('error');

$dispatcher = new EventDispatcher();
$httpKernel = new HttpKernel($dispatcher, $resolver);
$httpKernel = new TestHttpKernel($dispatcher, function () {
throw new NotFoundHttpException();
});

$kernel = new KernelForTest('test', true);
$kernel->boot();
Expand Down
29 changes: 29 additions & 0 deletions tests/Integration/TestHttpKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Jsor\Stack\Hal\Integration;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Tests\TestHttpKernel as SymfonyTestHttpKernel;

final class TestHttpKernel extends SymfonyTestHttpKernel
{
private $controller;

public function __construct(EventDispatcherInterface $eventDispatcher, callable $controller = null)
{
$this->controller = $controller;

HttpKernel::__construct($eventDispatcher, $this);
}

public function getController(Request $request)
{
if ($this->controller) {
return $this->controller;
}

return parent::getController($request);
}
}

0 comments on commit 6f192da

Please sign in to comment.