From 5dfca90c7dcd28a10def4ca25c34fe05179e01e4 Mon Sep 17 00:00:00 2001 From: Rachel Date: Thu, 28 Nov 2019 14:09:06 +0100 Subject: [PATCH] Add support for Symfony 5, drop support for PHP5, drop support for Symfony 2 --- .gitignore | 1 + .travis.yml | 3 --- Command/RouterDebugExposedCommand.php | 1 + Tests/Command/DumpCommandTest.php | 26 ++++++++----------- .../Command/RouterDebugExposedCommandTest.php | 16 +++++------- Tests/Controller/ControllerTest.php | 9 +++---- .../FOSJsRoutingExtensionTest.php | 2 +- .../Extractor/ExposedRoutesExtractorTest.php | 2 +- composer.json | 10 +++---- 9 files changed, 30 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 0fa9e6c6..b6fb3940 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /vendor/ /node_modules/ /.phpunit/ +/.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 211e0cc8..f76d7dff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Command/RouterDebugExposedCommand.php b/Command/RouterDebugExposedCommand.php index caac0fc2..8fae3769 100644 --- a/Command/RouterDebugExposedCommand.php +++ b/Command/RouterDebugExposedCommand.php @@ -104,6 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'show_controllers' => $input->getOption('show-controllers'), )); } + return 0; } protected function getRoutes($domain = array()) diff --git a/Tests/Command/DumpCommandTest.php b/Tests/Command/DumpCommandTest.php index 254f3040..50230c3d 100644 --- a/Tests/Command/DumpCommandTest.php +++ b/Tests/Command/DumpCommandTest.php @@ -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() @@ -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')); } @@ -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')); } @@ -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":""}')); diff --git a/Tests/Command/RouterDebugExposedCommandTest.php b/Tests/Command/RouterDebugExposedCommandTest.php index 759ef7bb..6a246c04 100644 --- a/Tests/Command/RouterDebugExposedCommandTest.php +++ b/Tests/Command/RouterDebugExposedCommandTest.php @@ -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() @@ -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}')); @@ -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}')); @@ -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()); } } diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 811832a6..b7f525bf 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -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; @@ -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); } @@ -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'); } diff --git a/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php b/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php index 294ff341..d7dc45b9 100644 --- a/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php +++ b/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php @@ -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.'); diff --git a/Tests/Extractor/ExposedRoutesExtractorTest.php b/Tests/Extractor/ExposedRoutesExtractorTest.php index 31d7aea5..7078bcb0 100644 --- a/Tests/Extractor/ExposedRoutesExtractorTest.php +++ b/Tests/Extractor/ExposedRoutesExtractorTest.php @@ -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.'); diff --git a/composer.json b/composer.json index b5bcd388..2dc049b9 100644 --- a/composer.json +++ b/composer.json @@ -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": {