diff --git a/composer.json b/composer.json index 5274745..bde531f 100644 --- a/composer.json +++ b/composer.json @@ -3,17 +3,16 @@ "description": "A nice PHP microframework", "license": "MIT", "require": { - "php": ">=5.4.0", - "symfony/config": "~2.3", - "symfony/http-kernel": "~2.3", - "symfony/dependency-injection": "~2.3", - "nikic/fast-route": ">=0.6" + "php": ">=8.1", + "symfony/config": "~6.3", + "symfony/http-kernel": "~6.3", + "symfony/dependency-injection": "~6.3", + "symfony/yaml": "~6.3", + "nikic/fast-route": ">=1.3" }, "require-dev": { - "symfony/debug": "~2.3", - "symfony/expression-language": "~2.4", - "phpunit/phpunit": "~3.7", - "codeclimate/php-test-reporter": "dev-master" + "symfony/expression-language": "~6.3", + "phpunit/phpunit": "~10.3" }, "suggest": { "stack/builder": "Stack HttpKernel middlewares - http://stackphp.com", diff --git a/src/Application.php b/src/Application.php index ba42df1..f3319c0 100644 --- a/src/Application.php +++ b/src/Application.php @@ -244,12 +244,12 @@ public function run(Request $request = null) * * @param Request $request A Request instance * @param int $type The type of the request - * (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) + * (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST) * @param bool $catch Whether to catch exceptions or not * * @return Response A Response instance */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) + public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response { if (!$this->booted) { $this->boot(); @@ -361,13 +361,13 @@ public function getContainer() * @param object|callable $service The service instance * @param string $scope The scope of the service */ - public function set($id, $service, $scope = ContainerInterface::SCOPE_CONTAINER) + public function set(string $id, ?object $service) { if (!$this->booted) { $this->boot(); } - $this->container->set($id, $service, $scope); + $this->container->set($id, $service); } /** diff --git a/src/DependencyInjection/ContainerInitializer/CachedInitializer.php b/src/DependencyInjection/ContainerInitializer/CachedInitializer.php index be0457a..d9eb3c4 100644 --- a/src/DependencyInjection/ContainerInitializer/CachedInitializer.php +++ b/src/DependencyInjection/ContainerInitializer/CachedInitializer.php @@ -72,7 +72,7 @@ public function initializeContainer(Application $application, array $extensions $this->dumpContainer($cache, $container, $class, 'Container'); } - require_once $cache; + require_once $cache->getPath(); return new $class(); } @@ -97,6 +97,11 @@ protected function getContainerClass(Application $application) */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { + if (!$container->isCompiled()) { + // The container must be compiled before it can be dumped. + $container->compile(); + } + $dumper = new PhpDumper($container); $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass)); diff --git a/src/DependencyInjection/ContainerInitializer/DefaultInitializer.php b/src/DependencyInjection/ContainerInitializer/DefaultInitializer.php index cd74ae1..a35e39e 100644 --- a/src/DependencyInjection/ContainerInitializer/DefaultInitializer.php +++ b/src/DependencyInjection/ContainerInitializer/DefaultInitializer.php @@ -19,8 +19,8 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Scope; +use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; -use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; /** * Creates and initializes a Service Container, ready for use by the Application @@ -62,18 +62,14 @@ public function initializeContainer(Application $application, array $extensions $container->setParameter('app.cache_dir', $application->getCacheDir()); $container->setParameter('app.log_dir', $application->getLogDir()); - $container->register('event_dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher') - ->setArguments(array(new Reference('service_container'))); + $container->register('event_dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher') + ->setPublic(true); $container->register('app', 'Symfony\Component\HttpKernel\HttpKernelInterface') ->setSynthetic(true); $container->register('request', 'Symfony\Componenet\HttpKernel\Request') - ->setSynthetic(true) - ->setSynchronized(true) - ->setScope('request'); - - $container->addScope(new Scope('request')); + ->setSynthetic(true); $extensionAliases = array(); foreach ($extensions as $extension) { diff --git a/src/Extension/LogConfiguration.php b/src/Extension/LogConfiguration.php index 21f72e6..fe880e5 100644 --- a/src/Extension/LogConfiguration.php +++ b/src/Extension/LogConfiguration.php @@ -21,8 +21,8 @@ class LogConfiguration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('logging'); + $treeBuilder = new TreeBuilder('logging'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() diff --git a/src/Extension/LogExtension.php b/src/Extension/LogExtension.php index 2998954..b9f55f0 100644 --- a/src/Extension/LogExtension.php +++ b/src/Extension/LogExtension.php @@ -97,7 +97,8 @@ private function configureStreamChannel(array $channelConfig, ContainerBuilder $ $container->register($loggerService) ->setClass('Monolog\Logger') ->addArgument($name) - ->addMethodCall('pushHandler', array(new Reference($handlerService))); + ->addMethodCall('pushHandler', array(new Reference($handlerService))) + ->setPublic(true); } private function configureErrorLogChannel(array $channelConfig, ContainerBuilder $container) diff --git a/src/Extension/RouterExtension.php b/src/Extension/RouterExtension.php index 240edcf..c79b11c 100644 --- a/src/Extension/RouterExtension.php +++ b/src/Extension/RouterExtension.php @@ -46,8 +46,7 @@ public function load(array $config, ContainerBuilder $container) ->addArgument(new Reference('router.collector')); $container->register('router.dispatcher', 'FastRoute\Dispatcher') - ->setFactoryService('router.dispatcher_factory') - ->setFactoryMethod('create'); + ->setFactory(array(new Reference('router.dispatcher_factory'), 'create')); $container->register('router.dispatcher_subscriber', 'Nice\Router\RouterSubscriber') ->addArgument(new Reference('router.dispatcher')) @@ -68,11 +67,12 @@ public function load(array $config, ContainerBuilder $container) 'request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false - ))); + ))) + ->setPublic(true); - $container->register('http_kernel', 'Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel') + $container->register('http_kernel', 'Symfony\Component\HttpKernel\HttpKernel') ->addArgument(new Reference('event_dispatcher')) - ->addArgument(new Reference('service_container')) - ->addArgument(new Reference('router.controller_resolver')); + ->addArgument(new Reference('router.controller_resolver')) + ->setPublic(true); } } diff --git a/src/Extension/SessionExtension.php b/src/Extension/SessionExtension.php index 256c114..50596ae 100644 --- a/src/Extension/SessionExtension.php +++ b/src/Extension/SessionExtension.php @@ -26,7 +26,8 @@ class SessionExtension extends Extension */ public function load(array $config, ContainerBuilder $container) { - $container->register('session', 'Symfony\Component\HttpFoundation\Session\Session'); + $container->register('session', 'Symfony\Component\HttpFoundation\Session\Session') + ->setPublic(true); $container->register('session.session_subscriber', 'Nice\Session\SessionSubscriber') ->addArgument(new Reference('service_container')) diff --git a/src/Router/ContainerAwareControllerResolver.php b/src/Router/ContainerAwareControllerResolver.php index cdbe1d7..2c613be 100644 --- a/src/Router/ContainerAwareControllerResolver.php +++ b/src/Router/ContainerAwareControllerResolver.php @@ -40,7 +40,7 @@ public function setContainer(ContainerInterface $container = null) * * @return callable */ - protected function createController($controller) + protected function createController(string $controller): callable { $parts = explode(':', $controller); if (count($parts) === 2) { diff --git a/src/Router/RouteCollector/CachedCollector.php b/src/Router/RouteCollector/CachedCollector.php index 40c5129..fcf2336 100644 --- a/src/Router/RouteCollector/CachedCollector.php +++ b/src/Router/RouteCollector/CachedCollector.php @@ -65,7 +65,7 @@ public function getData() $cache->write('getPath(); } /** diff --git a/src/Router/RouterSubscriber.php b/src/Router/RouterSubscriber.php index 61b1fca..fbfeb58 100644 --- a/src/Router/RouterSubscriber.php +++ b/src/Router/RouterSubscriber.php @@ -11,7 +11,7 @@ use FastRoute\Dispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; @@ -42,7 +42,7 @@ public function __construct(Dispatcher $dispatcher) * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { $request = $event->getRequest(); if ($request->get('_controller')) { diff --git a/src/Router/UrlGenerator/CachedDataGenerator.php b/src/Router/UrlGenerator/CachedDataGenerator.php index 263019e..5e485a6 100644 --- a/src/Router/UrlGenerator/CachedDataGenerator.php +++ b/src/Router/UrlGenerator/CachedDataGenerator.php @@ -59,6 +59,6 @@ public function getData() $cache->write('getPath(); } } diff --git a/src/Router/WrappedHandlerSubscriber.php b/src/Router/WrappedHandlerSubscriber.php index 046db38..16839c1 100644 --- a/src/Router/WrappedHandlerSubscriber.php +++ b/src/Router/WrappedHandlerSubscriber.php @@ -10,7 +10,7 @@ namespace Nice\Router; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -19,9 +19,9 @@ class WrappedHandlerSubscriber implements EventSubscriberInterface { /** - * @param GetResponseEvent $event + * @param RequestEvent $event */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { $request = $event->getRequest(); $handler = $request->get('_controller'); diff --git a/src/Session/SessionSubscriber.php b/src/Session/SessionSubscriber.php index 32b0fec..81f1b24 100644 --- a/src/Session/SessionSubscriber.php +++ b/src/Session/SessionSubscriber.php @@ -11,7 +11,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -36,9 +36,9 @@ public function __construct(ContainerInterface $container) } /** - * @param GetResponseEvent $event + * @param RequestEvent $event */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index ea4e623..4c3c4c6 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -9,6 +9,7 @@ namespace Nice\Tests; +use PHPUnit\Framework\TestCase; use Nice\Application; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; @@ -16,7 +17,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; -class ApplicationTest extends \PHPUnit_Framework_TestCase +class ApplicationTest extends TestCase { /** * Test the instantiation @@ -190,7 +191,7 @@ public function testDefaultExtensions() { /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('getRootDir')) + ->onlyMethods(array('getRootDir')) ->setConstructorArgs(array('init', true)) ->getMock(); $app->expects($this->any()) @@ -211,7 +212,7 @@ public function testInitializeContainer() { /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('getRootDir')) + ->onlyMethods(array('getRootDir')) ->setConstructorArgs(array('init', true)) ->getMock(); $app->expects($this->any()) @@ -234,14 +235,14 @@ public function testFailureToCreateCacheDir() { /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('getRootDir', 'getCacheDir')) + ->onlyMethods(array('getRootDir', 'getCacheDir')) ->setConstructorArgs(array('create', true)) ->getMock(); $app->expects($this->any()) ->method('getCacheDir') ->will($this->returnValue('/someunwriteable/path')); - $this->setExpectedException('RuntimeException', 'Unable to create the cache directory'); + $this->expectException('RuntimeException', 'Unable to create the cache directory'); $app->boot(); } @@ -257,14 +258,14 @@ public function testFailureToWriteCacheDir() /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('getRootDir', 'getCacheDir')) + ->onlyMethods(array('getRootDir', 'getCacheDir')) ->setConstructorArgs(array('write', true)) ->getMock(); $app->expects($this->any()) ->method('getCacheDir') ->will($this->returnValue($tmpdir)); - $this->setExpectedException('RuntimeException', 'Unable to write in the cache directory'); + $this->expectException('RuntimeException', 'Unable to write in the cache directory'); $app->boot(); } @@ -280,7 +281,7 @@ protected function getMockApplication(HttpKernelInterface $kernel = null, $cache /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('getRootDir', 'registerDefaultExtensions', 'initializeContainer')) + ->onlyMethods(array('getRootDir', 'registerDefaultExtensions', 'initializeContainer')) ->setConstructorArgs(array('test', true, $cache)) ->getMock(); $app->expects($this->any()) diff --git a/tests/DependencyInjection/ConfigurationProvider/FileConfigurationProviderTest.php b/tests/DependencyInjection/ConfigurationProvider/FileConfigurationProviderTest.php index 9733dc1..308b68c 100644 --- a/tests/DependencyInjection/ConfigurationProvider/FileConfigurationProviderTest.php +++ b/tests/DependencyInjection/ConfigurationProvider/FileConfigurationProviderTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\DependencyInjection\ConfigurationProvider; +use PHPUnit\Framework\TestCase; use Nice\DependencyInjection\ConfigurationProvider\FileConfigurationProvider; use Symfony\Component\DependencyInjection\ContainerBuilder; -class FileConfigurationProviderTest extends \PHPUnit_Framework_TestCase +class FileConfigurationProviderTest extends TestCase { /** * Test no-operation functionality diff --git a/tests/DependencyInjection/ConfigurationProvider/NullConfigurationProviderTest.php b/tests/DependencyInjection/ConfigurationProvider/NullConfigurationProviderTest.php index 014dcfa..f8d7459 100644 --- a/tests/DependencyInjection/ConfigurationProvider/NullConfigurationProviderTest.php +++ b/tests/DependencyInjection/ConfigurationProvider/NullConfigurationProviderTest.php @@ -9,16 +9,17 @@ namespace Nice\Tests\DependencyInjection\ConfigurationProvider; +use PHPUnit\Framework\TestCase; use Nice\DependencyInjection\ConfigurationProvider\NullConfigurationProvider; -class NullConfigurationProviderTest extends \PHPUnit_Framework_TestCase +class NullConfigurationProviderTest extends TestCase { /** * Test no-operation functionality */ public function testNoOp() { - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); + $container = $this->getMockForAbstractClass('Symfony\Component\DependencyInjection\ContainerBuilder'); $container->expects($this->never()) ->method($this->anything()); diff --git a/tests/DependencyInjection/ContainerInitializer/CachedInitializerTest.php b/tests/DependencyInjection/ContainerInitializer/CachedInitializerTest.php index f0417a9..a9e0056 100644 --- a/tests/DependencyInjection/ContainerInitializer/CachedInitializerTest.php +++ b/tests/DependencyInjection/ContainerInitializer/CachedInitializerTest.php @@ -9,12 +9,13 @@ namespace Nice\Tests\DependencyInjection\ContainerInitializer; +use PHPUnit\Framework\TestCase; use Nice\Application; use Nice\DependencyInjection\ContainerInitializer\CachedInitializer; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; -class CachedInitializerTest extends \PHPUnit_Framework_TestCase +class CachedInitializerTest extends TestCase { /** * Test container initialization @@ -25,7 +26,7 @@ public function testInitializeContainer() /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array('registerDefaultExtensions')) + ->onlyMethods(array('registerDefaultExtensions')) ->setConstructorArgs(array('cache_init'.sha1(uniqid('cache', true)), false)) ->getMock(); @@ -53,7 +54,8 @@ public function testCacheIsFresh(Application $app) */ public function testFailureToCreateCacheDir() { - $this->setExpectedException('RuntimeException', 'Unable to create the cache directory'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Unable to create the cache directory'); $this->getInitializer('/someunwriteable/path'); } @@ -67,7 +69,8 @@ public function testFailureToWriteCacheDir() mkdir($tmpdir, 0700, true); chmod($tmpdir, 0000); - $this->setExpectedException('RuntimeException', 'Unable to write in the cache directory'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Unable to write in the cache directory'); $this->getInitializer($tmpdir); } diff --git a/tests/DependencyInjection/ContainerInitializer/DefaultInitializerTest.php b/tests/DependencyInjection/ContainerInitializer/DefaultInitializerTest.php index 794f64d..d5db027 100644 --- a/tests/DependencyInjection/ContainerInitializer/DefaultInitializerTest.php +++ b/tests/DependencyInjection/ContainerInitializer/DefaultInitializerTest.php @@ -9,6 +9,7 @@ namespace Nice\Tests\DependencyInjection\ContainerInitializer; +use PHPUnit\Framework\TestCase; use Nice\Application; use Nice\DependencyInjection\CompilerAwareExtensionInterface; use Nice\DependencyInjection\ConfigurationProvider\NullConfigurationProvider; @@ -18,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; -class DefaultInitializerTest extends \PHPUnit_Framework_TestCase +class DefaultInitializerTest extends TestCase { /** * Test container initialization @@ -29,7 +30,7 @@ public function testInitializeContainer() /** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('Nice\Application') - ->setMethods(array( + ->onlyMethods(array( 'registerDefaultExtensions', 'getRootDir', 'getLogDir', @@ -86,7 +87,7 @@ public function __construct($serviceName = 'test') public function process(ContainerBuilder $container) { - $container->register($this->serviceName, '\stdClass'); + $container->register($this->serviceName, '\stdClass')->setPublic(true); } } diff --git a/tests/Extension/LogConfigurationTest.php b/tests/Extension/LogConfigurationTest.php index a4e91bc..0586628 100644 --- a/tests/Extension/LogConfigurationTest.php +++ b/tests/Extension/LogConfigurationTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\Extension; +use PHPUnit\Framework\TestCase; use Nice\Extension\LogConfiguration; use Symfony\Component\Config\Definition\Processor; -class LogConfigurationTest extends \PHPUnit_Framework_TestCase +class LogConfigurationTest extends TestCase { public function testDefaultConfig() { @@ -38,10 +39,10 @@ public function testDefaultChannelConfig() public function testInvalidHandler() { - $this->setExpectedException( - 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', - 'Invalid logging handler "fake"' + $this->expectException( + 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' ); + $this->expectExceptionMessage('Invalid logging handler "fake"'); $processor = new Processor(); $processor->processConfiguration(new LogConfiguration(), array(array('channels' => array('default' => array('handler' => 'fake'))))); diff --git a/tests/Extension/LogExtensionTest.php b/tests/Extension/LogExtensionTest.php index c7495a1..3626f46 100644 --- a/tests/Extension/LogExtensionTest.php +++ b/tests/Extension/LogExtensionTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\Extension; +use PHPUnit\Framework\TestCase; use Nice\Extension\LogExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; -class LogExtensionTest extends \PHPUnit_Framework_TestCase +class LogExtensionTest extends TestCase { /** * Test the LogExtension @@ -23,6 +24,8 @@ public function testConfigure() $container = new ContainerBuilder(); $extension->load(array(), $container); + + $this->assertFalse($container->hasDefinition('logger.default'), 'No logger config given, logger should not exist.'); } /** @@ -110,7 +113,8 @@ public function testConfigureStreamWithoutFileFails() ), )); - $this->setExpectedException('RuntimeException', 'The option "file" must be specified for the stream handler.'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('The option "file" must be specified for the stream handler.'); $container = new ContainerBuilder(); $extension->load(array(), $container); diff --git a/tests/Extension/RouterExtensionTest.php b/tests/Extension/RouterExtensionTest.php index f2e8cbf..79bf61a 100644 --- a/tests/Extension/RouterExtensionTest.php +++ b/tests/Extension/RouterExtensionTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\Extension; +use PHPUnit\Framework\TestCase; use Nice\Extension\RouterExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; -class RouterExtensionTest extends \PHPUnit_Framework_TestCase +class RouterExtensionTest extends TestCase { /** * Test the RouterExtension diff --git a/tests/Extension/SessionExtensionTest.php b/tests/Extension/SessionExtensionTest.php index 7721563..63a4af3 100644 --- a/tests/Extension/SessionExtensionTest.php +++ b/tests/Extension/SessionExtensionTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\Extension; +use PHPUnit\Framework\TestCase; use Nice\Extension\SessionExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; -class SessionExtensionTest extends \PHPUnit_Framework_TestCase +class SessionExtensionTest extends TestCase { /** * Test the RouterExtension diff --git a/tests/Router/ContainerAwareControllerResolverTest.php b/tests/Router/ContainerAwareControllerResolverTest.php index a407ebf..01e8731 100644 --- a/tests/Router/ContainerAwareControllerResolverTest.php +++ b/tests/Router/ContainerAwareControllerResolverTest.php @@ -9,13 +9,14 @@ namespace Nice\Tests\Router; +use PHPUnit\Framework\TestCase; use Nice\Router\ContainerAwareControllerResolver; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -class ContainerAwareControllerResolverTest extends \PHPUnit_Framework_TestCase +class ContainerAwareControllerResolverTest extends TestCase { /** * Test that the ContainerAwareControllerResolver properly injects the container diff --git a/tests/Router/DispatcherFactory/GroupCountBasedFactoryTest.php b/tests/Router/DispatcherFactory/GroupCountBasedFactoryTest.php index 2b5ef8e..45231bc 100644 --- a/tests/Router/DispatcherFactory/GroupCountBasedFactoryTest.php +++ b/tests/Router/DispatcherFactory/GroupCountBasedFactoryTest.php @@ -9,9 +9,10 @@ namespace Nice\Tests\Router\DispatcherFactory; +use PHPUnit\Framework\TestCase; use Nice\Router\DispatcherFactory\GroupCountBasedFactory; -class GroupCountBasedFactoryTest extends \PHPUnit_Framework_TestCase +class GroupCountBasedFactoryTest extends TestCase { /** * Test Dispatcher creation diff --git a/tests/Router/NamedDataGenerator/HandlerWrapperGeneratorTest.php b/tests/Router/NamedDataGenerator/HandlerWrapperGeneratorTest.php index c700cf5..a3a6fec 100644 --- a/tests/Router/NamedDataGenerator/HandlerWrapperGeneratorTest.php +++ b/tests/Router/NamedDataGenerator/HandlerWrapperGeneratorTest.php @@ -10,9 +10,10 @@ namespace Nice\Tests\Router\NamedDataGenerator; use FastRoute\DataGenerator; +use PHPUnit\Framework\TestCase; use Nice\Router\NamedDataGenerator\HandlerWrapperGenerator; -class HandlerWrapperGeneratorTest extends \PHPUnit_Framework_TestCase +class HandlerWrapperGeneratorTest extends TestCase { /** * Tests addRoute functionality diff --git a/tests/Router/RouteCollector/CachedCollectorTest.php b/tests/Router/RouteCollector/CachedCollectorTest.php index 9aaad87..062ff8d 100644 --- a/tests/Router/RouteCollector/CachedCollectorTest.php +++ b/tests/Router/RouteCollector/CachedCollectorTest.php @@ -9,9 +9,10 @@ namespace Nice\Tests\Router\RouteCollector; +use PHPUnit\Framework\TestCase; use Nice\Router\RouteCollector\CachedCollector; -class CachedCollectorTest extends \PHPUnit_Framework_TestCase +class CachedCollectorTest extends TestCase { /** * Test basic caching @@ -50,7 +51,8 @@ public function testUnableToWriteCache() { $collector = $this->getCollector('/some/unwriteable/path'); - $this->setExpectedException('RuntimeException', 'Failed to create'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Failed to create'); $collector->getData(); } diff --git a/tests/Router/RouteCollector/SimpleCollectorTest.php b/tests/Router/RouteCollector/SimpleCollectorTest.php index 24da7b3..1ec442c 100644 --- a/tests/Router/RouteCollector/SimpleCollectorTest.php +++ b/tests/Router/RouteCollector/SimpleCollectorTest.php @@ -9,17 +9,18 @@ namespace Nice\Tests\Router\RouteCollector; +use PHPUnit\Framework\TestCase; use Nice\Router\RouteCollector\SimpleCollector; -class SimpleCollectorTest extends \PHPUnit_Framework_TestCase +class SimpleCollectorTest extends TestCase { /** * Test basic functionality */ public function testFunctionality() { - $parser = $this->getMock('FastRoute\RouteParser'); - $generator = $this->getMock('FastRoute\DataGenerator'); + $parser = $this->getMockForAbstractClass('FastRoute\RouteParser'); + $generator = $this->getMockForAbstractClass('FastRoute\DataGenerator'); $called = false; diff --git a/tests/Router/RouteCollectorTest.php b/tests/Router/RouteCollectorTest.php index 3b0c1db..569aea4 100644 --- a/tests/Router/RouteCollectorTest.php +++ b/tests/Router/RouteCollectorTest.php @@ -9,16 +9,17 @@ namespace Nice\Tests\Router\RouteCollector; +use PHPUnit\Framework\TestCase; use Nice\Router\RouteCollector; -class RouteCollectorTest extends \PHPUnit_Framework_TestCase +class RouteCollectorTest extends TestCase { /** * Test basic functionality */ public function testFunctionality() { - $parser = $this->getMock('FastRoute\RouteParser'); + $parser = $this->getMockForAbstractClass('FastRoute\RouteParser'); $parser->expects($this->exactly(7))->method('parse') ->will($this->returnCallback(function($route) { return array($route); @@ -38,7 +39,7 @@ public function testFunctionality() */ public function testExceptionIfNotNamedDataGenerator() { - $parser = $this->getMock('FastRoute\RouteParser'); + $parser = $this->getMockForAbstractClass('FastRoute\RouteParser'); $parser->expects($this->atLeastOnce()) ->method('parse') ->will($this->returnValue(array())); @@ -46,7 +47,8 @@ public function testExceptionIfNotNamedDataGenerator() $collector = new ConcreteRouteCollector($parser, $generator); - $this->setExpectedException('RuntimeException', 'The injected generator does not support named routes'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('The injected generator does not support named routes'); $collector->getData(); } diff --git a/tests/Router/RouterSubscriberTest.php b/tests/Router/RouterSubscriberTest.php index 1c212d2..d0d2db5 100644 --- a/tests/Router/RouterSubscriberTest.php +++ b/tests/Router/RouterSubscriberTest.php @@ -9,13 +9,14 @@ namespace Nice\Tests\Router; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Nice\Router\RouterSubscriber; use Symfony\Component\HttpKernel\KernelEvents; -class RouterSubscriberTest extends \PHPUnit_Framework_TestCase +class RouterSubscriberTest extends TestCase { /** * Test a Found route @@ -58,7 +59,7 @@ public function testMethodNotAllowed() $event = $this->getEvent($request); - $this->setExpectedException('Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException'); + $this->expectException('Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException'); $subscriber->onKernelRequest($event); } @@ -89,7 +90,7 @@ public function testNotFound() $event = $this->getEvent($request); - $this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); + $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); $subscriber->onKernelRequest($event); } @@ -122,11 +123,11 @@ private function getSubscriber() /** * @param Request $request * - * @return GetResponseEvent + * @return RequestEvent */ private function getEvent(Request $request) { - return new GetResponseEvent( + return new RequestEvent( $this->getMockForAbstractClass('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST diff --git a/tests/Router/UrlGenerator/CachedDataGeneratorTest.php b/tests/Router/UrlGenerator/CachedDataGeneratorTest.php index 77030a3..38698c2 100644 --- a/tests/Router/UrlGenerator/CachedDataGeneratorTest.php +++ b/tests/Router/UrlGenerator/CachedDataGeneratorTest.php @@ -9,9 +9,10 @@ namespace Nice\Tests\Router\UrlGenerator; +use PHPUnit\Framework\TestCase; use Nice\Router\UrlGenerator\CachedDataGenerator; -class CachedDataGeneratorTest extends \PHPUnit_Framework_TestCase +class CachedDataGeneratorTest extends TestCase { /** * Test basic caching @@ -50,7 +51,8 @@ public function testUnableToWriteCache() { $generator = $this->getGenerator('/some/unwriteable/path'); - $this->setExpectedException('RuntimeException', 'Failed to create'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Failed to create'); $generator->getData(); } diff --git a/tests/Router/UrlGenerator/GroupCountBasedDataGeneratorTest.php b/tests/Router/UrlGenerator/GroupCountBasedDataGeneratorTest.php index 9021ccd..563bf7d 100644 --- a/tests/Router/UrlGenerator/GroupCountBasedDataGeneratorTest.php +++ b/tests/Router/UrlGenerator/GroupCountBasedDataGeneratorTest.php @@ -9,9 +9,10 @@ namespace Nice\Tests\Router\UrlGenerator; +use PHPUnit\Framework\TestCase; use Nice\Router\UrlGenerator\GroupCountBasedDataGenerator; -class GroupCountBasedDataGeneratorTest extends \PHPUnit_Framework_TestCase +class GroupCountBasedDataGeneratorTest extends TestCase { /** * Test basic functionality diff --git a/tests/Router/UrlGenerator/SimpleUrlGeneratorTest.php b/tests/Router/UrlGenerator/SimpleUrlGeneratorTest.php index 2d7738b..4d2a434 100644 --- a/tests/Router/UrlGenerator/SimpleUrlGeneratorTest.php +++ b/tests/Router/UrlGenerator/SimpleUrlGeneratorTest.php @@ -9,10 +9,11 @@ namespace Nice\Tests\Router\UrlGenerator; +use PHPUnit\Framework\TestCase; use Nice\Router\UrlGenerator\SimpleUrlGenerator; use Symfony\Component\HttpFoundation\Request; -class SimpleUrlGeneratorTest extends \PHPUnit_Framework_TestCase +class SimpleUrlGeneratorTest extends TestCase { /** * Test basic functionality @@ -87,7 +88,8 @@ public function testDynamicRouteWithMissingParameter() ), )); - $this->setExpectedException('RuntimeException', 'Missing required parameter'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('Missing required parameter'); $this->assertEquals('/user/123/edit', $generator->generate('user_edit')); } diff --git a/tests/Router/WrappedHandlerSubscriberTest.php b/tests/Router/WrappedHandlerSubscriberTest.php index 2d0e376..a4ee8f1 100644 --- a/tests/Router/WrappedHandlerSubscriberTest.php +++ b/tests/Router/WrappedHandlerSubscriberTest.php @@ -9,13 +9,14 @@ namespace Nice\Tests\Router; +use PHPUnit\Framework\TestCase; use Nice\Router\WrappedHandlerSubscriber; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; -class WrappedHandlerSubscriberTest extends \PHPUnit_Framework_TestCase +class WrappedHandlerSubscriberTest extends TestCase { /** * Tests basic functionality @@ -57,11 +58,11 @@ private function getSubscriber() /** * @param Request $request * - * @return GetResponseEvent + * @return RequestEvent */ private function getEvent(Request $request) { - return new GetResponseEvent( + return new RequestEvent( $this->getMockForAbstractClass('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST diff --git a/tests/Session/SessionSubscriberTest.php b/tests/Session/SessionSubscriberTest.php index 90f8002..553f13e 100644 --- a/tests/Session/SessionSubscriberTest.php +++ b/tests/Session/SessionSubscriberTest.php @@ -9,16 +9,17 @@ namespace Nice\Tests\Session; +use PHPUnit\Framework\TestCase; use Nice\Session\SessionSubscriber; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; -class SessionSubscriberTest extends \PHPUnit_Framework_TestCase +class SessionSubscriberTest extends TestCase { /** * Test a Master request @@ -53,7 +54,10 @@ public function testSubRequestDoesNotInjectSession() $subscriber->onKernelRequest($event); - $this->assertEmpty($request->getSession()); + $this->expectException('Symfony\Component\HttpFoundation\Exception\SessionNotFoundException'); + $this->expectExceptionMessage('Session has not been set.'); + + $request->getSession(); } /** @@ -69,7 +73,10 @@ public function testNoSessionDoesNotInject() $subscriber->onKernelRequest($event); - $this->assertEmpty($request->getSession()); + $this->expectException('Symfony\Component\HttpFoundation\Exception\SessionNotFoundException'); + $this->expectExceptionMessage('Session has not been set.'); + + $request->getSession(); } /** @@ -105,11 +112,11 @@ public function testGetSubscribedEvents() /** * @param Request $request * - * @return GetResponseEvent + * @return RequestEvent */ private function getEvent(Request $request, $type = HttpKernelInterface::MASTER_REQUEST) { - return new GetResponseEvent( + return new RequestEvent( $this->getMockForAbstractClass('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, $type