diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 000000000..c6e63a4e1 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,46 @@ +name: Build + +on: + pull_request: + push: + branches: + - "master" + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "7.4" + - "8.0" + + steps: + - uses: actions/checkout@v2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + ini-values: "memory_limit=-1, phar.readonly=0" + php-version: "${{ matrix.php-version }}" + + - name: Composer Cache Directory + id: composer-cache + uses: actions/cache@v1 + with: + path: ~/.composer + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: PHPUnit + run: ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 3d4ff050e..16e3a0c63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /phpunit.xml +/.phpunit.result.cache /vendor /build /composer.lock diff --git a/composer.json b/composer.json index b5c6ffe2c..7586d8479 100644 --- a/composer.json +++ b/composer.json @@ -17,38 +17,41 @@ "require": { "php": ">=7.1.3", "pimple/pimple": "^3.0", - "symfony/event-dispatcher": "^4.0", - "symfony/http-foundation": "^4.0", - "symfony/http-kernel": "^4.0", - "symfony/routing": "^4.0" + "symfony/event-dispatcher": "^5.3", + "symfony/http-foundation": "^5.3", + "symfony/http-kernel": "^5.3", + "symfony/routing": "^5.3", + "symfony/monolog-bridge": "^5.3", + "monolog/monolog": "^2.3" }, "require-dev": { - "symfony/asset": "^4.0", - "symfony/expression-language": "^4.0", - "symfony/security": "^4.0", - "symfony/config": "^4.0", - "symfony/form": "^4.0", - "symfony/browser-kit": "^4.0", - "symfony/css-selector": "^4.0", - "symfony/debug": "^4.0", - "symfony/dom-crawler": "^4.0", - "symfony/finder": "^4.0", - "symfony/intl": "^4.0", - "symfony/monolog-bridge": "^4.0", - "symfony/doctrine-bridge": "^4.0", - "symfony/options-resolver": "^4.0", - "symfony/phpunit-bridge": "^3.2", - "symfony/process": "^4.0", - "symfony/serializer": "^4.0", - "symfony/translation": "^4.0", - "symfony/twig-bridge": "^4.0", - "symfony/validator": "^4.0", - "symfony/var-dumper": "^4.0", + "phpunit/phpunit": "^9.5", + "symfony/asset": "^5.3", + "symfony/expression-language": "^5.3", + "symfony/security-core": "^5.3", + "symfony/security-csrf": "^5.3", + "symfony/security-http": "^5.3", + "symfony/security-guard": "^5.3", + "symfony/config": "^5.3", + "symfony/form": "^5.3", + "symfony/browser-kit": "^5.3", + "symfony/css-selector": "^5.3", + "symfony/error-handler": "^5.3", + "symfony/dom-crawler": "^5.3", + "symfony/finder": "^5.3", + "symfony/intl": "^5.3", + "symfony/doctrine-bridge": "^5.3", + "symfony/options-resolver": "^5.3", + "symfony/process": "^5.3", + "symfony/serializer": "^5.3", + "symfony/translation": "^5.3", + "symfony/twig-bridge": "^5.3", + "symfony/validator": "^5.3", + "symfony/var-dumper": "^5.3", "twig/twig": "^2.0", "doctrine/dbal": "^2.2", - "swiftmailer/swiftmailer": "^5", - "monolog/monolog": "^1.4.1", - "symfony/web-link": "^4.0" + "swiftmailer/swiftmailer": "^6", + "symfony/web-link": "^5.3" }, "replace": { "silex/api": "self.version", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 799f16c90..706c16d27 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php" > diff --git a/src/Silex/Application.php b/src/Silex/Application.php index b1125d0df..640982cf5 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -15,11 +15,11 @@ use Pimple\ServiceProviderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpFoundation\Request; @@ -65,6 +65,7 @@ public function __construct(array $values = []) $this['debug'] = false; $this['charset'] = 'UTF-8'; $this['logger'] = null; + $this['psr_container'] = new \Pimple\Psr11\Container($this); $this->register(new HttpKernelServiceProvider()); $this->register(new RoutingServiceProvider()); @@ -246,8 +247,8 @@ public function before($callback, $priority = 0) { $app = $this; - $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($callback, $app) { - if (!$event->isMasterRequest()) { + $this->on(KernelEvents::REQUEST, function (RequestEvent $event) use ($callback, $app) { + if (!$event->isMainRequest()) { return; } @@ -272,8 +273,8 @@ public function after($callback, $priority = 0) { $app = $this; - $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($callback, $app) { - if (!$event->isMasterRequest()) { + $this->on(KernelEvents::RESPONSE, function (ResponseEvent $event) use ($callback, $app) { + if (!$event->isMainRequest()) { return; } @@ -299,7 +300,7 @@ public function finish($callback, $priority = 0) { $app = $this; - $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($callback, $app) { + $this->on(KernelEvents::TERMINATE, function (TerminateEvent $event) use ($callback, $app) { call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app); }, $priority); } @@ -485,7 +486,7 @@ public function run(Request $request = null) * If you call this method directly instead of run(), you must call the * terminate() method yourself if you want the finish filters to be run. */ - public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) + public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = true) { if (!$this->booted) { $this->boot(); diff --git a/src/Silex/Application/TranslationTrait.php b/src/Silex/Application/TranslationTrait.php index ad5a4f031..8b3299a5d 100644 --- a/src/Silex/Application/TranslationTrait.php +++ b/src/Silex/Application/TranslationTrait.php @@ -32,20 +32,4 @@ public function trans($id, array $parameters = [], $domain = 'messages', $locale { return $this['translator']->trans($id, $parameters, $domain, $locale); } - - /** - * Translates the given choice message by choosing a translation according to a number. - * - * @param string $id The message id - * @param int $number The number to use to find the indice of the message - * @param array $parameters An array of parameters for the message - * @param string $domain The domain for the message - * @param string $locale The locale - * - * @return string The translated string - */ - public function transChoice($id, $number, array $parameters = [], $domain = 'messages', $locale = null) - { - return $this['translator']->transChoice($id, $number, $parameters, $domain, $locale); - } } diff --git a/src/Silex/EventListener/ConverterListener.php b/src/Silex/EventListener/ConverterListener.php index dfb2d5c19..4e76c9811 100644 --- a/src/Silex/EventListener/ConverterListener.php +++ b/src/Silex/EventListener/ConverterListener.php @@ -13,7 +13,7 @@ use Silex\CallbackResolver; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\RouteCollection; @@ -42,9 +42,9 @@ public function __construct(RouteCollection $routes, CallbackResolver $callbackR /** * Handles converters. * - * @param FilterControllerEvent $event The event to handle + * @param ControllerEvent $event The event to handle */ - public function onKernelController(FilterControllerEvent $event) + public function onKernelController(ControllerEvent $event) { $request = $event->getRequest(); $route = $this->routes->get($request->attributes->get('_route')); diff --git a/src/Silex/EventListener/LogListener.php b/src/Silex/EventListener/LogListener.php index 39c1b1120..386e4684e 100644 --- a/src/Silex/EventListener/LogListener.php +++ b/src/Silex/EventListener/LogListener.php @@ -14,9 +14,9 @@ use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpFoundation\Request; @@ -50,11 +50,11 @@ public function __construct(LoggerInterface $logger, $exceptionLogFilter = null) /** * Logs master requests on event KernelEvents::REQUEST. * - * @param GetResponseEvent $event + * @param RequestEvent $event */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } @@ -64,9 +64,9 @@ public function onKernelRequest(GetResponseEvent $event) /** * Logs master response on event KernelEvents::RESPONSE. * - * @param FilterResponseEvent $event + * @param ResponseEvent $event */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(ResponseEvent $event) { if (!$event->isMasterRequest()) { return; @@ -78,11 +78,11 @@ public function onKernelResponse(FilterResponseEvent $event) /** * Logs uncaught exceptions on event KernelEvents::EXCEPTION. * - * @param GetResponseForExceptionEvent $event + * @param ExceptionEvent $event */ - public function onKernelException(GetResponseForExceptionEvent $event) + public function onKernelException(ExceptionEvent $event) { - $this->logException($event->getException()); + $this->logException($event->getThrowable()); } /** @@ -114,7 +114,7 @@ protected function logResponse(Response $response) /** * Logs an exception. */ - protected function logException(\Exception $e) + protected function logException(\Throwable $e) { $this->logger->log(call_user_func($this->exceptionLogFilter, $e), sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e]); } diff --git a/src/Silex/EventListener/MiddlewareListener.php b/src/Silex/EventListener/MiddlewareListener.php index 32ab4cb83..a8ab0225d 100644 --- a/src/Silex/EventListener/MiddlewareListener.php +++ b/src/Silex/EventListener/MiddlewareListener.php @@ -11,9 +11,9 @@ namespace Silex\EventListener; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Silex\Application; @@ -40,9 +40,9 @@ public function __construct(Application $app) /** * Runs before filters. * - * @param GetResponseEvent $event The event to handle + * @param RequestEvent $event The event to handle */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { $request = $event->getRequest(); $routeName = $request->attributes->get('_route'); @@ -65,13 +65,13 @@ public function onKernelRequest(GetResponseEvent $event) /** * Runs after filters. * - * @param FilterResponseEvent $event The event to handle + * @param ResponseEvent $event The event to handle */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(ResponseEvent $event) { $request = $event->getRequest(); $routeName = $request->attributes->get('_route'); - if (!$route = $this->app['routes']->get($routeName)) { + if (!$route = $this->app['routes']->get((string) $routeName)) { return; } diff --git a/src/Silex/EventListener/StringToResponseListener.php b/src/Silex/EventListener/StringToResponseListener.php index 5b93b2164..8289ca954 100644 --- a/src/Silex/EventListener/StringToResponseListener.php +++ b/src/Silex/EventListener/StringToResponseListener.php @@ -12,7 +12,7 @@ namespace Silex\EventListener; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; @@ -26,9 +26,9 @@ class StringToResponseListener implements EventSubscriberInterface /** * Handles string responses. * - * @param GetResponseForControllerResultEvent $event The event to handle + * @param ViewEvent $event The event to handle */ - public function onKernelView(GetResponseForControllerResultEvent $event) + public function onKernelView(ViewEvent $event) { $response = $event->getControllerResult(); diff --git a/src/Silex/ExceptionHandler.php b/src/Silex/ExceptionHandler.php index 0e2abc288..37789f958 100644 --- a/src/Silex/ExceptionHandler.php +++ b/src/Silex/ExceptionHandler.php @@ -11,11 +11,11 @@ namespace Silex; -use Symfony\Component\Debug\ExceptionHandler as DebugExceptionHandler; -use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; +use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -32,16 +32,17 @@ public function __construct($debug) $this->debug = $debug; } - public function onSilexError(GetResponseForExceptionEvent $event) + public function onSilexError(ExceptionEvent $event) { - $handler = new DebugExceptionHandler($this->debug); + $handler = new HtmlErrorRenderer($this->debug); - $exception = $event->getException(); + $exception = $event->getThrowable(); if (!$exception instanceof FlattenException) { - $exception = FlattenException::create($exception); + $exception = FlattenException::createFromThrowable($exception); } - $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset')); + $response = new Response($handler->getBody($exception), $exception->getStatusCode(), $exception->getHeaders()); + $response->setCharset(ini_get('default_charset')); $event->setResponse($response); } diff --git a/src/Silex/ExceptionListenerWrapper.php b/src/Silex/ExceptionListenerWrapper.php index d83170ebf..76b9a2f0c 100644 --- a/src/Silex/ExceptionListenerWrapper.php +++ b/src/Silex/ExceptionListenerWrapper.php @@ -14,8 +14,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Wraps exception listeners. @@ -39,9 +39,9 @@ public function __construct(Application $app, $callback) $this->callback = $callback; } - public function __invoke(GetResponseForExceptionEvent $event) + public function __invoke(ExceptionEvent $event) { - $exception = $event->getException(); + $exception = $event->getThrowable(); $this->callback = $this->app['callback_resolver']->resolveCallback($this->callback); if (!$this->shouldRun($exception)) { @@ -55,7 +55,7 @@ public function __invoke(GetResponseForExceptionEvent $event) $this->ensureResponse($response, $event); } - protected function shouldRun(\Exception $exception) + protected function shouldRun(\Throwable $exception) { if (is_array($this->callback)) { $callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]); @@ -69,21 +69,25 @@ protected function shouldRun(\Exception $exception) if ($callbackReflection->getNumberOfParameters() > 0) { $parameters = $callbackReflection->getParameters(); $expectedException = $parameters[0]; - if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) { - return false; + $exceptionParameterType = $expectedException->getType(); + if ($exceptionParameterType) { + $typeName = $exceptionParameterType->getName(); + if (!$exception instanceof $typeName) { + return false; + } } } return true; } - protected function ensureResponse($response, GetResponseForExceptionEvent $event) + protected function ensureResponse($response, ExceptionEvent $event) { if ($response instanceof Response) { $event->setResponse($response); } else { - $viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); - $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent); + $viewEvent = new ViewEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); + $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); if ($viewEvent->hasResponse()) { $event->setResponse($viewEvent->getResponse()); diff --git a/src/Silex/Provider/Form/SilexFormExtension.php b/src/Silex/Provider/Form/SilexFormExtension.php index 12efbdf23..df5b6e047 100644 --- a/src/Silex/Provider/Form/SilexFormExtension.php +++ b/src/Silex/Provider/Form/SilexFormExtension.php @@ -14,6 +14,7 @@ use Pimple\Container; use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\FormExtensionInterface; +use Symfony\Component\Form\FormTypeExtensionInterface; use Symfony\Component\Form\FormTypeGuesserChain; class SilexFormExtension implements FormExtensionInterface @@ -33,7 +34,7 @@ public function __construct(Container $app, array $types, array $typeExtensions, $this->setGuessers($guessers); } - public function getType($name) + public function getType(string $name) { if (!isset($this->types[$name])) { throw new InvalidArgumentException(sprintf('The type "%s" is not the name of a registered form type.', $name)); @@ -45,17 +46,17 @@ public function getType($name) return $this->types[$name]; } - public function hasType($name) + public function hasType(string $name) { return isset($this->types[$name]); } - public function getTypeExtensions($name) + public function getTypeExtensions(string $name) { return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : []; } - public function hasTypeExtensions($name) + public function hasTypeExtensions(string $name) { return isset($this->typeExtensions[$name]); } @@ -95,6 +96,9 @@ private function setTypes(array $types) } } + /** + * @param FormTypeExtensionInterface[] $typeExtensions + */ private function setTypeExtensions(array $typeExtensions) { $this->typeExtensions = []; @@ -105,7 +109,10 @@ private function setTypeExtensions(array $typeExtensions) } $extension = $this->app[$extension]; } - $this->typeExtensions[$extension->getExtendedType()][] = $extension; + + foreach ($extension::getExtendedTypes() as $type) { + $this->typeExtensions[$type][] = $extension; + } } } diff --git a/src/Silex/Provider/HttpFragmentServiceProvider.php b/src/Silex/Provider/HttpFragmentServiceProvider.php index 2c951cd09..e50427668 100644 --- a/src/Silex/Provider/HttpFragmentServiceProvider.php +++ b/src/Silex/Provider/HttpFragmentServiceProvider.php @@ -44,7 +44,7 @@ public function register(Container $app) }; $app['fragment.renderer.hinclude'] = function ($app) { - $renderer = new HIncludeFragmentRenderer(null, $app['uri_signer'], $app['fragment.renderer.hinclude.global_template'], $app['charset']); + $renderer = new HIncludeFragmentRenderer($app['twig'], $app['uri_signer'], $app['fragment.renderer.hinclude.global_template'], $app['charset']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; diff --git a/src/Silex/Provider/Locale/LocaleListener.php b/src/Silex/Provider/Locale/LocaleListener.php index 2463cc818..e94e9f967 100644 --- a/src/Silex/Provider/Locale/LocaleListener.php +++ b/src/Silex/Provider/Locale/LocaleListener.php @@ -12,7 +12,7 @@ namespace Silex\Provider\Locale; use Pimple\Container; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpFoundation\Request; @@ -41,7 +41,7 @@ public function __construct(Container $app, $defaultLocale = 'en', RequestStack $this->requestContext = $requestContext; } - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { $request = $event->getRequest(); $request->setDefaultLocale($this->defaultLocale); diff --git a/src/Silex/Provider/MonologServiceProvider.php b/src/Silex/Provider/MonologServiceProvider.php index 91552a69f..8aa208de9 100644 --- a/src/Silex/Provider/MonologServiceProvider.php +++ b/src/Silex/Provider/MonologServiceProvider.php @@ -11,6 +11,7 @@ namespace Silex\Provider; +use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Pimple\Container; use Pimple\ServiceProviderInterface; use Monolog\Formatter\LineFormatter; @@ -38,20 +39,16 @@ public function register(Container $app) return $app['monolog']; }; - if ($bridge = class_exists('Symfony\Bridge\Monolog\Logger')) { - if (isset($app['request_stack'])) { - $app['monolog.not_found_activation_strategy'] = function () use ($app) { - $level = MonologServiceProvider::translateLevel($app['monolog.level']); + if (isset($app['request_stack'])) { + $app['monolog.not_found_activation_strategy'] = function () use ($app) { + $level = MonologServiceProvider::translateLevel($app['monolog.level']); - return new NotFoundActivationStrategy($app['request_stack'], ['^/'], $level); - }; - } + return new NotFoundActivationStrategy($app['request_stack'], ['^/'], new ErrorLevelActivationStrategy($level)); + }; } - $app['monolog.logger.class'] = $bridge ? 'Symfony\Bridge\Monolog\Logger' : 'Monolog\Logger'; - - $app['monolog'] = function ($app) use ($bridge) { - $log = new $app['monolog.logger.class']($app['monolog.name']); + $app['monolog'] = function ($app) { + $log = new \Symfony\Bridge\Monolog\Logger($app['monolog.name']); $handler = new Handler\GroupHandler($app['monolog.handlers']); if (isset($app['monolog.not_found_activation_strategy'])) { @@ -60,7 +57,7 @@ public function register(Container $app) $log->pushHandler($handler); - if ($app['debug'] && $bridge) { + if ($app['debug']) { $log->pushProcessor(new DebugProcessor()); } diff --git a/src/Silex/Provider/SecurityServiceProvider.php b/src/Silex/Provider/SecurityServiceProvider.php index 08f21cd6b..f5075d8a2 100644 --- a/src/Silex/Provider/SecurityServiceProvider.php +++ b/src/Silex/Provider/SecurityServiceProvider.php @@ -20,12 +20,12 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RequestMatcher; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder; use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\User\UserChecker; use Symfony\Component\Security\Core\User\InMemoryUserProvider; use Symfony\Component\Security\Core\Encoder\EncoderFactory; use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; -use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder; use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder; use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider; use Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider; @@ -83,7 +83,6 @@ public function register(Container $app) $app['security.role_hierarchy'] = []; $app['security.access_rules'] = []; $app['security.hide_user_not_found'] = true; - $app['security.encoder.bcrypt.cost'] = 13; $app['security.authorization_checker'] = function ($app) { return new AuthorizationChecker($app['security.token_storage'], $app['security.authentication_manager'], $app['security.access_manager']); @@ -119,17 +118,17 @@ public function register(Container $app) ]); }; - // by default, all users use the BCrypt encoder + // by default, all users use the native encoder $app['security.default_encoder'] = function ($app) { - return $app['security.encoder.bcrypt']; + return $app['security.encoder.native']; }; $app['security.encoder.digest'] = function ($app) { return new MessageDigestPasswordEncoder(); }; - $app['security.encoder.bcrypt'] = function ($app) { - return new BCryptPasswordEncoder($app['security.encoder.bcrypt.cost']); + $app['security.encoder.native'] = function ($app) { + return new NativePasswordEncoder(); }; $app['security.encoder.pbkdf2'] = function ($app) { @@ -358,8 +357,7 @@ public function register(Container $app) $app['security.token_storage'], $app['security.access_manager'], $app['security.access_map'], - $app['security.authentication_manager'], - $app['logger'] + $app['security.authentication_manager'] ); }; diff --git a/src/Silex/Provider/Session/SessionListener.php b/src/Silex/Provider/Session/SessionListener.php index aba4c4e86..10e32ecd8 100644 --- a/src/Silex/Provider/Session/SessionListener.php +++ b/src/Silex/Provider/Session/SessionListener.php @@ -12,6 +12,7 @@ namespace Silex\Provider\Session; use Pimple\Container; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener; /** @@ -26,12 +27,13 @@ class SessionListener extends BaseSessionListener public function __construct(Container $app) { $this->app = $app; + parent::__construct($app['psr_container']); } - protected function getSession() + protected function getSession(): ?SessionInterface { if (!isset($this->app['session'])) { - return; + return null; } return $this->app['session']; diff --git a/src/Silex/Provider/Session/TestSessionListener.php b/src/Silex/Provider/Session/TestSessionListener.php index ab98eb12b..fbca08c0c 100644 --- a/src/Silex/Provider/Session/TestSessionListener.php +++ b/src/Silex/Provider/Session/TestSessionListener.php @@ -12,6 +12,7 @@ namespace Silex\Provider\Session; use Pimple\Container; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\EventListener\TestSessionListener as BaseTestSessionListener; /** @@ -26,12 +27,13 @@ class TestSessionListener extends BaseTestSessionListener public function __construct(Container $app) { $this->app = $app; + parent::__construct($app['psr_container']); } - protected function getSession() + protected function getSession(): ?SessionInterface { if (!isset($this->app['session'])) { - return; + return null; } return $this->app['session']; diff --git a/src/Silex/Provider/SwiftmailerServiceProvider.php b/src/Silex/Provider/SwiftmailerServiceProvider.php index 0cd3b35dc..a4d5991d0 100644 --- a/src/Silex/Provider/SwiftmailerServiceProvider.php +++ b/src/Silex/Provider/SwiftmailerServiceProvider.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; /** * Swiftmailer Provider. diff --git a/src/Silex/Provider/TranslationServiceProvider.php b/src/Silex/Provider/TranslationServiceProvider.php index 6f70c5d6f..21e33db0e 100644 --- a/src/Silex/Provider/TranslationServiceProvider.php +++ b/src/Silex/Provider/TranslationServiceProvider.php @@ -13,12 +13,12 @@ use Pimple\Container; use Pimple\ServiceProviderInterface; +use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\Formatter\MessageFormatter; use Symfony\Component\Translation\Loader\ArrayLoader; use Symfony\Component\Translation\Loader\XliffFileLoader; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\EventListener\TranslatorListener; use Silex\Api\EventListenerProviderInterface; /** @@ -72,7 +72,7 @@ public function register(Container $app) if (isset($app['request_stack'])) { $app['translator.listener'] = function ($app) { - return new TranslatorListener($app['translator'], $app['request_stack']); + return new LocaleAwareListener([$app['translator']], $app['request_stack']); }; } diff --git a/src/Silex/Provider/Twig/RuntimeLoader.php b/src/Silex/Provider/Twig/RuntimeLoader.php index 9a7aa915e..505baa399 100644 --- a/src/Silex/Provider/Twig/RuntimeLoader.php +++ b/src/Silex/Provider/Twig/RuntimeLoader.php @@ -12,13 +12,14 @@ namespace Silex\Provider\Twig; use Pimple\Container; +use Twig\RuntimeLoader\RuntimeLoaderInterface; /** * Loads Twig extension runtimes via Pimple. * * @author Fabien Potencier */ -class RuntimeLoader implements \Twig_RuntimeLoaderInterface +class RuntimeLoader implements RuntimeLoaderInterface { private $container; private $mapping; diff --git a/src/Silex/Provider/TwigServiceProvider.php b/src/Silex/Provider/TwigServiceProvider.php index 9b999e0ff..fa9aea23e 100644 --- a/src/Silex/Provider/TwigServiceProvider.php +++ b/src/Silex/Provider/TwigServiceProvider.php @@ -27,6 +27,13 @@ use Symfony\Bridge\Twig\Form\TwigRendererEngine; use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; use Symfony\Component\Form\FormRenderer; +use Symfony\Component\HttpFoundation\UrlHelper; +use Twig\Environment; +use Twig\Extension\CoreExtension; +use Twig\Extension\DebugExtension; +use Twig\Loader\ArrayLoader; +use Twig\Loader\ChainLoader; +use Twig\Loader\FilesystemLoader; /** * Twig integration for Silex. @@ -56,7 +63,7 @@ public function register(Container $app) // deprecated and should probably be removed in Silex 3.0 $twig->addGlobal('app', $app); - $coreExtension = $twig->getExtension('Twig_Extension_Core'); + $coreExtension = $twig->getExtension(CoreExtension::class); $coreExtension->setDateFormat($app['twig.date.format'], $app['twig.date.interval_format']); @@ -67,7 +74,7 @@ public function register(Container $app) $coreExtension->setNumberFormat($app['twig.number_format.decimals'], $app['twig.number_format.decimal_point'], $app['twig.number_format.thousands_separator']); if ($app['debug']) { - $twig->addExtension(new \Twig_Extension_Debug()); + $twig->addExtension(new DebugExtension()); } if (class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')) { @@ -87,7 +94,7 @@ public function register(Container $app) $twig->addGlobal('global', $app['twig.app_variable']); if (isset($app['request_stack'])) { - $twig->addExtension(new HttpFoundationExtension($app['request_stack'])); + $twig->addExtension(new HttpFoundationExtension(new UrlHelper($app['request_stack']))); $twig->addExtension(new RoutingExtension($app['url_generator'])); $twig->addExtension(new WebLinkExtension($app['request_stack'])); } @@ -101,9 +108,7 @@ public function register(Container $app) } if (isset($app['fragment.handler'])) { - $app['fragment.renderer.hinclude']->setTemplating($twig); - - $twig->addExtension(new HttpKernelExtension($app['fragment.handler'])); + $twig->addExtension(new HttpKernelExtension()); } if (isset($app['assets.packages'])) { @@ -126,7 +131,7 @@ public function register(Container $app) // add loader for Symfony built-in form templates $reflected = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension'); $path = dirname($reflected->getFileName()).'/../Resources/views/Form'; - $app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($path)); + $app['twig.loader']->addLoader(new FilesystemLoader($path)); } if (isset($app['var_dumper.cloner'])) { @@ -140,7 +145,7 @@ public function register(Container $app) }; $app['twig.loader.filesystem'] = function ($app) { - $loader = new \Twig_Loader_Filesystem(); + $loader = new FilesystemLoader(); foreach (is_array($app['twig.path']) ? $app['twig.path'] : [$app['twig.path']] as $key => $val) { if (is_string($key)) { $loader->addPath($key, $val); @@ -153,18 +158,18 @@ public function register(Container $app) }; $app['twig.loader.array'] = function ($app) { - return new \Twig_Loader_Array($app['twig.templates']); + return new ArrayLoader($app['twig.templates']); }; $app['twig.loader'] = function ($app) { - return new \Twig_Loader_Chain([ + return new ChainLoader([ $app['twig.loader.array'], $app['twig.loader.filesystem'], ]); }; $app['twig.environment_factory'] = $app->protect(function ($app) { - return new \Twig_Environment($app['twig.loader'], array_replace([ + return new Environment($app['twig.loader'], array_replace([ 'charset' => $app['charset'], 'debug' => $app['debug'], 'strict_variables' => $app['debug'], diff --git a/src/Silex/ViewListenerWrapper.php b/src/Silex/ViewListenerWrapper.php index a67ec938e..e13cdf749 100644 --- a/src/Silex/ViewListenerWrapper.php +++ b/src/Silex/ViewListenerWrapper.php @@ -12,7 +12,7 @@ namespace Silex; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Wraps view listeners. @@ -36,7 +36,7 @@ public function __construct(Application $app, $callback) $this->callback = $callback; } - public function __invoke(GetResponseForControllerResultEvent $event) + public function __invoke(ViewEvent $event) { $controllerResult = $event->getControllerResult(); $callback = $this->app['callback_resolver']->resolveCallback($this->callback); diff --git a/src/Silex/WebTestCase.php b/src/Silex/WebTestCase.php index 8580b79cf..290f6afea 100644 --- a/src/Silex/WebTestCase.php +++ b/src/Silex/WebTestCase.php @@ -12,7 +12,7 @@ namespace Silex; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpKernel\Client; +use Symfony\Component\HttpKernel\HttpKernelBrowser; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -35,7 +35,7 @@ abstract class WebTestCase extends TestCase * Note: Child classes that define a setUp method must call * parent::setUp(). */ - protected function setUp() + protected function setUp(): void { $this->app = $this->createApplication(); } @@ -52,14 +52,17 @@ abstract public function createApplication(); * * @param array $server Server parameters * - * @return Client A Client instance + * @return HttpKernelBrowser A Client instance */ public function createClient(array $server = []) { - if (!class_exists('Symfony\Component\BrowserKit\Client')) { + if (!class_exists('Symfony\Component\HttpKernel\HttpKernelBrowser')) { throw new \LogicException('Component "symfony/browser-kit" is required by WebTestCase.'.PHP_EOL.'Run composer require symfony/browser-kit'); } - return new Client($this->app, $server); + $this->app->boot(); + $this->app->flush(); + + return new HttpKernelBrowser($this->app['kernel'], $server); } } diff --git a/tests/Silex/Tests/Application/SecurityTraitTest.php b/tests/Silex/Tests/Application/SecurityTraitTest.php index 8918a100c..89fd75658 100644 --- a/tests/Silex/Tests/Application/SecurityTraitTest.php +++ b/tests/Silex/Tests/Application/SecurityTraitTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Silex\Provider\SecurityServiceProvider; -use Symfony\Component\Security\Core\User\User; +use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\HttpFoundation\Request; /** @@ -27,7 +27,7 @@ public function testEncodePassword() 'fabien' => ['ROLE_ADMIN', '$2y$15$lzUNsTegNXvZW3qtfucV0erYBcEqWVeyOmjolB7R1uodsAVJ95vvu'], ]); - $user = new User('foo', 'bar'); + $user = new InMemoryUser('foo', 'bar'); $password = 'foo'; $encoded = $app->encodePassword($user, $password); @@ -36,11 +36,10 @@ public function testEncodePassword() ); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException - */ public function testIsGrantedWithoutTokenThrowsException() { + $this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class); + $app = $this->createApplication(); $app->get('/', function () { return 'foo'; }); $app->handle(Request::create('/')); diff --git a/tests/Silex/Tests/Application/TranslationTraitTest.php b/tests/Silex/Tests/Application/TranslationTraitTest.php index ed4b5fe3e..9068444d1 100644 --- a/tests/Silex/Tests/Application/TranslationTraitTest.php +++ b/tests/Silex/Tests/Application/TranslationTraitTest.php @@ -27,14 +27,6 @@ public function testTrans() $app->trans('foo'); } - public function testTransChoice() - { - $app = $this->createApplication(); - $app['translator'] = $translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')->disableOriginalConstructor()->getMock(); - $translator->expects($this->once())->method('transChoice'); - $app->transChoice('foo', 2); - } - public function createApplication() { $app = new TranslationApplication(); diff --git a/tests/Silex/Tests/Application/TwigTraitTest.php b/tests/Silex/Tests/Application/TwigTraitTest.php index 753d92b79..79527eb3f 100644 --- a/tests/Silex/Tests/Application/TwigTraitTest.php +++ b/tests/Silex/Tests/Application/TwigTraitTest.php @@ -15,6 +15,7 @@ use Silex\Provider\TwigServiceProvider; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; +use Twig\Environment; /** * @author Fabien Potencier @@ -25,7 +26,7 @@ public function testRender() { $app = $this->createApplication(); - $app['twig'] = $mailer = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $app['twig'] = $mailer = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); $mailer->expects($this->once())->method('render')->will($this->returnValue('foo')); $response = $app->render('view'); @@ -37,7 +38,7 @@ public function testRenderKeepResponse() { $app = $this->createApplication(); - $app['twig'] = $mailer = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $app['twig'] = $mailer = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); $mailer->expects($this->once())->method('render')->will($this->returnValue('foo')); $response = $app->render('view', [], new Response('', 404)); @@ -48,7 +49,7 @@ public function testRenderForStream() { $app = $this->createApplication(); - $app['twig'] = $mailer = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $app['twig'] = $mailer = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); $mailer->expects($this->once())->method('display')->will($this->returnCallback(function () { echo 'foo'; })); $response = $app->render('view', [], new StreamedResponse()); @@ -63,7 +64,7 @@ public function testRenderView() { $app = $this->createApplication(); - $app['twig'] = $mailer = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $app['twig'] = $mailer = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); $mailer->expects($this->once())->method('render'); $app->renderView('view'); diff --git a/tests/Silex/Tests/ApplicationTest.php b/tests/Silex/Tests/ApplicationTest.php index ee6c804a5..fbcd9696f 100644 --- a/tests/Silex/Tests/ApplicationTest.php +++ b/tests/Silex/Tests/ApplicationTest.php @@ -11,8 +11,6 @@ namespace Silex\Tests; -use Fig\Link\GenericLinkProvider; -use Fig\Link\Link; use PHPUnit\Framework\TestCase; use Silex\Application; use Silex\ControllerCollection; @@ -23,8 +21,10 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\WebLink\GenericLinkProvider; +use Symfony\Component\WebLink\Link; +use Symfony\Contracts\EventDispatcher\Event; /** * Application test cases. @@ -133,11 +133,11 @@ public function testOn() $app = new Application(); $app['pass'] = false; - $app->on('test', function (Event $e) use ($app) { + $app->on(Event::class, function (Event $e) use ($app) { $app['pass'] = true; }); - $app['dispatcher']->dispatch('test'); + $app['dispatcher']->dispatch(new Event()); $this->assertTrue($app['pass']); } @@ -405,11 +405,10 @@ public function testFinishFilter() $this->assertSame(['1_routeTriggered', '2_filterAfter', '3_responseSent', '4_filterFinish'], $containerTarget); } - /** - * @expectedException \RuntimeException - */ public function testNonResponseAndNonNullReturnFromRouteBeforeMiddlewareShouldThrowRuntimeException() { + $this->expectException(\RuntimeException::class); + $app = new Application(); $middleware = function (Request $request) { @@ -424,11 +423,10 @@ public function testNonResponseAndNonNullReturnFromRouteBeforeMiddlewareShouldTh $app->handle(Request::create('/'), HttpKernelInterface::MASTER_REQUEST, false); } - /** - * @expectedException \RuntimeException - */ public function testNonResponseAndNonNullReturnFromRouteAfterMiddlewareShouldThrowRuntimeException() { + $this->expectException(\RuntimeException::class); + $app = new Application(); $middleware = function (Request $request) { @@ -487,22 +485,20 @@ public function testMountPreservesOrder() $this->assertEquals(['first', 'second', 'third'], array_keys(iterator_to_array($app['routes']))); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The "mount" method takes either a "ControllerCollection" instance, "ControllerProviderInterface" instance, or a callable. - */ public function testMountNullException() { + $this->expectException(\LogicException::class); + $this->expectErrorMessage('The "mount" method takes either a "ControllerCollection" instance, "ControllerProviderInterface" instance, or a callable.'); + $app = new Application(); $app->mount('/exception', null); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The method "Silex\Tests\IncorrectControllerCollection::connect" must return a "ControllerCollection" instance. Got: "NULL" - */ public function testMountWrongConnectReturnValueException() { + $this->expectException(\LogicException::class); + $this->expectErrorMessage('The method "Silex\Tests\IncorrectControllerCollection::connect" must return a "ControllerCollection" instance. Got: "NULL"'); + $app = new Application(); $app->mount('/exception', new IncorrectControllerCollection()); } @@ -528,12 +524,11 @@ public function testSendFile() $this->assertEquals(__FILE__, (string) $response->getFile()); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The "homepage" route must have code to run when it matches. - */ public function testGetRouteCollectionWithRouteWithoutController() { + $this->expectException(\LogicException::class); + $this->expectErrorMessage('The "homepage" route must have code to run when it matches.'); + $app = new Application(); unset($app['exception_handler']); $app->match('/')->bind('homepage'); diff --git a/tests/Silex/Tests/CallbackResolverTest.php b/tests/Silex/Tests/CallbackResolverTest.php index fc664759e..928561307 100644 --- a/tests/Silex/Tests/CallbackResolverTest.php +++ b/tests/Silex/Tests/CallbackResolverTest.php @@ -20,7 +20,7 @@ class CallbackResolverTest extends Testcase private $app; private $resolver; - public function setup() + public function setup(): void { $this->app = new Container(); $this->resolver = new CallbackResolver($this->app); @@ -61,12 +61,11 @@ public function nonStringsAreNotValidProvider() } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp /Service "[a-z_]+" is not callable./ * @dataProvider shouldThrowAnExceptionIfServiceIsNotCallableProvider */ public function testShouldThrowAnExceptionIfServiceIsNotCallable($name) { + $this->expectException(\InvalidArgumentException::class); $this->app['non_callable_obj'] = function () { return new \stdClass(); }; $this->app['non_callable'] = function () { return []; }; $this->resolver->convertCallback($name); diff --git a/tests/Silex/Tests/CallbackServicesTest.php b/tests/Silex/Tests/CallbackServicesTest.php index 2210977bb..697f8c1e8 100644 --- a/tests/Silex/Tests/CallbackServicesTest.php +++ b/tests/Silex/Tests/CallbackServicesTest.php @@ -15,6 +15,7 @@ use Silex\Application; use Symfony\Component\HttpFoundation\Request; use Silex\Provider\ServiceControllerServiceProvider; +use Symfony\Component\HttpKernel\KernelEvents; /** * Callback as services test cases. @@ -38,7 +39,7 @@ public function testCallbacksAsServices() $app->after('service:afterApp'); $app->finish('service:finishApp'); $app->error('service:error'); - $app->on('kernel.request', 'service:onRequest'); + $app->on(KernelEvents::REQUEST, 'service:onRequest'); $app ->match('/', 'service:controller') diff --git a/tests/Silex/Tests/ControllerCollectionTest.php b/tests/Silex/Tests/ControllerCollectionTest.php index 319ed7a34..73723e2a4 100644 --- a/tests/Silex/Tests/ControllerCollectionTest.php +++ b/tests/Silex/Tests/ControllerCollectionTest.php @@ -173,12 +173,11 @@ public function testMountControllersFactory() }); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The "mount" method takes either a "ControllerCollection" instance or callable. - */ public function testMountCallableException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The "mount" method takes either a "ControllerCollection" instance or callable.'); + $controllers = new ControllerCollection(new Route()); $controllers->mount('/prefix', ''); } @@ -285,11 +284,10 @@ public function testRouteExtension() $this->assertEquals('foo', $route->foo); } - /** - * @expectedException \BadMethodCallException - */ public function testRouteMethodDoesNotExist() { + $this->expectException(\BadMethodCallException::class); + $route = new MyRoute1(); $controller = new ControllerCollection($route); diff --git a/tests/Silex/Tests/ControllerTest.php b/tests/Silex/Tests/ControllerTest.php index ebf10b1ee..ecfff71de 100644 --- a/tests/Silex/Tests/ControllerTest.php +++ b/tests/Silex/Tests/ControllerTest.php @@ -31,11 +31,10 @@ public function testBind() $this->assertEquals('foo', $controller->getRouteName()); } - /** - * @expectedException \Silex\Exception\ControllerFrozenException - */ public function testBindOnFrozenControllerShouldThrowException() { + $this->expectException(\Silex\Exception\ControllerFrozenException::class); + $controller = new Controller(new Route('/foo')); $controller->bind('foo'); $controller->freeze(); @@ -110,11 +109,10 @@ public function testRouteExtension() $this->assertEquals('foo', $route->foo); } - /** - * @expectedException \BadMethodCallException - */ public function testRouteMethodDoesNotExist() { + $this->expectException(\BadMethodCallException::class); + $route = new MyRoute(); $controller = new Controller($route); diff --git a/tests/Silex/Tests/EventListener/LogListenerTest.php b/tests/Silex/Tests/EventListener/LogListenerTest.php index b56082e09..f079c224e 100644 --- a/tests/Silex/Tests/EventListener/LogListenerTest.php +++ b/tests/Silex/Tests/EventListener/LogListenerTest.php @@ -14,9 +14,9 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; use Silex\EventListener\LogListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; @@ -45,9 +45,9 @@ public function testRequestListener() $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->getMock(); - $dispatcher->dispatch(KernelEvents::REQUEST, new GetResponseEvent($kernel, Request::create('/subrequest'), HttpKernelInterface::SUB_REQUEST), 'Skip sub requests'); + $dispatcher->dispatch(new RequestEvent($kernel, Request::create('/subrequest'), HttpKernelInterface::SUB_REQUEST),KernelEvents::REQUEST); - $dispatcher->dispatch(KernelEvents::REQUEST, new GetResponseEvent($kernel, Request::create('/foo'), HttpKernelInterface::MASTER_REQUEST), 'Log master requests'); + $dispatcher->dispatch(new RequestEvent($kernel, Request::create('/foo'), HttpKernelInterface::MAIN_REQUEST), KernelEvents::REQUEST); } public function testResponseListener() @@ -64,23 +64,21 @@ public function testResponseListener() $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->getMock(); - $dispatcher->dispatch(KernelEvents::RESPONSE, new FilterResponseEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, Response::create('subrequest', 200)), 'Skip sub requests'); + $dispatcher->dispatch(new ResponseEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, Response::create('subrequest', 200)), KernelEvents::RESPONSE); - $dispatcher->dispatch(KernelEvents::RESPONSE, new FilterResponseEvent($kernel, Request::create('/foo'), HttpKernelInterface::MASTER_REQUEST, Response::create('bar', 301)), 'Log master requests'); + $dispatcher->dispatch(new ResponseEvent($kernel, Request::create('/foo'), HttpKernelInterface::MAIN_REQUEST, Response::create('bar', 301)), KernelEvents::RESPONSE); } public function testExceptionListener() { $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $logger - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('log') - ->with(LogLevel::CRITICAL, 'RuntimeException: Fatal error (uncaught exception) at '.__FILE__.' line '.(__LINE__ + 13)) - ; - $logger - ->expects($this->at(1)) - ->method('log') - ->with(LogLevel::ERROR, 'Symfony\Component\HttpKernel\Exception\HttpException: Http error (uncaught exception) at '.__FILE__.' line '.(__LINE__ + 9)) + ->withConsecutive( + [LogLevel::CRITICAL, 'RuntimeException: Fatal error (uncaught exception) at '.__FILE__.' line '.(__LINE__ + 10)], + [LogLevel::ERROR, 'Symfony\Component\HttpKernel\Exception\HttpException: Http error (uncaught exception) at '.__FILE__.' line '.(__LINE__ + 10)] + ) ; $dispatcher = new EventDispatcher(); @@ -88,7 +86,7 @@ public function testExceptionListener() $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->getMock(); - $dispatcher->dispatch(KernelEvents::EXCEPTION, new GetResponseForExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new \RuntimeException('Fatal error'))); - $dispatcher->dispatch(KernelEvents::EXCEPTION, new GetResponseForExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new HttpException(400, 'Http error'))); + $dispatcher->dispatch(new ExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new \RuntimeException('Fatal error')), KernelEvents::EXCEPTION); + $dispatcher->dispatch(new ExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new HttpException(400, 'Http error')), KernelEvents::EXCEPTION); } } diff --git a/tests/Silex/Tests/ExceptionHandlerTest.php b/tests/Silex/Tests/ExceptionHandlerTest.php index e5c43fbbf..72bf9221d 100644 --- a/tests/Silex/Tests/ExceptionHandlerTest.php +++ b/tests/Silex/Tests/ExceptionHandlerTest.php @@ -35,7 +35,7 @@ public function testExceptionHandlerExceptionNoDebug() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Whoops, looks like something went wrong.', $response->getContent()); + $this->assertStringContainsString('Something is broken. Please let us know what you were doing when this error occurred.', $response->getContent()); $this->assertEquals(500, $response->getStatusCode()); } @@ -51,7 +51,7 @@ public function testExceptionHandlerExceptionDebug() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('foo exception', $response->getContent()); + $this->assertStringContainsString('foo exception', $response->getContent()); $this->assertEquals(500, $response->getStatusCode()); } @@ -62,7 +62,7 @@ public function testExceptionHandlerNotFoundNoDebug() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Sorry, the page you are looking for could not be found.', $response->getContent()); + $this->assertStringContainsString('The server returned a "404 Not Found"', $response->getContent()); $this->assertEquals(404, $response->getStatusCode()); } @@ -73,7 +73,7 @@ public function testExceptionHandlerNotFoundDebug() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('No route found for "GET /foo"', html_entity_decode($response->getContent())); + $this->assertStringContainsString('No route found for "GET http://localhost/foo"', html_entity_decode($response->getContent())); $this->assertEquals(404, $response->getStatusCode()); } @@ -86,7 +86,7 @@ public function testExceptionHandlerMethodNotAllowedNoDebug() $request = Request::create('/foo', 'POST'); $response = $app->handle($request); - $this->assertContains('Whoops, looks like something went wrong.', $response->getContent()); + $this->assertStringContainsString('The server returned a "405 Method Not Allowed"', $response->getContent()); $this->assertEquals(405, $response->getStatusCode()); $this->assertEquals('GET', $response->headers->get('Allow')); } @@ -100,7 +100,7 @@ public function testExceptionHandlerMethodNotAllowedDebug() $request = Request::create('/foo', 'POST'); $response = $app->handle($request); - $this->assertContains('No route found for "POST /foo": Method Not Allowed (Allow: GET)', html_entity_decode($response->getContent())); + $this->assertStringContainsString('No route found for "POST http://localhost/foo": Method Not Allowed (Allow: GET)', html_entity_decode($response->getContent())); $this->assertEquals(405, $response->getStatusCode()); $this->assertEquals('GET', $response->headers->get('Allow')); } @@ -290,7 +290,7 @@ public function testExceptionHandlerWithDefaultException() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Exception thrown', $response->getContent()); + $this->assertStringContainsString('Exception thrown', $response->getContent()); $this->assertEquals(500, $response->getStatusCode()); } @@ -316,7 +316,7 @@ public function testExceptionHandlerWithStandardException() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Caught Exception', $response->getContent()); + $this->assertStringContainsString('Caught Exception', $response->getContent()); } public function testExceptionHandlerWithSpecifiedException() @@ -341,7 +341,7 @@ public function testExceptionHandlerWithSpecifiedException() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Caught LogicException', $response->getContent()); + $this->assertStringContainsString('Caught LogicException', $response->getContent()); } public function testExceptionHandlerWithSpecifiedExceptionInReverseOrder() @@ -368,7 +368,7 @@ public function testExceptionHandlerWithSpecifiedExceptionInReverseOrder() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Caught Exception', $response->getContent()); + $this->assertStringContainsString('Caught Exception', $response->getContent()); } public function testExceptionHandlerWithArrayStyleCallback() @@ -385,14 +385,14 @@ public function testExceptionHandlerWithArrayStyleCallback() $request = Request::create('/foo'); $response = $app->handle($request); - $this->assertContains('Caught Exception', $response->getContent()); + $this->assertStringContainsString('Caught Exception', $response->getContent()); } protected function checkRouteResponse($app, $path, $expectedContent, $method = 'get', $message = null) { $request = Request::create($path, $method); $response = $app->handle($request); - $this->assertEquals($expectedContent, $response->getContent(), $message); + $this->assertEquals($expectedContent, $response->getContent(), (string) $message); return $response; } diff --git a/tests/Silex/Tests/LazyRequestMatcherTest.php b/tests/Silex/Tests/LazyRequestMatcherTest.php index 879d46fac..5389bdc2f 100644 --- a/tests/Silex/Tests/LazyRequestMatcherTest.php +++ b/tests/Silex/Tests/LazyRequestMatcherTest.php @@ -42,12 +42,11 @@ public function testUserMatcherIsCreatedLazily() $this->assertEquals(1, $callCounter); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Factory supplied to LazyRequestMatcher must return implementation of Symfony\Component\Routing\RequestMatcherInterface. - */ public function testThatCanInjectRequestMatcherOnly() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Factory supplied to LazyRequestMatcher must return implementation of Symfony\Component\Routing\RequestMatcherInterface.'); + $matcher = new LazyRequestMatcher(function () { return 'someMatcher'; }); diff --git a/tests/Silex/Tests/Provider/FormServiceProviderTest.php b/tests/Silex/Tests/Provider/FormServiceProviderTest.php index dd4727133..374ea6687 100644 --- a/tests/Silex/Tests/Provider/FormServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/FormServiceProviderTest.php @@ -83,12 +83,11 @@ public function testFormServiceProviderWillLoadTypesServices() $this->assertInstanceOf('Symfony\Component\Form\Form', $form); } - /** - * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid form type. The silex service "dummy" does not exist. - */ public function testNonExistentTypeService() { + $this->expectException(\Symfony\Component\Form\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid form type. The silex service "dummy" does not exist.'); + $app = new Application(); $app->register(new FormServiceProvider()); @@ -147,12 +146,11 @@ public function testFormServiceProviderWillLoadTypeExtensionsServices() $this->assertInstanceOf('Symfony\Component\Form\Form', $form); } - /** - * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid form type extension. The silex service "dummy.form.type.extension" does not exist. - */ public function testNonExistentTypeExtensionService() { + $this->expectException(\Symfony\Component\Form\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid form type extension. The silex service "dummy.form.type.extension" does not exist.'); + $app = new Application(); $app->register(new FormServiceProvider()); @@ -202,12 +200,11 @@ public function testFormServiceProviderWillLoadTypeGuessersServices() $this->assertInstanceOf('Symfony\Component\Form\FormFactory', $app['form.factory']); } - /** - * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid form type guesser. The silex service "dummy.form.type.guesser" does not exist. - */ public function testNonExistentTypeGuesserService() { + $this->expectException(\Symfony\Component\Form\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid form type guesser. The silex service "dummy.form.type.guesser" does not exist.'); + $app = new Application(); $app->register(new FormServiceProvider()); @@ -250,10 +247,10 @@ public function testFormServiceProviderWillUseTranslatorIfAvailable() $this->assertFalse($form->isValid()); $r = new \ReflectionMethod($form, 'getErrors'); if (!$r->getNumberOfParameters()) { - $this->assertContains('ERROR: German translation', $form->getErrorsAsString()); + $this->assertStringContainsString('ERROR: German translation', $form->getErrorsAsString()); } else { // as of 2.5 - $this->assertContains('ERROR: German translation', (string) $form->getErrors(true, false)); + $this->assertStringContainsString('ERROR: German translation', (string) $form->getErrors(true, false)); } } @@ -318,9 +315,9 @@ class DummyFormType extends AbstractType class DummyFormTypeExtension extends AbstractTypeExtension { - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return 'Symfony\Component\Form\Extension\Core\Type\FileType'; + return ['Symfony\Component\Form\Extension\Core\Type\FileType']; } public function configureOptions(OptionsResolver $resolver) diff --git a/tests/Silex/Tests/Provider/FormServiceProviderTest/DisableCsrfExtension.php b/tests/Silex/Tests/Provider/FormServiceProviderTest/DisableCsrfExtension.php index ec55da1e9..a78966af4 100644 --- a/tests/Silex/Tests/Provider/FormServiceProviderTest/DisableCsrfExtension.php +++ b/tests/Silex/Tests/Provider/FormServiceProviderTest/DisableCsrfExtension.php @@ -15,8 +15,8 @@ public function configureOptions(OptionsResolver $resolver) ]); } - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return FormType::class; + return [FormType::class]; } } diff --git a/tests/Silex/Tests/Provider/MonologServiceProviderTest.php b/tests/Silex/Tests/Provider/MonologServiceProviderTest.php index 408fb1c16..0134f570f 100644 --- a/tests/Silex/Tests/Provider/MonologServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/MonologServiceProviderTest.php @@ -30,13 +30,13 @@ class MonologServiceProviderTest extends TestCase { private $currErrorHandler; - protected function setUp() + protected function setup(): void { $this->currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); } - protected function tearDown() + protected function tearDown(): void { set_error_handler($this->currErrorHandler); } @@ -58,7 +58,7 @@ public function testRequestLogging() $this->assertTrue($app['monolog.handler']->hasDebug('< 200')); $records = $app['monolog.handler']->getRecords(); - $this->assertContains('Matched route "{route}".', $records[0]['message']); + $this->assertStringContainsString('Matched route "{route}".', $records[0]['message']); $this->assertSame('GET_foo', $records[0]['context']['route']); } @@ -67,7 +67,7 @@ public function testManualLogging() $app = $this->getApplication(); $app->get('/log', function () use ($app) { - $app['monolog']->addDebug('logging a message'); + $app['monolog']->debug('logging a message'); }); $this->assertFalse($app['monolog.handler']->hasDebugRecords()); @@ -106,7 +106,7 @@ public function testErrorLogging() $request = Request::create('/error'); $app->handle($request); - $pattern = "#Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\NotFoundHttpException: No route found for \"GET /error\" \(uncaught exception\) at .* line \d+#"; + $pattern = "#Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\NotFoundHttpException: No route found for \"GET http:\/\/localhost\/error\" \(uncaught exception\) at .* line \d+#"; $this->assertMatchingRecord($pattern, Logger::ERROR, $app['monolog.handler']); /* @@ -174,12 +174,10 @@ public function testStringErrorLevel() $this->assertSame(Logger::INFO, $app['monolog.handler']->getLevel()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Provided logging level 'foo' does not exist. Must be a valid monolog logging level. - */ public function testNonExistentStringErrorLevel() { + $this->expectException(\InvalidArgumentException::class); + $app = $this->getApplication(); $app['monolog.level'] = 'foo'; diff --git a/tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php b/tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php index a673ac620..8729f47eb 100644 --- a/tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php @@ -16,7 +16,7 @@ use Silex\Provider\RememberMeServiceProvider; use Silex\Provider\SecurityServiceProvider; use Silex\Provider\SessionServiceProvider; -use Symfony\Component\HttpKernel\Client; +use Symfony\Component\HttpKernel\HttpKernelBrowser; use Symfony\Component\Security\Http\SecurityEvents; /** @@ -33,7 +33,10 @@ public function testRememberMeAuthentication() $interactiveLogin = new InteractiveLoginTriggered(); $app->on(SecurityEvents::INTERACTIVE_LOGIN, [$interactiveLogin, 'onInteractiveLogin']); - $client = new Client($app); + $app->boot(); + $app->flush(); + + $client = new HttpKernelBrowser($app); $client->request('get', '/'); $this->assertFalse($interactiveLogin->triggered, 'The interactive login has not been triggered yet'); diff --git a/tests/Silex/Tests/Provider/SecurityServiceProviderTest.php b/tests/Silex/Tests/Provider/SecurityServiceProviderTest.php index ccaa9aafd..ebd090c59 100644 --- a/tests/Silex/Tests/Provider/SecurityServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/SecurityServiceProviderTest.php @@ -18,7 +18,6 @@ use Silex\Provider\ValidatorServiceProvider; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AuthenticationException; -use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Request; /** @@ -28,11 +27,10 @@ */ class SecurityServiceProviderTest extends WebTestCase { - /** - * @expectedException \LogicException - */ public function testWrongAuthenticationType() { + $this->expectException(\LogicException::class); + $app = new Application(); $app->register(new SecurityServiceProvider(), [ 'security.firewalls' => [ @@ -48,15 +46,15 @@ public function testWrongAuthenticationType() public function testFormAuthentication() { - $app = $this->createApplication('form'); + $this->app = $app = $this->createApplication('form'); - $client = new Client($app); + $client = $this->createClient(); $client->request('get', '/'); $this->assertEquals('ANONYMOUS', $client->getResponse()->getContent()); $client->request('post', '/login_check', ['_username' => 'fabien', '_password' => 'bar']); - $this->assertContains('Bad credentials', $app['security.last_error']($client->getRequest())); + $this->assertStringContainsString('Bad credentials', $app['security.last_error']($client->getRequest())); // hack to re-close the session as the previous assertions re-opens it $client->getRequest()->getSession()->save(); @@ -97,8 +95,9 @@ public function testFormAuthentication() public function testHttpAuthentication() { $app = $this->createApplication('http'); + $this->app = $app; - $client = new Client($app); + $client = $this->createClient(); $client->request('get', '/'); $this->assertEquals(401, $client->getResponse()->getStatusCode()); @@ -124,8 +123,9 @@ public function testHttpAuthentication() public function testGuardAuthentication() { $app = $this->createApplication('guard'); + $this->app = $app; - $client = new Client($app); + $client = $this->createClient(); $client->request('get', '/'); $this->assertEquals(401, $client->getResponse()->getStatusCode(), 'The entry point is configured'); @@ -133,7 +133,7 @@ public function testGuardAuthentication() $client->request('get', '/', [], [], ['HTTP_X_AUTH_TOKEN' => 'lili:not the secret']); $this->assertEquals(403, $client->getResponse()->getStatusCode(), 'User not found'); - $this->assertEquals('{"message":"Username could not be found."}', $client->getResponse()->getContent()); + $this->assertEquals('{"message":"Invalid credentials."}', $client->getResponse()->getContent()); $client->request('get', '/', [], [], ['HTTP_X_AUTH_TOKEN' => 'victoria:not the secret']); $this->assertEquals(403, $client->getResponse()->getStatusCode(), 'Invalid credentials'); @@ -169,8 +169,9 @@ public function testExposedExceptions() { $app = $this->createApplication('form'); $app['security.hide_user_not_found'] = false; + $this->app = $app; - $client = new Client($app); + $client = $this->createClient(); $client->request('get', '/'); $this->assertEquals('ANONYMOUS', $client->getResponse()->getContent()); diff --git a/tests/Silex/Tests/Provider/SessionServiceProviderTest.php b/tests/Silex/Tests/Provider/SessionServiceProviderTest.php index 9c1e342b7..60d41a0e6 100644 --- a/tests/Silex/Tests/Provider/SessionServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/SessionServiceProviderTest.php @@ -14,8 +14,8 @@ use Silex\Application; use Silex\WebTestCase; use Silex\Provider\SessionServiceProvider; -use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Session; +use Symfony\Component\HttpKernel\HttpKernelBrowser; /** * SessionProvider test cases. @@ -92,7 +92,9 @@ public function testWithRoutesThatDoesNotUseSession() $app['debug'] = true; unset($app['exception_handler']); - $client = new Client($app); + $this->app = $app; + + $client = $this->createClient(); $client->request('get', '/'); $this->assertEquals('A welcome page.', $client->getResponse()->getContent()); diff --git a/tests/Silex/Tests/Provider/SpoolStub.php b/tests/Silex/Tests/Provider/SpoolStub.php index 753e5974e..87224fc5d 100644 --- a/tests/Silex/Tests/Provider/SpoolStub.php +++ b/tests/Silex/Tests/Provider/SpoolStub.php @@ -34,7 +34,7 @@ public function isStarted() return count($this->messages) > 0; } - public function queueMessage(\Swift_Mime_Message $message) + public function queueMessage(\Swift_Mime_SimpleMessage $message) { $this->messages[] = clone $message; } diff --git a/tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php b/tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php index 3dbf6b0cb..4d50850ce 100644 --- a/tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php @@ -56,7 +56,7 @@ public function testSwiftMailerSendsMailsOnFinish() }; $app->get('/', function () use ($app) { - $app['mailer']->send(\Swift_Message::newInstance()); + $app['mailer']->send(new \Swift_Message()); }); $this->assertCount(0, $app['swiftmailer.spool']->getMessages()); @@ -104,7 +104,7 @@ public function testSwiftMailerSenderAddress() $app['swiftmailer.sender_address'] = 'foo@example.com'; - $app['mailer']->send(\Swift_Message::newInstance()); + $app['mailer']->send(new \Swift_Message()); $messages = $app['swiftmailer.spool']->getMessages(); $this->assertCount(1, $messages); diff --git a/tests/Silex/Tests/Provider/TranslationServiceProviderTest.php b/tests/Silex/Tests/Provider/TranslationServiceProviderTest.php index 5c942a4d3..b61ce3983 100644 --- a/tests/Silex/Tests/Provider/TranslationServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/TranslationServiceProviderTest.php @@ -57,21 +57,6 @@ protected function getPreparedApp() return $app; } - public function transChoiceProvider() - { - return [ - ['key2', 0, null, '0 apples'], - ['key2', 1, null, 'One apple'], - ['key2', 2, null, '2 apples'], - ['key2', 0, 'de', '0 german apples'], - ['key2', 1, 'de', 'One german apple'], - ['key2', 2, 'de', '2 german apples'], - ['key2', 0, 'ru', '0 apples'], // fallback - ['key2', 1, 'ru', 'One apple'], // fallback - ['key2', 2, 'ru', '2 apples'], // fallback - ]; - } - public function transProvider() { return [ @@ -96,17 +81,6 @@ public function testTransForDefaultLanguage($key, $locale, $expected) $this->assertEquals($expected, $result); } - /** - * @dataProvider transChoiceProvider - */ - public function testTransChoiceForDefaultLanguage($key, $number, $locale, $expected) - { - $app = $this->getPreparedApp(); - - $result = $app['translator']->transChoice($key, $number, ['%count%' => $number], null, $locale); - $this->assertEquals($expected, $result); - } - public function testFallbacks() { $app = $this->getPreparedApp(); diff --git a/tests/Silex/Tests/Provider/TwigServiceProviderTest.php b/tests/Silex/Tests/Provider/TwigServiceProviderTest.php index 852dcebe4..309cc3b54 100644 --- a/tests/Silex/Tests/Provider/TwigServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/TwigServiceProviderTest.php @@ -11,7 +11,6 @@ namespace Silex\Tests\Provider; -use Fig\Link\Link; use PHPUnit\Framework\TestCase; use Silex\Application; use Silex\Provider\CsrfServiceProvider; @@ -19,6 +18,9 @@ use Silex\Provider\TwigServiceProvider; use Silex\Provider\AssetServiceProvider; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\WebLink\Link; +use Twig\Environment; +use Twig\Loader\LoaderInterface; /** * TwigProvider test cases. @@ -50,8 +52,8 @@ public function testLoaderPriority() $app->register(new TwigServiceProvider(), [ 'twig.templates' => ['foo' => 'foo'], ]); - $loader = $this->getMockBuilder('\Twig_LoaderInterface')->getMock(); - if (method_exists('\Twig_LoaderInterface', 'getSourceContext')) { + $loader = $this->getMockBuilder(LoaderInterface::class)->getMock(); + if (method_exists(LoaderInterface::class, 'getSourceContext')) { $loader->expects($this->never())->method('getSourceContext'); } $app['twig.loader.filesystem'] = function ($app) use ($loader) { @@ -107,7 +109,7 @@ public function testFormFactory() $app->register(new CsrfServiceProvider()); $app->register(new TwigServiceProvider()); - $this->assertInstanceOf('Twig_Environment', $app['twig']); + $this->assertInstanceOf(Environment::class, $app['twig']); $this->assertInstanceOf('Symfony\Bridge\Twig\Form\TwigRendererEngine', $app['twig.form.engine']); $this->assertInstanceOf('Symfony\Component\Form\FormRenderer', $app['twig.form.renderer']); } @@ -118,7 +120,7 @@ public function testFormWithoutCsrf() $app->register(new FormServiceProvider()); $app->register(new TwigServiceProvider()); - $this->assertInstanceOf('Twig_Environment', $app['twig']); + $this->assertInstanceOf(Environment::class, $app['twig']); } public function testFormatParameters() diff --git a/tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php b/tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php index 832abb3c5..4dbf1df0c 100644 --- a/tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php @@ -201,6 +201,6 @@ public function testTranslatorResourcesIsArray() $app->register(new ValidatorServiceProvider()); $app->register(new TranslationServiceProvider()); - $this->assertInternalType('array', $app['translator.resources']); + $this->assertIsArray($app['translator.resources']); } } diff --git a/tests/Silex/Tests/RouterTest.php b/tests/Silex/Tests/RouterTest.php index 5cf8cce32..10e8a565b 100644 --- a/tests/Silex/Tests/RouterTest.php +++ b/tests/Silex/Tests/RouterTest.php @@ -95,11 +95,10 @@ public function testRedirect() $this->assertTrue($response->isRedirect('/target2')); } - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - */ public function testMissingRoute() { + $this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class); + $app = new Application(); unset($app['exception_handler']); @@ -164,7 +163,7 @@ public function testRequestShouldBeStoredRegardlessOfRouting() foreach (['/foo', '/bar'] as $path) { $request = Request::create($path); $response = $app->handle($request); - $this->assertContains($path, $response->getContent()); + $this->assertStringContainsString($path, $response->getContent()); } } @@ -268,7 +267,7 @@ protected function checkRouteResponse(Application $app, $path, $expectedContent, { $request = Request::create($path, $method); $response = $app->handle($request); - $this->assertEquals($expectedContent, $response->getContent(), $message); + $this->assertEquals($expectedContent, $response->getContent(), (string) $message); } } diff --git a/tests/Silex/Tests/ServiceControllerResolverRouterTest.php b/tests/Silex/Tests/ServiceControllerResolverRouterTest.php index 4bc88a451..8417adab9 100644 --- a/tests/Silex/Tests/ServiceControllerResolverRouterTest.php +++ b/tests/Silex/Tests/ServiceControllerResolverRouterTest.php @@ -38,6 +38,6 @@ protected function checkRouteResponse(Application $app, $path, $expectedContent, { $request = Request::create($path, $method); $response = $app->handle($request); - $this->assertEquals($expectedContent, $response->getContent(), $message); + $this->assertEquals($expectedContent, $response->getContent(), (string) $message); } } diff --git a/tests/Silex/Tests/ServiceControllerResolverTest.php b/tests/Silex/Tests/ServiceControllerResolverTest.php index f5e446954..8337127d1 100644 --- a/tests/Silex/Tests/ServiceControllerResolverTest.php +++ b/tests/Silex/Tests/ServiceControllerResolverTest.php @@ -27,7 +27,7 @@ class ServiceControllerResolverTest extends Testcase private $mockResolver; private $resolver; - public function setup() + public function setup(): void { $this->mockResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface') ->disableOriginalConstructor() diff --git a/tests/Silex/Tests/WebTestCaseTest.php b/tests/Silex/Tests/WebTestCaseTest.php index a5961ae30..b246c9387 100644 --- a/tests/Silex/Tests/WebTestCaseTest.php +++ b/tests/Silex/Tests/WebTestCaseTest.php @@ -14,6 +14,7 @@ use Silex\Application; use Silex\WebTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * Functional test cases. @@ -27,18 +28,18 @@ public function createApplication() $app = new Application(); $app->match('/hello', function () { - return 'world'; + return new Response('world'); }); $app->match('/html', function () { - return '

title

'; + return new Response('

title

'); }); $app->match('/server', function (Request $request) use ($app) { $user = $request->server->get('PHP_AUTH_USER'); $pass = $request->server->get('PHP_AUTH_PW'); - return "

$user:$pass

"; + return new Response("

$user:$pass

"); }); return $app;