Skip to content

Commit

Permalink
Merge pull request #366 from rachel-fizz/symfony-5
Browse files Browse the repository at this point in the history
Add support for Symfony 5, drop support for PHP5, drop support for Symfony 2
  • Loading branch information
tobias-93 committed Dec 1, 2019
2 parents e42ed45 + 5dfca90 commit 01a4684
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
/vendor/
/node_modules/
/.phpunit/
/.phpunit.result.cache
3 changes: 0 additions & 3 deletions .travis.yml
Expand Up @@ -2,12 +2,9 @@ language: php

matrix:
include:
- php: 5.6
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.1
env: SYMFONY_VERSION='2.8.*'
- php: 7.1
env: SYMFONY_VERSION='3.4.*'
- php: 7.1
Expand Down
1 change: 1 addition & 0 deletions Command/RouterDebugExposedCommand.php
Expand Up @@ -104,6 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'show_controllers' => $input->getOption('show-controllers'),
));
}
return 0;
}

protected function getRoutes($domain = array())
Expand Down
26 changes: 11 additions & 15 deletions Tests/Command/DumpCommandTest.php
Expand Up @@ -21,7 +21,7 @@ class DumpCommandTest extends TestCase
protected $router;
private $serializer;

public function setUp()
public function setUp(): void
{
$this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor')
->disableOriginalConstructor()
Expand All @@ -47,8 +47,8 @@ public function testExecute()
$tester = new CommandTester($command);
$tester->execute(array('--target' => '/tmp/dump-command-test'));

$this->assertContains('Dumping exposed routes.', $tester->getDisplay());
$this->assertContains('[file+] /tmp/dump-command-test', $tester->getDisplay());
$this->assertStringContainsString('Dumping exposed routes.', $tester->getDisplay());
$this->assertStringContainsString('[file+] /tmp/dump-command-test', $tester->getDisplay());

$this->assertEquals('fos.Router.setData({"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""});', file_get_contents('/tmp/dump-command-test'));
}
Expand All @@ -67,8 +67,8 @@ public function testExecuteCallbackOption()
'--callback' => 'test',
));

$this->assertContains('Dumping exposed routes.', $tester->getDisplay());
$this->assertContains('[file+] /tmp/dump-command-test', $tester->getDisplay());
$this->assertStringContainsString('Dumping exposed routes.', $tester->getDisplay());
$this->assertStringContainsString('[file+] /tmp/dump-command-test', $tester->getDisplay());

$this->assertEquals('test({"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""});', file_get_contents('/tmp/dump-command-test'));
}
Expand All @@ -89,30 +89,26 @@ public function testExecuteFormatOption()
'--format' => 'json',
));

$this->assertContains('Dumping exposed routes.', $tester->getDisplay());
$this->assertContains('[file+] /tmp/dump-command-test', $tester->getDisplay());
$this->assertStringContainsString('Dumping exposed routes.', $tester->getDisplay());
$this->assertStringContainsString('[file+] /tmp/dump-command-test', $tester->getDisplay());

$this->assertEquals($json, file_get_contents('/tmp/dump-command-test'));
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Unable to create directory /root/dir/../web/js
*/
public function testExecuteUnableToCreateDirectory()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to create directory /root/dir/../web/js');
$command = new DumpCommand($this->extractor, $this->serializer, '/root/dir');

$tester = new CommandTester($command);
$tester->execute(array());
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Unable to write file /tmp
*/
public function testExecuteUnableToWriteFile()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to write file /tmp');
$this->serializer->expects($this->once())
->method('serialize')
->will($this->returnValue('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""}'));
Expand Down
16 changes: 6 additions & 10 deletions Tests/Command/RouterDebugExposedCommandTest.php
Expand Up @@ -22,7 +22,7 @@ class RouterDebugExposedCommandTest extends TestCase
protected $extractor;
protected $router;

public function setUp()
public function setUp(): void
{
$this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor')
->disableOriginalConstructor()
Expand Down Expand Up @@ -54,12 +54,10 @@ public function testExecute()
$this->assertRegExp('/list(.*ANY){3}.*\/literal/', $tester->getDisplay());
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage The route "foobar" does not exist.
*/
public function testExecuteWithNameUnknown()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The route "foobar" does not exist.');
$routes = new RouteCollection();
$routes->add('literal', new Route('/literal'));
$routes->add('blog_post', new Route('/blog-post/{slug}'));
Expand All @@ -75,12 +73,10 @@ public function testExecuteWithNameUnknown()
$tester->execute(array('name' => 'foobar'));
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage The route "literal" was found, but it is not an exposed route.
*/
public function testExecuteWithNameNotExposed()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The route "literal" was found, but it is not an exposed route.');
$routes = new RouteCollection();
$routes->add('literal', new Route('/literal'));
$routes->add('blog_post', new Route('/blog-post/{slug}'));
Expand Down Expand Up @@ -116,6 +112,6 @@ public function testExecuteWithName()
$tester = new CommandTester($command);
$tester->execute(array('name' => 'literal'));

$this->assertContains('exposed: true', $tester->getDisplay());
$this->assertStringContainsString('exposed: true', $tester->getDisplay());
}
}
9 changes: 4 additions & 5 deletions Tests/Controller/ControllerTest.php
Expand Up @@ -17,6 +17,7 @@
use FOS\JsRoutingBundle\Serializer\Normalizer\RoutesResponseNormalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
Expand All @@ -26,12 +27,12 @@ class ControllerTest extends TestCase
{
private $cachePath;

public function setUp()
public function setUp(): void
{
$this->cachePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'fosJsRouting' . DIRECTORY_SEPARATOR . 'data.json';
}

public function tearDown()
public function tearDown(): void
{
unlink($this->cachePath);
}
Expand Down Expand Up @@ -108,11 +109,9 @@ public static function dataProviderForTestGenerateWithCallback()
);
}

/**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testGenerateWithInvalidCallback()
{
$this->expectException(HttpException::class);
$controller = new Controller($this->getSerializer(), $this->getExtractor());
$controller->indexAction($this->getRequest('/', 'GET', array('callback' => '(function xss(x) {evil()})')), 'json');
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/FOSJsRoutingExtensionTest.php
Expand Up @@ -17,7 +17,7 @@

class FOSJsRoutingExtensionTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (!class_exists('Symfony\Component\DependencyInjection\ContainerBuilder')) {
$this->markTestSkipped('The DependencyInjection component is not available.');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Extractor/ExposedRoutesExtractorTest.php
Expand Up @@ -26,7 +26,7 @@ class ExposedRoutesExtractorTest extends TestCase
{
private $cacheDir;

public function setUp()
public function setUp(): void
{
if (!class_exists('Symfony\\Component\\Routing\\Route')) {
$this->markTestSkipped('The Routing component is not available.');
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -16,14 +16,14 @@
}
],
"require": {
"php": "^5.3.9|^7.0",
"symfony/framework-bundle": "~2.7||~3.0|^4.0",
"symfony/serializer": "~2.7||~3.0|^4.0",
"symfony/console": "~2.7||~3.0|^4.0",
"php": "^7.1",
"symfony/framework-bundle": "~3.0|^4.0|^5.0",
"symfony/serializer": "~3.0|^4.0|^5.0",
"symfony/console": "~3.0|^4.0|^5.0",
"willdurand/jsonp-callback-validator": "~1.0"
},
"require-dev": {
"symfony/expression-language": "~2.7||~3.0|^4.0",
"symfony/expression-language": "~3.0|^4.0|^5.0",
"symfony/phpunit-bridge": "^3.3|^4.0"
},
"autoload": {
Expand Down

0 comments on commit 01a4684

Please sign in to comment.