diff --git a/tests/Functional/BaseTestCase.php b/tests/Functional/BaseTestCase.php index ba50b502..804c6886 100644 --- a/tests/Functional/BaseTestCase.php +++ b/tests/Functional/BaseTestCase.php @@ -19,20 +19,12 @@ class BaseTestCase extends ComponentBaseTestCase { - /** - * @return DocumentManagerInterface - */ - protected function getDm() + protected function getDm(): DocumentManagerInterface { return $this->db('PHPCR')->getOm(); } - /** - * @param string $path - * - * @return Route - */ - protected function createRoute($path) + protected function createRoute(string $path): Route { $parentPath = PathHelper::getParentPath($path); $parent = $this->getDm()->find(null, $parentPath); @@ -45,12 +37,7 @@ protected function createRoute($path) return $route; } - /** - * @param string $path - * - * @return Content - */ - protected function createContent($path = '/test/content') + protected function createContent(string $path = '/test/content'): Content { $content = new Content(); $content->setId($path); diff --git a/tests/Functional/Controller/RedirectControllerTest.php b/tests/Functional/Controller/RedirectControllerTest.php index cb531652..26486b12 100644 --- a/tests/Functional/Controller/RedirectControllerTest.php +++ b/tests/Functional/Controller/RedirectControllerTest.php @@ -22,7 +22,7 @@ final class RedirectControllerTest extends BaseTestCase private RedirectController $controller; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->db('PHPCR')->createTestNode(); diff --git a/tests/Functional/Doctrine/Orm/OrmTestCase.php b/tests/Functional/Doctrine/Orm/OrmTestCase.php index 4c3cdfab..2fbc583a 100644 --- a/tests/Functional/Doctrine/Orm/OrmTestCase.php +++ b/tests/Functional/Doctrine/Orm/OrmTestCase.php @@ -11,6 +11,9 @@ namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm; +use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\DocumentManagerInterface; +use Doctrine\Persistence\ObjectManager; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as ComponentBaseTestCase; @@ -23,7 +26,7 @@ protected static function getKernelConfiguration(): array ]; } - protected function clearDb($model) + protected function clearDb($model): void { if (\is_array($model)) { foreach ($model as $singleModel) { @@ -40,12 +43,12 @@ protected function clearDb($model) $this->getDm()->flush(); } - protected function getDm() + protected function getDm(): DocumentManager|ObjectManager|DocumentManagerInterface { return $this->db('ORM')->getOm(); } - protected function createRoute($name, $path) + protected function createRoute($name, $path): Route { // split path in static and variable part preg_match('{^(.*?)(/[^/]*\{.*)?$}', $path, $paths); diff --git a/tests/Functional/Doctrine/Orm/RedirectRouteTest.php b/tests/Functional/Doctrine/Orm/RedirectRouteTest.php index 1e938f68..9a02cfaf 100644 --- a/tests/Functional/Doctrine/Orm/RedirectRouteTest.php +++ b/tests/Functional/Doctrine/Orm/RedirectRouteTest.php @@ -19,13 +19,13 @@ class RedirectRouteTest extends OrmTestCase { private RedirectController $controller; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->clearDb(Route::class); $this->clearDb(RedirectRoute::class); - $this->controller = new RedirectController($this->getContainer()->get('router')); + $this->controller = new RedirectController(self::getContainer()->get('router')); } public function testRedirectDoctrine(): void diff --git a/tests/Functional/Doctrine/Orm/RouteProviderTest.php b/tests/Functional/Doctrine/Orm/RouteProviderTest.php index d2e8c162..be6fc06c 100644 --- a/tests/Functional/Doctrine/Orm/RouteProviderTest.php +++ b/tests/Functional/Doctrine/Orm/RouteProviderTest.php @@ -12,21 +12,22 @@ namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route; +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\RouteProvider; use Symfony\Component\HttpFoundation\Request; class RouteProviderTest extends OrmTestCase { - private $repository; + private RouteProvider $repository; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->clearDb(Route::class); - $this->repository = $this->getContainer()->get('cmf_routing.route_provider'); + $this->repository = self::getContainer()->get('cmf_routing.route_provider'); } - public function testGetRouteCollectionForRequest() + public function testGetRouteCollectionForRequest(): void { $this->createRoute('route1', '/test'); $this->createRoute('route2', '/test/child'); diff --git a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php index c7247c0c..b2bceef6 100644 --- a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php @@ -18,16 +18,16 @@ class RedirectRouteTest extends BaseTestCase { - public const ROUTE_ROOT = '/test/redirectroute'; + private const ROUTE_ROOT = '/test/redirectroute'; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->db('PHPCR')->createTestNode(); $this->createRoute(self::ROUTE_ROOT); } - public function testRedirectDoctrine() + public function testRedirectDoctrine(): void { $content = $this->createContent(); $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -57,7 +57,7 @@ public function testRedirectDoctrine() $this->assertEquals(['test' => 'toast'], $defaults); } - public function testSetContent() + public function testSetContent(): void { $content = $this->createMock(RouteReferrersReadInterface::class); $redirect = new RedirectRoute(); diff --git a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php index 6c028463..7bba5d9a 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php @@ -21,20 +21,19 @@ class RouteProviderTest extends BaseTestCase { - public const ROUTE_ROOT = '/test/routing'; + private const ROUTE_ROOT = '/test/routing'; - /** @var RouteProvider */ - private $repository; + private RouteProvider $repository; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->db('PHPCR')->createTestNode(); $this->createRoute(self::ROUTE_ROOT); - $this->repository = $this->getContainer()->get('cmf_routing.route_provider'); + $this->repository = self::getContainer()->get('cmf_routing.route_provider'); } - private function buildRoutes() + private function buildRoutes(): void { $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -58,7 +57,7 @@ private function buildRoutes() $this->getDm()->clear(); } - public function testGetRouteCollectionForRequest() + public function testGetRouteCollectionForRequest(): void { $this->buildRoutes(); @@ -83,7 +82,7 @@ public function testGetRouteCollectionForRequest() $this->assertNull($iterator->current()->getDefault('_format')); } - public function testGetRouteCollectionForRequestFormat() + public function testGetRouteCollectionForRequestFormat(): void { $this->buildRoutes(); @@ -111,7 +110,7 @@ public function testGetRouteCollectionForRequestFormat() /** * The root route will always be found. */ - public function testGetRouteCollectionForRequestNonPhpcrUrl() + public function testGetRouteCollectionForRequestNonPhpcrUrl(): void { $routes = $this->repository->getRouteCollectionForRequest(Request::create('http://localhost/')); $this->assertInstanceOf(RouteCollection::class, $routes); @@ -126,14 +125,14 @@ public function testGetRouteCollectionForRequestNonPhpcrUrl() /** * The root route will always be found. */ - public function testGetRouteCollectionForRequestColonInUrl() + public function testGetRouteCollectionForRequestColonInUrl(): void { $collection = $this->repository->getRouteCollectionForRequest(Request::create('http://foo.com/jcr:content')); $this->assertInstanceOf(RouteCollection::class, $collection); $this->assertCount(0, $collection); } - public function testGetRoutesByNames() + public function testGetRoutesByNames(): void { $this->buildRoutes(); diff --git a/tests/Functional/Doctrine/Phpcr/RouteTest.php b/tests/Functional/Doctrine/Phpcr/RouteTest.php index 8c98e191..a5a8eff7 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteTest.php @@ -16,9 +16,9 @@ class RouteTest extends BaseTestCase { - public const ROUTE_ROOT = '/test/routing'; + private const ROUTE_ROOT = '/test/routing'; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->db('PHPCR')->createTestNode(); diff --git a/tests/Functional/Routing/DynamicRouterTest.php b/tests/Functional/Routing/DynamicRouterTest.php index 14b17d8d..a1b45ee2 100644 --- a/tests/Functional/Routing/DynamicRouterTest.php +++ b/tests/Functional/Routing/DynamicRouterTest.php @@ -32,23 +32,18 @@ */ class DynamicRouterTest extends BaseTestCase { - /** - * @var ChainRouter - */ - protected $router; + private ChainRouter $router; - protected $routeNamePrefix; + private const ROUTE_ROOT = '/test/routing'; - public const ROUTE_ROOT = '/test/routing'; - - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->db('PHPCR')->createTestNode(); $this->createRoute(self::ROUTE_ROOT); - $this->router = $this->getContainer()->get('router'); + $this->router = self::getContainer()->get('router'); $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -91,7 +86,7 @@ public function setUp(): void $this->getDm()->flush(); } - public function testMatch() + public function testMatch(): void { $expected = [ RouteObjectInterface::CONTROLLER_NAME, @@ -107,7 +102,7 @@ public function testMatch() $this->assertEquals('/test/routing/testroute/child', $matches[RouteObjectInterface::ROUTE_NAME]); } - public function testMatchParameters() + public function testMatchParameters(): void { $expected = [ RouteObjectInterface::CONTROLLER_NAME => 'testController', @@ -125,13 +120,13 @@ public function testMatchParameters() $this->assertEquals($expected, $matches); } - public function testNoMatch() + public function testNoMatch(): void { $this->expectException(ResourceNotFoundException::class); $this->router->matchRequest(Request::create('/testroute/child/123a')); } - public function testNotAllowed() + public function testNotAllowed(): void { $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -147,7 +142,7 @@ public function testNotAllowed() $this->router->matchRequest(Request::create('/notallowed', 'POST')); } - public function testMatchDefaultFormat() + public function testMatchDefaultFormat(): void { $expected = [ '_controller' => 'testController', @@ -163,7 +158,7 @@ public function testMatchDefaultFormat() $this->assertEquals($expected, $matches); } - public function testMatchFormat() + public function testMatchFormat(): void { $expected = [ '_controller' => 'testController', @@ -203,13 +198,13 @@ public function testMatchFormat() $this->assertEquals($expected, $matches); } - public function testNoMatchingFormat() + public function testNoMatchingFormat(): void { $this->expectException(ResourceNotFoundException::class); $this->router->matchRequest(Request::create('/format/48.xml')); } - public function testMatchLocale() + public function testMatchLocale(): void { $route = new Route(); $route->setPosition($this->getDm()->find(null, self::ROUTE_ROOT), 'de'); @@ -254,7 +249,7 @@ public function testMatchLocale() ); } - public function testEnhanceControllerByAlias() + public function testEnhanceControllerByAlias(): void { // put a redirect route $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -278,7 +273,7 @@ public function testEnhanceControllerByAlias() $this->assertEquals($expected, $matches); } - public function testEnhanceControllerByClass() + public function testEnhanceControllerByClass(): void { // put a redirect route $root = $this->getDm()->find(null, self::ROUTE_ROOT); @@ -301,7 +296,7 @@ public function testEnhanceControllerByClass() $this->assertEquals($expected, $matches); } - public function testEnhanceTemplateByClass() + public function testEnhanceTemplateByClass(): void { if ($content = $this->getDm()->find(null, '/test/content/templatebyclass')) { $this->getDm()->remove($content); @@ -335,7 +330,7 @@ public function testEnhanceTemplateByClass() $this->assertEquals('TestBundle:Content:index.html.twig', $request->attributes->get(DynamicRouter::CONTENT_TEMPLATE)); } - public function testGenerate() + public function testGenerate(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute/child'); @@ -343,14 +338,14 @@ public function testGenerate() $this->assertEquals('/testroute/child?test=value', $url); } - public function testGenerateAbsolute() + public function testGenerateAbsolute(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute/child'); $url = $this->router->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['test' => 'value', RouteObjectInterface::ROUTE_OBJECT => $route], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/testroute/child?test=value', $url); } - public function testGenerateParameters() + public function testGenerateParameters(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute'); @@ -358,7 +353,7 @@ public function testGenerateParameters() $this->assertEquals('/testroute/gen-slug?test=value', $url); } - public function testGenerateParametersInvalid() + public function testGenerateParametersInvalid(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute'); @@ -366,7 +361,7 @@ public function testGenerateParametersInvalid() $this->router->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['slug' => 'gen-slug', 'id' => 'nonumber', RouteObjectInterface::ROUTE_OBJECT => $route]); } - public function testGenerateDefaultFormat() + public function testGenerateDefaultFormat(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/format'); @@ -374,7 +369,7 @@ public function testGenerateDefaultFormat() $this->assertEquals('/format/37', $url); } - public function testGenerateFormat() + public function testGenerateFormat(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/format'); @@ -382,7 +377,7 @@ public function testGenerateFormat() $this->assertEquals('/format/37.json', $url); } - public function testGenerateNoMatchingFormat() + public function testGenerateNoMatchingFormat(): void { $route = $this->getDm()->find(null, self::ROUTE_ROOT.'/format'); diff --git a/tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php b/tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php index 65bc5aa0..13b65be0 100644 --- a/tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php +++ b/tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php @@ -26,7 +26,7 @@ protected function getContainerExtensions(): array ]; } - public function testLoadDefault() + public function testLoadDefault(): void { $this->load([ 'dynamic' => [ @@ -56,7 +56,7 @@ public function testLoadDefault() ); } - public function testLoadConfigured() + public function testLoadConfigured(): void { $this->load([ 'dynamic' => [ @@ -93,7 +93,7 @@ public function testLoadConfigured() ); } - public function testWhitespaceInPriorities() + public function testWhitespaceInPriorities(): void { $this->load([ 'dynamic' => [ @@ -133,7 +133,7 @@ public function testWhitespaceInPriorities() /** * @dataProvider getBasePathsTests */ - public function testLoadBasePaths($phpcrConfig, $routeBasepathsParameter) + public function testLoadBasePaths(array $phpcrConfig, array $routeBasepathsParameter): void { $this->container->setParameter( 'kernel.bundles', @@ -163,7 +163,7 @@ public function testLoadBasePaths($phpcrConfig, $routeBasepathsParameter) ); } - public function getBasePathsTests() + public function getBasePathsTests(): array { return [ [ @@ -191,7 +191,7 @@ public function getBasePathsTests() /** * @dataProvider getBasePathsMergingTests */ - public function testRouteBasepathsMerging($phpcrConfig1, $phpcrConfig2, $routeBasepathsParameter) + public function testRouteBasepathsMerging(array $phpcrConfig1, array $phpcrConfig2, array $routeBasepathsParameter): void { $this->container->setParameter( 'kernel.bundles', @@ -232,7 +232,7 @@ public function testRouteBasepathsMerging($phpcrConfig1, $phpcrConfig2, $routeBa ); } - public function getBasePathsMergingTests() + public function getBasePathsMergingTests(): array { return [ [ @@ -258,7 +258,7 @@ public function getBasePathsMergingTests() ]; } - public function testInitializerEnabled() + public function testInitializerEnabled(): void { $this->container->setParameter( 'kernel.bundles', @@ -282,7 +282,7 @@ public function testInitializerEnabled() $this->assertContainerBuilderHasService('cmf_routing.initializer', GenericInitializer::class); } - public function testInitializerDisabled() + public function testInitializerDisabled(): void { $this->container->setParameter( 'kernel.bundles', @@ -306,7 +306,7 @@ public function testInitializerDisabled() $this->assertFalse($this->container->has('cmf_routing.initializer')); } - public function testSettingCustomRouteClassForOrm() + public function testSettingCustomRouteClassForOrm(): void { $this->load([ 'dynamic' => [ diff --git a/tests/Unit/DependencyInjection/Compiler/SetRouterPassTest.php b/tests/Unit/DependencyInjection/Compiler/SetRouterPassTest.php index 9e388c56..2331434d 100644 --- a/tests/Unit/DependencyInjection/Compiler/SetRouterPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/SetRouterPassTest.php @@ -22,7 +22,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new SetRouterPass()); } - public function testMapperPassReplacesRouterAlias() + public function testMapperPassReplacesRouterAlias(): void { $this->container->setParameter('cmf_routing.replace_symfony_router', true); @@ -31,7 +31,7 @@ public function testMapperPassReplacesRouterAlias() $this->assertContainerBuilderHasAlias('router', 'cmf_routing.router'); } - public function testMapperPassDoesNotReplaceRouterAlias() + public function testMapperPassDoesNotReplaceRouterAlias(): void { $this->container->setParameter('cmf_routing.replace_symfony_router', false); diff --git a/tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php b/tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php index 768f1f33..f9266386 100644 --- a/tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php @@ -29,7 +29,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void * * @dataProvider provideDocumentsValidationContext */ - public function testRegisterDocumentsValidation($hasPhpcr, $hasValidator, $shouldBeRegistered) + public function testRegisterDocumentsValidation(bool $hasPhpcr, bool $hasValidator, bool $shouldBeRegistered): void { if ($hasPhpcr) { $this->setParameter('cmf_routing.backend_type_phpcr', null); @@ -71,7 +71,7 @@ public function testRegisterDocumentsValidation($hasPhpcr, $hasValidator, $shoul * - _$hasValidator: Is the validator available ? * - _$shouldBeRegistered_: Should the documents validation be registered ? */ - public function provideDocumentsValidationContext() + public function provideDocumentsValidationContext(): array { return [ [true, true, true], diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 089c472d..d3bc386f 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -29,7 +29,7 @@ protected function getConfiguration(): ConfigurationInterface return new Configuration(); } - public function testSupportsAllConfigFormats() + public function testSupportsAllConfigFormats(): void { $expectedConfiguration = [ 'chain' => [ @@ -80,7 +80,7 @@ public function testSupportsAllConfigFormats() ], ]; - $formats = array_map(function ($path) { + $formats = array_map(static function ($path) { return __DIR__.'/../../Fixtures/fixtures/'.$path; }, [ 'config/config.yml', diff --git a/tests/Unit/DependencyInjection/XmlSchemaTest.php b/tests/Unit/DependencyInjection/XmlSchemaTest.php index e06ae92f..ae2aa502 100644 --- a/tests/Unit/DependencyInjection/XmlSchemaTest.php +++ b/tests/Unit/DependencyInjection/XmlSchemaTest.php @@ -15,20 +15,19 @@ class XmlSchemaTest extends XmlSchemaTestCase { - protected $fixturesPath; + private string $fixturesPath; + private string $schemaPath; - protected $schemaPath; - - public function setUp(): void + protected function setUp(): void { $this->fixturesPath = __DIR__.'/../../Fixtures/fixtures/config/'; $this->schemaPath = __DIR__.'/../../../src/Resources/config/schema/routing-1.0.xsd'; } - public function testSchema() + public function testSchema(): void { $fixturesPath = $this->fixturesPath; - $xmlFiles = array_map(function ($file) use ($fixturesPath) { + $xmlFiles = array_map(static function ($file) use ($fixturesPath) { return $fixturesPath.$file; }, [ 'config.xml', @@ -41,7 +40,7 @@ public function testSchema() $this->assertSchemaAcceptsXml($xmlFiles, $this->schemaPath); } - public function testSchemaInvalidesTwoPersistenceLayers() + public function testSchemaInvalidatesTwoPersistenceLayers(): void { $this->assertSchemaRefusesXml($this->fixturesPath.'config_invalid1.xml', $this->schemaPath); } diff --git a/tests/Unit/Doctrine/Orm/ContentRepositoryTest.php b/tests/Unit/Doctrine/Orm/ContentRepositoryTest.php index caf4d00b..77250d78 100644 --- a/tests/Unit/Doctrine/Orm/ContentRepositoryTest.php +++ b/tests/Unit/Doctrine/Orm/ContentRepositoryTest.php @@ -14,20 +14,18 @@ use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectRepository; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\ContentRepository; class ContentRepositoryTest extends TestCase { - private $document; + private \stdClass $document; + private ManagerRegistry&MockObject $managerRegistry; + private ObjectManager&MockObject $objectManager; + private ObjectRepository&MockObject $objectRepository; - private $managerRegistry; - - private $objectManager; - - private $objectRepository; - - public function setUp(): void + protected function setUp(): void { $this->document = new \stdClass(); $this->objectManager = $this->createMock(ObjectManager::class); @@ -35,26 +33,23 @@ public function setUp(): void $this->objectRepository = $this->createMock(ObjectRepository::class); } - public function testFindById() + public function testFindById(): void { $this->objectManager - ->expects($this->any()) ->method('getRepository') ->with($this->equalTo('stdClass')) - ->will($this->returnValue($this->objectRepository)) + ->willReturn($this->objectRepository) ; $this->objectRepository - ->expects($this->any()) ->method('find') ->with(123) - ->will($this->returnValue($this->document)) + ->willReturn($this->document) ; $this->managerRegistry - ->expects($this->any()) ->method('getManager') - ->will($this->returnValue($this->objectManager)) + ->willReturn($this->objectManager) ; $contentRepository = new ContentRepository($this->managerRegistry); @@ -68,26 +63,23 @@ public function testFindById() /** * @dataProvider getFindCorrectModelAndIdData */ - public function testFindCorrectModelAndId($input, $model, $id) + public function testFindCorrectModelAndId($input, $model, $id): void { $this->objectManager - ->expects($this->any()) ->method('getRepository') ->with($this->equalTo($model)) - ->will($this->returnValue($this->objectRepository)) + ->willReturn($this->objectRepository) ; $this->objectRepository - ->expects($this->any()) ->method('find') ->with($id) - ->will($this->returnValue($this)) + ->willReturn($this) ; $this->managerRegistry - ->expects($this->any()) ->method('getManager') - ->will($this->returnValue($this->objectManager)) + ->willReturn($this->objectManager) ; $contentRepository = new ContentRepository($this->managerRegistry); @@ -97,7 +89,7 @@ public function testFindCorrectModelAndId($input, $model, $id) $this->assertSame($this, $foundDocument); } - public function getFindCorrectModelAndIdData() + public function getFindCorrectModelAndIdData(): array { return [ ['Acme\ContentBundle\Entity\Content:12', 'Acme\ContentBundle\Entity\Content', 12], diff --git a/tests/Unit/Doctrine/Orm/RouteProviderTest.php b/tests/Unit/Doctrine/Orm/RouteProviderTest.php index 138f2331..539f4cd0 100644 --- a/tests/Unit/Doctrine/Orm/RouteProviderTest.php +++ b/tests/Unit/Doctrine/Orm/RouteProviderTest.php @@ -24,37 +24,14 @@ class RouteProviderTest extends TestCase { - /** - * @var Route&MockObject - */ - private Route $routeMock; - - /** - * @var Route&MockObject - */ - private Route $route2Mock; - - /** - * @var ManagerRegistry&MockObject - */ - private ManagerRegistry $managerRegistryMock; - - /** - * @var ObjectManager&MockObject - */ - private ObjectManager $objectManagerMock; - - /** - * @var EntityRepository&MockObject - */ - private EntityRepository $objectRepositoryMock; - - /** - * @var CandidatesInterface&MockObject - */ - private CandidatesInterface $candidatesMock; - - public function setUp(): void + private Route&MockObject $routeMock; + private Route&MockObject $route2Mock; + private ManagerRegistry&MockObject $managerRegistryMock; + private ObjectManager&MockObject $objectManagerMock; + private EntityRepository&MockObject $objectRepositoryMock; + private CandidatesInterface&MockObject $candidatesMock; + + protected function setUp(): void { $this->routeMock = $this->createMock(Route::class); $this->route2Mock = $this->createMock(Route::class); @@ -62,7 +39,7 @@ public function setUp(): void $this->managerRegistryMock = $this->createMock(ManagerRegistry::class); $this->objectRepositoryMock = $this->getMockBuilder(EntityRepository::class) ->disableOriginalConstructor() - ->setMethods(['findByStaticPrefix', 'findOneBy', 'findBy']) + ->onlyMethods(['findByStaticPrefix', 'findOneBy', 'findBy']) ->getMock(); $this->candidatesMock = $this->createMock(CandidatesInterface::class); $this->candidatesMock diff --git a/tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php b/tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php index f4104fa3..1902143d 100644 --- a/tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php +++ b/tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php @@ -15,22 +15,19 @@ use Doctrine\ODM\PHPCR\DocumentManagerInterface; use Doctrine\ODM\PHPCR\UnitOfWork; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\ContentRepository; class ContentRepositoryTest extends TestCase { - private $document; + private \stdClass $document; + private \stdClass $document2; + private DocumentManagerInterface&MockObject $objectManager; + private DocumentManagerInterface&MockObject $objectManager2; + private ManagerRegistry&MockObject $managerRegistry; - private $document2; - - private $objectManager; - - private $objectManager2; - - private $managerRegistry; - - public function setUp(): void + protected function setUp(): void { $this->document = new \stdClass(); $this->document2 = new \stdClass(); diff --git a/tests/Unit/Doctrine/Phpcr/IdPrefixListenerTest.php b/tests/Unit/Doctrine/Phpcr/IdPrefixListenerTest.php index 46e9b8e8..96218345 100644 --- a/tests/Unit/Doctrine/Phpcr/IdPrefixListenerTest.php +++ b/tests/Unit/Doctrine/Phpcr/IdPrefixListenerTest.php @@ -22,20 +22,11 @@ final class IdPrefixListenerTest extends TestCase { private IdPrefixListener $listener; - private PrefixCandidates $candidates; + private DocumentManager&MockObject $dmMock; + private Route&MockObject $routeMock; - /** - * @var DocumentManager&MockObject - */ - private DocumentManager $dmMock; - - /** - * @var Route&MockObject - */ - private Route $routeMock; - - public function setUp(): void + protected function setUp(): void { $this->candidates = new PrefixCandidates(['/cms/routes', '/cms/simple']); diff --git a/tests/Unit/Doctrine/Phpcr/LocaleListenerTest.php b/tests/Unit/Doctrine/Phpcr/LocaleListenerTest.php index 1c17325f..a1071803 100644 --- a/tests/Unit/Doctrine/Phpcr/LocaleListenerTest.php +++ b/tests/Unit/Doctrine/Phpcr/LocaleListenerTest.php @@ -23,20 +23,11 @@ class LocaleListenerTest extends TestCase { private LocaleListener $listener; - private PrefixCandidates $candidates; + private DocumentManager&MockObject $dmMock; + private Route&MockObject $routeMock; - /** - * @var DocumentManager&MockObject - */ - private DocumentManager $dmMock; - - /** - * @var Route&MockObject - */ - private Route $routeMock; - - public function setUp(): void + protected function setUp(): void { $this->candidates = new PrefixCandidates(['/cms/routes', '/cms/simple']); @@ -73,7 +64,7 @@ public function testNoPrefixMatch(): void $this->listener->postLoad($args); } - private function prepareMatch() + private function prepareMatch(): LifecycleEventArgs { $this->routeMock->expects($this->once()) ->method('getId') @@ -162,7 +153,6 @@ public function testSetLocales(): void $this->listener->setLocales(['xx']); $reflection = new \ReflectionClass(LocaleListener::class); $locales = $reflection->getProperty('locales'); - $locales->setAccessible(true); $this->assertSame(['xx'], $locales->getValue($this->listener)); } diff --git a/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php b/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php index 8eb3ef4e..1142cadc 100644 --- a/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php +++ b/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php @@ -29,37 +29,14 @@ class RouteProviderTest extends TestCase { - /** - * @var ManagerRegistry&MockObject - */ - private ManagerRegistry $managerRegistryMock; - - /** - * @var CandidatesInterface&MockObject - */ - protected CandidatesInterface $candidatesMock; - - /** - * @var DocumentManager&MockObject - */ - protected DocumentManager $dmMock; - - /** - * @var DocumentManager&MockObject - */ - protected DocumentManager $dm2Mock; - - /** - * @var Route&MockObject - */ - protected Route $routeMock; - - /** - * @var Route&MockObject - */ - protected Route $route2Mock; - - public function setUp(): void + private ManagerRegistry&MockObject $managerRegistryMock; + private CandidatesInterface&MockObject $candidatesMock; + private DocumentManager&MockObject $dmMock; + private DocumentManager&MockObject $dm2Mock; + private Route&MockObject $routeMock; + private Route&MockObject $route2Mock; + + protected function setUp(): void { $this->routeMock = $this->createMock(Route::class); $this->route2Mock = $this->createMock(Route::class); @@ -69,7 +46,7 @@ public function setUp(): void $this->managerRegistryMock ->method('getManager') - ->will($this->returnValue($this->dmMock)) + ->willReturn($this->dmMock) ; $this->candidatesMock = $this->createMock(CandidatesInterface::class); @@ -187,7 +164,7 @@ public function testGetRouteByNameUuid(): void $this->assertEquals('/cms/routes/test-route', $foundRoute->getPath()); } - public function testGetRouteByNameUuidNotFound() + public function testGetRouteByNameUuidNotFound(): void { $uuid = UUIDHelper::generateUUID(); @@ -208,7 +185,6 @@ public function testGetRouteByNameUuidNotCandidate(): void { $uuid = UUIDHelper::generateUUID(); $this->routeMock - ->expects($this->any()) ->method('getPath') ->willReturn('/cms/routes/test-route') ; diff --git a/tests/Unit/Doctrine/Phpcr/RouteTest.php b/tests/Unit/Doctrine/Phpcr/RouteTest.php index bce445bd..5dc6c5bb 100644 --- a/tests/Unit/Doctrine/Phpcr/RouteTest.php +++ b/tests/Unit/Doctrine/Phpcr/RouteTest.php @@ -18,10 +18,9 @@ class RouteTest extends TestCase { private Route $route; - private Route $childRoute1; - public function setUp(): void + protected function setUp(): void { $this->route = new Route(); diff --git a/tests/Unit/Form/Type/RouteTypeTypeTest.php b/tests/Unit/Form/Type/RouteTypeTypeTest.php index 92978403..742b2b06 100644 --- a/tests/Unit/Form/Type/RouteTypeTypeTest.php +++ b/tests/Unit/Form/Type/RouteTypeTypeTest.php @@ -17,17 +17,14 @@ class RouteTypeTypeTest extends TestCase { - /** - * @var RouteTypeType - */ - private $type; + private RouteTypeType $type; - public function setUp(): void + protected function setUp(): void { $this->type = new RouteTypeType(); } - public function testSetDefaultOptions() + public function testSetDefaultOptions(): void { $type = new RouteTypeType(); $optionsResolver = new OptionsResolver(); @@ -39,7 +36,7 @@ public function testSetDefaultOptions() $this->assertIsArray($options['choices']); } - public function testDefaultsSet() + public function testDefaultsSet(): void { $this->type->addRouteType('foobar'); $this->type->addRouteType('barfoo'); diff --git a/tests/Unit/Routing/DynamicRouterTest.php b/tests/Unit/Routing/DynamicRouterTest.php index b9c1890d..d323d7c5 100644 --- a/tests/Unit/Routing/DynamicRouterTest.php +++ b/tests/Unit/Routing/DynamicRouterTest.php @@ -24,52 +24,24 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\RequestContext; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; class DynamicRouterTest extends TestCase { - /** - * @var DynamicRouter - */ - private $router; - - /** - * @var UrlMatcherInterface|MockObject - */ - private $matcher; - - /** - * @var UrlGeneratorInterface|MockObject - */ - private $generator; - - /** - * @var RequestContext|MockObject - */ - private $context; - - /** - * @var Request - */ - private $request; - - /** - * @var RequestStack - */ - private $requestStack; - - /** - * @var EventDispatcherInterface|MockObject - */ - private $eventDispatcher; - - public function setUp(): void + private DynamicRouter $router; + private UrlMatcherInterface&MockObject $matcher; + private UrlGeneratorInterface&MockObject $generator; + private RequestContext&MockObject $context; + private Request $request; + private RequestStack $requestStack; + private EventDispatcherInterface&MockObject $eventDispatcher; + + protected function setUp(): void { $this->matcher = $this->createMock(UrlMatcherInterface::class); $this->matcher->expects($this->once()) ->method('match') ->with('/foo') - ->will($this->returnValue(['foo' => 'bar', RouteObjectInterface::CONTENT_OBJECT => 'bla', RouteObjectInterface::TEMPLATE_NAME => 'template'])) + ->willReturn(['foo' => 'bar', RouteObjectInterface::CONTENT_OBJECT => 'bla', RouteObjectInterface::TEMPLATE_NAME => 'template']) ; $this->generator = $this->createMock(UrlGeneratorInterface::class); @@ -83,7 +55,7 @@ public function setUp(): void $this->router->setRequestStack($this->requestStack); } - private function assertRequestAttributes($request) + private function assertRequestAttributes($request): void { $this->assertTrue($request->attributes->has(DynamicRouter::CONTENT_KEY)); $this->assertEquals('bla', $request->attributes->get(DynamicRouter::CONTENT_KEY)); @@ -94,17 +66,11 @@ private function assertRequestAttributes($request) /** * @group legacy */ - public function testMatch() + public function testMatch(): void { - $dispatchParams = [Events::PRE_DYNAMIC_MATCH, $this->equalTo(new RouterMatchEvent())]; - if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) { - // New Symfony 4.3 EventDispatcher signature - $dispatchParams = [$this->equalTo(new RouterMatchEvent()), Events::PRE_DYNAMIC_MATCH]; - } - $this->eventDispatcher->expects($this->once()) ->method('dispatch') - ->with(...$dispatchParams) + ->with($this->equalTo(new RouterMatchEvent()), Events::PRE_DYNAMIC_MATCH) ; $parameters = $this->router->match('/foo'); @@ -113,17 +79,11 @@ public function testMatch() $this->assertRequestAttributes($this->request); } - public function testMatchRequest() + public function testMatchRequest(): void { - $dispatchParams = [Events::PRE_DYNAMIC_MATCH_REQUEST, $this->equalTo(new RouterMatchEvent($this->request))]; - if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) { - // New Symfony 4.3 EventDispatcher signature - $dispatchParams = [$this->equalTo(new RouterMatchEvent($this->request)), Events::PRE_DYNAMIC_MATCH_REQUEST]; - } - $this->eventDispatcher->expects($this->once()) ->method('dispatch') - ->with(...$dispatchParams) + ->with($this->equalTo(new RouterMatchEvent($this->request)), Events::PRE_DYNAMIC_MATCH_REQUEST) ; $parameters = $this->router->matchRequest($this->request); @@ -135,19 +95,13 @@ public function testMatchRequest() /** * @group legacy */ - public function testMatchNoRequest() + public function testMatchNoRequest(): void { $this->router->setRequestStack(new RequestStack()); - $dispatchParams = [Events::PRE_DYNAMIC_MATCH, $this->equalTo(new RouterMatchEvent())]; - if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) { - // New Symfony 4.3 EventDispatcher signature - $dispatchParams = [$this->equalTo(new RouterMatchEvent()), Events::PRE_DYNAMIC_MATCH]; - } - $this->eventDispatcher->expects($this->once()) ->method('dispatch') - ->with(...$dispatchParams) + ->with($this->equalTo(new RouterMatchEvent()), Events::PRE_DYNAMIC_MATCH) ; $this->expectException(ResourceNotFoundException::class); @@ -155,7 +109,7 @@ public function testMatchNoRequest() $this->router->match('/foo'); } - public function testEventOptional() + public function testEventOptional(): void { $router = new DynamicRouter($this->context, $this->matcher, $this->generator); diff --git a/tests/Unit/Routing/RedirectableRequestMatcherTest.php b/tests/Unit/Routing/RedirectableRequestMatcherTest.php index 9d4c0fad..39464670 100644 --- a/tests/Unit/Routing/RedirectableRequestMatcherTest.php +++ b/tests/Unit/Routing/RedirectableRequestMatcherTest.php @@ -21,32 +21,13 @@ class RedirectableRequestMatcherTest extends TestCase { - /** - * @var RedirectableRequestMatcher - */ - private $redirectableRequestMatcher; + private RedirectableRequestMatcher $redirectableRequestMatcher; + private RequestMatcherInterface&MockObject $decoratedRequestMatcher; + private Request $requestWithoutSlash; + private Request $requestWithSlash; + private RequestContext&MockObject $context; - /** - * @var RequestMatcherInterface|MockObject - */ - private $decoratedRequestMatcher; - - /** - * @var Request - */ - private $requestWithoutSlash; - - /** - * @var Request - */ - private $requestWithSlash; - - /** - * @var RequestContext|MockObject - */ - private $context; - - public function setUp(): void + protected function setUp(): void { $this->requestWithoutSlash = Request::create('/foo'); $this->requestWithSlash = Request::create('/foo/'); @@ -55,19 +36,19 @@ public function setUp(): void $this->redirectableRequestMatcher = new RedirectableRequestMatcher($this->decoratedRequestMatcher, $this->context); } - public function testMatchRequest() + public function testMatchRequest(): void { $this->decoratedRequestMatcher ->expects($this->once()) ->method('matchRequest') ->with($this->requestWithoutSlash) - ->will($this->returnValue(['foo' => 'bar'])); + ->willReturn(['foo' => 'bar']); $parameters = $this->redirectableRequestMatcher->matchRequest($this->requestWithoutSlash); $this->assertEquals(['foo' => 'bar'], $parameters); } - public function testMatchRequestWithSlash() + public function testMatchRequestWithSlash(): void { $this->decoratedRequestMatcher ->method('matchRequest') @@ -82,7 +63,7 @@ public function testMatchRequestWithSlash() )); $parameters = $this->redirectableRequestMatcher->matchRequest($this->requestWithSlash); - $this->assertTrue('foobar' === $parameters['_route']); - $this->assertTrue('/foo' === $parameters['path']); + $this->assertSame('foobar', $parameters['_route']); + $this->assertSame('/foo', $parameters['path']); } } diff --git a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php index 9182ef13..779d85ac 100644 --- a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php +++ b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php @@ -23,8 +23,7 @@ class RouteDefaultsTwigValidatorTest extends ConstraintValidatorTestCase { - protected MockObject&ControllerResolverInterface $controllerResolver; - + private MockObject&ControllerResolverInterface $controllerResolver; private MockObject&LoaderInterface $loader; protected function setUp(): void