diff --git a/.github/workflows/fix-cs-php.yml b/.github/workflows/fix-cs-php.yml new file mode 100644 index 0000000..4e30909 --- /dev/null +++ b/.github/workflows/fix-cs-php.yml @@ -0,0 +1,29 @@ +# Update this by running +# curl https://gist.github.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml + +on: + push: + branches: + - master + pull_request: + +name: Coding Standards + +jobs: + fix-cs-issues: + name: PHP-CS-Fixer + runs-on: ubuntu-22.04 + if: github.actor != 'dependabot[bot]' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + + - name: Commit and push back changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Fix CS with PHP-CS-Fixer" diff --git a/.gitignore b/.gitignore index c8d673d..3b62acd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ phpunit.xml composer.lock .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..87587fc --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,19 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'short'), + 'no_unreachable_default_argument_value' => false, + 'braces' => array('allow_single_line_closure' => true), + 'heredoc_to_nowdoc' => false, + 'psr_autoloading' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->notPath('vendor/') + ) +; diff --git a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php index 89ad9ce..0b738b9 100644 --- a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php +++ b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,10 +28,10 @@ final class ObjectRoute public $name; /** @var array */ - public $params = array(); + public $params = []; /** @var array */ - public $paramExpressions = array(); + public $paramExpressions = []; public function __construct(string $type, string $name, array $params = [], array $paramExpressions = []) { diff --git a/src/JMS/ObjectRouting/Exception/Exception.php b/src/JMS/ObjectRouting/Exception/Exception.php index 033dfd4..4ad6894 100644 --- a/src/JMS/ObjectRouting/Exception/Exception.php +++ b/src/JMS/ObjectRouting/Exception/Exception.php @@ -2,8 +2,6 @@ namespace JMS\ObjectRouting\Exception; - interface Exception { - -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Exception/RuntimeException.php b/src/JMS/ObjectRouting/Exception/RuntimeException.php index 28a7a1a..f93105e 100644 --- a/src/JMS/ObjectRouting/Exception/RuntimeException.php +++ b/src/JMS/ObjectRouting/Exception/RuntimeException.php @@ -2,8 +2,6 @@ namespace JMS\ObjectRouting\Exception; - class RuntimeException extends \RuntimeException implements Exception { - -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Exception/XmlErrorException.php b/src/JMS/ObjectRouting/Exception/XmlErrorException.php index 4b65e05..0f8499b 100644 --- a/src/JMS/ObjectRouting/Exception/XmlErrorException.php +++ b/src/JMS/ObjectRouting/Exception/XmlErrorException.php @@ -2,7 +2,6 @@ namespace JMS\ObjectRouting\Exception; - class XmlErrorException extends RuntimeException { private $xmlError; @@ -10,13 +9,13 @@ class XmlErrorException extends RuntimeException public function __construct(\LibXMLError $error) { switch ($error->level) { - case LIBXML_ERR_WARNING: + case \LIBXML_ERR_WARNING: $level = 'WARNING'; break; - case LIBXML_ERR_FATAL: + case \LIBXML_ERR_FATAL: $level = 'FATAL'; break; - case LIBXML_ERR_ERROR: + case \LIBXML_ERR_ERROR: $level = 'ERROR'; break; default: @@ -30,4 +29,4 @@ public function getXmlError() { return $this->xmlError; } -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php index 0f733b0..7436113 100644 --- a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php +++ b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,15 +23,15 @@ class ClassMetadata extends MergeableClassMetadata { - public $routes = array(); + public $routes = []; - public function addRoute($type, $name, array $params = array(), array $paramExpressions = array()) + public function addRoute($type, $name, array $params = [], array $paramExpressions = []) { - $this->routes[$type] = array( + $this->routes[$type] = [ 'name' => $name, 'params' => $params, 'paramExpressions' => $paramExpressions, - ); + ]; } public function merge(MergeableInterface $object): void @@ -43,10 +43,10 @@ public function merge(MergeableInterface $object): void public function serialize(): string { return serialize( - array( + [ $this->routes, parent::serialize(), - ) + ] ); } @@ -55,9 +55,8 @@ public function unserialize($str): void list( $this->routes, $parentStr - ) = unserialize($str); + ) = unserialize($str); parent::unserialize($parentStr); } - } diff --git a/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php index 47013eb..acca1cb 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php index 7936863..680c197 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php @@ -18,14 +18,13 @@ namespace JMS\ObjectRouting\Metadata\Driver; - use JMS\ObjectRouting\Exception\RuntimeException; use JMS\ObjectRouting\Metadata\ClassMetadata; use Metadata\Driver\AbstractFileDriver; /** - * Class PhpDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class PhpDriver. + * * @author Sebastian Kroczek */ class PhpDriver extends AbstractFileDriver diff --git a/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php index b3b2f04..bd0b4c2 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php @@ -18,26 +18,21 @@ namespace JMS\ObjectRouting\Metadata\Driver; - use JMS\ObjectRouting\Exception\RuntimeException; use JMS\ObjectRouting\Exception\XmlErrorException; use JMS\ObjectRouting\Metadata\ClassMetadata; use Metadata\Driver\AbstractFileDriver; /** - * Class XmlDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class XmlDriver. + * * @author Sebastian Kroczek */ class XmlDriver extends AbstractFileDriver { - /** * Parses the content of the file, and converts it to the desired metadata. * - * @param \ReflectionClass $class - * @param string $file - * * @return \Metadata\ClassMetadata|null */ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata @@ -57,28 +52,28 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): $metadata->fileResources[] = $class->getFileName(); if (null !== $xmlRootName = $elem->attributes()->{'xml-root-name'}) { - $metadata->xmlRootName = (string)$xmlRootName; + $metadata->xmlRootName = (string) $xmlRootName; } if (null !== $xmlRootNamespace = $elem->attributes()->{'xml-root-namespace'}) { - $metadata->xmlRootNamespace = (string)$xmlRootNamespace; + $metadata->xmlRootNamespace = (string) $xmlRootNamespace; } foreach ($elem->xpath('./route') as $r) { - if ('' === $type = (string)$r->attributes()->{'type'}) { + if ('' === $type = (string) $r->attributes()->{'type'}) { throw new RuntimeException('Could not find attribute "type" inside XML element.'); } - if ('' === $name = (string)$r->attributes()->{'name'}) { + if ('' === $name = (string) $r->attributes()->{'name'}) { throw new RuntimeException('Could not find attribute "name" inside XML element.'); } - $params = array(); + $params = []; foreach ($r->xpath('./param') as $p) { - $params[(string)$p->attributes()] = (string)$p; + $params[(string) $p->attributes()] = (string) $p; } - $paramExpressions = array(); + $paramExpressions = []; foreach ($r->xpath('./paramExpression') as $p) { - $paramExpressions[(string)$p->attributes()] = (string)$p; + $paramExpressions[(string) $p->attributes()] = (string) $p; } $metadata->addRoute($type, $name, $params, $paramExpressions); @@ -89,8 +84,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): /** * Returns the extension of the file. - * - * @return string */ protected function getExtension(): string { diff --git a/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php index 254079c..e627221 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php @@ -24,20 +24,15 @@ use Symfony\Component\Yaml\Yaml; /** - * Class YamlDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class YamlDriver. + * * @author Sebastian Kroczek */ class YamlDriver extends AbstractFileDriver { - - /** * Parses the content of the file, and converts it to the desired metadata. * - * @param \ReflectionClass $class - * @param string $file - * * @return \Metadata\ClassMetadata|null */ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata @@ -48,32 +43,28 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): throw new RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); } - $config = $config[$name]; $metadata = new ClassMetadata($name); $metadata->fileResources[] = $file; $metadata->fileResources[] = $class->getFileName(); foreach ($config as $type => $value) { - if (!array_key_exists('name', $value)) { + if (!\array_key_exists('name', $value)) { throw new RuntimeException('Could not find key "type" inside yaml element.'); } $metadata->addRoute( $type, $value['name'], - array_key_exists('params', $value) ? $value['params'] : array(), - array_key_exists('paramExpressions', $value) ? $value['paramExpressions'] : array() + \array_key_exists('params', $value) ? $value['params'] : [], + \array_key_exists('paramExpressions', $value) ? $value['paramExpressions'] : [] ); } return $metadata; - } /** * Returns the extension of the file. - * - * @return string */ protected function getExtension(): string { diff --git a/src/JMS/ObjectRouting/ObjectRouter.php b/src/JMS/ObjectRouting/ObjectRouter.php index f28f959..55204c6 100644 --- a/src/JMS/ObjectRouting/ObjectRouter.php +++ b/src/JMS/ObjectRouting/ObjectRouter.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -58,30 +58,24 @@ public function __construct(RouterInterface $router, MetadataFactoryInterface $m * * @param string $type * @param object $object - * @param boolean $absolute - * @param array $extraParams + * @param bool $absolute * * @throws \InvalidArgumentException */ - public function generate($type, $object, $absolute = false, array $extraParams = array()) + public function generate($type, $object, $absolute = false, array $extraParams = []) { - if ( ! is_object($object)) { - throw new \InvalidArgumentException(sprintf('$object must be an object, but got "%s".', gettype($object))); + if (!\is_object($object)) { + throw new \InvalidArgumentException(sprintf('$object must be an object, but got "%s".', \gettype($object))); } /** @var $metadata ClassMetadata */ - $metadata = $this->metadataFactory->getMetadataForClass(get_class($object)); + $metadata = $this->metadataFactory->getMetadataForClass($object::class); if (null === $metadata) { - throw new \RuntimeException(sprintf('There were no object routes defined for class "%s".', get_class($object))); + throw new \RuntimeException(sprintf('There were no object routes defined for class "%s".', $object::class)); } - if ( ! isset($metadata->routes[$type])) { - throw new \RuntimeException(sprintf( - 'The object of class "%s" has no route with type "%s". Available types: %s', - get_class($object), - $type, - implode(', ', array_keys($metadata->routes)) - )); + if (!isset($metadata->routes[$type])) { + throw new \RuntimeException(sprintf('The object of class "%s" has no route with type "%s". Available types: %s', $object::class, $type, implode(', ', array_keys($metadata->routes)))); } $route = $metadata->routes[$type]; @@ -97,8 +91,8 @@ public function generate($type, $object, $absolute = false, array $extraParams = $metadata->routes[$type]['paramExpressions'][$k] = $expression; } $evaluated = $this->expressionLanguage->evaluate($expression, ['this' => $object, 'params' => $params]); - if ($k[0] === '?') { - if ($evaluated === null) { + if ('?' === $k[0]) { + if (null === $evaluated) { continue; } $params[substr($k, 1)] = $evaluated; @@ -110,12 +104,12 @@ public function generate($type, $object, $absolute = false, array $extraParams = return $this->router->generate($route['name'], $params, $absolute); } - public function path($type, $object, array $extraParams = array()) + public function path($type, $object, array $extraParams = []) { return $this->generate($type, $object, false, $extraParams); } - public function url($type, $object, array $extraParams = array()) + public function url($type, $object, array $extraParams = []) { return $this->generate($type, $object, true, $extraParams); } diff --git a/src/JMS/ObjectRouting/RouterInterface.php b/src/JMS/ObjectRouting/RouterInterface.php index e95407d..183fba9 100644 --- a/src/JMS/ObjectRouting/RouterInterface.php +++ b/src/JMS/ObjectRouting/RouterInterface.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,4 +21,4 @@ interface RouterInterface { public function generate($name, array $params, $absolute = false); -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php b/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php index d278fa0..e92f1a7 100644 --- a/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php +++ b/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php @@ -2,13 +2,13 @@ /* * Copyright 2016 Sebastian Kroczek - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,8 +22,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** - * Class Symfony22Adapter - * @package JMS\ObjectRouting\Symfony + * Class Symfony22Adapter. + * * @author Sebastian Kroczek */ class Symfony22Adapter implements RouterInterface diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php index 37621e5..b3489dd 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php @@ -25,4 +25,4 @@ public function getSlug() { return $this->slug; } -} \ No newline at end of file +} diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php index 9848065..c42bc4a 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php @@ -4,8 +4,8 @@ use JMS\ObjectRouting\Attribute\ObjectRoute; -#[ObjectRoute(type: "view", name: "blog_post_view", params: ['slug' => 'slug'], paramExpressions: ['?year' => 'this.isArchived ? this.year : null'])] -#[ObjectRoute(type: "edit", name: "blog_post_edit", params: ['slug' => 'slug'])] +#[ObjectRoute(type: 'view', name: 'blog_post_view', params: ['slug' => 'slug'], paramExpressions: ['?year' => 'this.isArchived ? this.year : null'])] +#[ObjectRoute(type: 'edit', name: 'blog_post_edit', params: ['slug' => 'slug'])] class BlogPostWithAttributes { private $slug; diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php index f895072..0d6b3e6 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php @@ -30,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() protected function setUp(): void { - $this->driver = new PhpDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new PhpDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php index 65a15f7..fce5156 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php @@ -2,8 +2,6 @@ namespace JMS\Tests\ObjectRouting\Metadata\Driver; -use Doctrine\Common\Annotations\AnnotationReader; -use JMS\ObjectRouting\Metadata\Driver\AnnotationDriver; use JMS\ObjectRouting\Metadata\Driver\XmlDriver; use Metadata\Driver\FileLocator; use PHPUnit\Framework\TestCase; @@ -32,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() protected function setUp(): void { - $this->driver = new XmlDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new XmlDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php index eade4b6..a050347 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php @@ -2,8 +2,6 @@ namespace JMS\Tests\ObjectRouting\Metadata\Driver; -use Doctrine\Common\Annotations\AnnotationReader; -use JMS\ObjectRouting\Metadata\Driver\AnnotationDriver; use JMS\ObjectRouting\Metadata\Driver\YamlDriver; use Metadata\Driver\FileLocator; use PHPUnit\Framework\TestCase; @@ -32,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() protected function setUp(): void { - $this->driver = new YamlDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new YamlDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php b/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php index 722097d..64b125a 100644 --- a/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php +++ b/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php @@ -23,32 +23,32 @@ public function testGenerate() $this->factory->expects($this->once()) ->method('getMetadataForClass') ->with('stdClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array(), false) - ->will($this->returnValue('/foo')); + ->with('view_name', [], false) + ->willReturn('/foo'); - $this->assertEquals('/foo', $this->router->generate('view', new \stdClass)); + $this->assertEquals('/foo', $this->router->generate('view', new \stdClass())); } public function testGenerateWithParams() { $metadata = new ClassMetadata('stdClass'); - $metadata->addRoute('view', 'view_name', array('foo' => 'bar')); + $metadata->addRoute('view', 'view_name', ['foo' => 'bar']); - $object = new \stdClass; + $object = new \stdClass(); $object->bar = 'baz'; $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array('foo' => 'baz'), false) - ->will($this->returnValue('/foobar')); + ->with('view_name', ['foo' => 'baz'], false) + ->willReturn('/foobar'); $this->assertEquals('/foobar', $this->router->generate('view', $object)); } @@ -58,17 +58,17 @@ public function testGenerateWithParamExpression() $metadata = new ClassMetadata('stdClass'); $metadata->addRoute('view', 'view_name', [], ['foo' => 'this.bar']); - $object = new \stdClass; + $object = new \stdClass(); $object->bar = 'baz'; $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array('foo' => 'baz'), false) - ->will($this->returnValue('/foobar')); + ->with('view_name', ['foo' => 'baz'], false) + ->willReturn('/foobar'); $this->assertEquals('/foobar', $this->router->generate('view', $object)); } @@ -78,17 +78,17 @@ public function testGenerateWithParamExpressionThatRefersToParam() $metadata = new ClassMetadata('stdClass'); $metadata->addRoute('view', 'view_name', ['foo' => 'bar'], ['concat' => 'params["foo"] ~ this.bar']); - $object = new \stdClass; + $object = new \stdClass(); $object->bar = 'baz'; $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array('foo' => 'baz', 'concat' => 'bazbaz'), false) - ->will($this->returnValue('/foobar')); + ->with('view_name', ['foo' => 'baz', 'concat' => 'bazbaz'], false) + ->willReturn('/foobar'); $this->assertEquals('/foobar', $this->router->generate('view', $object)); } @@ -98,18 +98,18 @@ public function testGenerateWithNullableParamExpression() $metadata = new ClassMetadata('stdClass'); $metadata->addRoute('view', 'view_name', [], ['?foo' => 'this.bar', '?quux' => 'this.barbaz']); - $object = new \stdClass; + $object = new \stdClass(); $object->bar = 'baz'; $object->barbaz = null; $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array('foo' => 'baz'), false) - ->will($this->returnValue('/foobar')); + ->with('view_name', ['foo' => 'baz'], false) + ->willReturn('/foobar'); $this->assertEquals('/foobar', $this->router->generate('view', $object)); } @@ -124,9 +124,9 @@ public function testGenerateNonExistentType() $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); - $this->router->generate('foo', new \stdClass); + $this->router->generate('foo', new \stdClass()); } public function testGenerateNoMetadata() @@ -136,9 +136,9 @@ public function testGenerateNoMetadata() $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue(null)); + ->willReturn(null); - $this->router->generate('foo', new \stdClass); + $this->router->generate('foo', new \stdClass()); } protected function setUp(): void diff --git a/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php b/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php index 3e3410b..a953cf8 100644 --- a/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php +++ b/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php @@ -17,10 +17,10 @@ public function testGenerate() { $this->router->expects($this->once()) ->method('generate') - ->with('foo', array('bar' => 'baz'), UrlGeneratorInterface::ABSOLUTE_URL) - ->will($this->returnValue('/foo-bar-baz')); + ->with('foo', ['bar' => 'baz'], UrlGeneratorInterface::ABSOLUTE_URL) + ->willReturn('/foo-bar-baz'); - $this->assertEquals('/foo-bar-baz', $this->adapter->generate('foo', array('bar' => 'baz'), true)); + $this->assertEquals('/foo-bar-baz', $this->adapter->generate('foo', ['bar' => 'baz'], true)); } protected function setUp(): void diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 95b1e11..79fcc41 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,16 +1,16 @@