diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bdbeb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +/composer.lock +/phpunit.xml +/.phpunit.result.cache + +/var/ +/vendor/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8b0c751..82e0235 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,6 @@ cache: directories: - $HOME/.composer/cache/files - $HOME/symfony-bridge/.phpunit - - -git: - clone: false - env: global: - PHPUNIT_FLAGS="-v" @@ -18,37 +13,17 @@ env: matrix: fast_finish: true include: - # Test the latest stable release + # Test the 3.4 LTS release - php: 7.2 + env: SYMFONY="3.4.*" - php: 7.3 - env: SYMFONY=">=5.0-stable" - - # Latest commit to master - - php: 7.3 - env: SYMFONY=">=5.0-dev" - - allow_failures: - # Dev-master is allowed to fail. - - env: SYMFONY=">=5.0-dev" - -before_install: - - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - - if ! [ -z "$SYMFONY" ]; then composer create-project symfony/website-skeleton:$SYMFONY symfony; fi - - if [ -z "$SYMFONY" ]; then composer create-project symfony/website-skeleton symfony; fi - - cd symfony - - composer config repositories.xactsystems vcs https://github.com/XactSystems/js-routing-bundle.git --no-interaction - # Does not work for private repos, needs SSH key or other auth - - composer require xactsystems/js-routing-bundle:dev-$TRAVIS_BRANCH --no-interaction - - cat vendor/composer/autoload_psr4.php - #- git clone --depth=50 --branch=$TRAVIS_BRANCH https://github.com/XactSystems/js-routing-bundle.git XactSystems/js-routing-bundle + env: SYMFONY="3.4.*" install: - - ls -al vendor/xactsystems - - cp -p vendor/xactsystems/js-routing-bundle/phpunit.xml.dist . - - ./vendor/bin/simple-phpunit install + - travis_retry composer install --no-interaction --prefer-dist script: - #- composer validate --strict --no-check-lock # simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and # it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge) + - export SYMFONY_DEPRECATIONS_HELPER=disabled - ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS diff --git a/Controller/RoutingController.php b/Controller/RoutingController.php deleted file mode 100644 index f1ba588..0000000 --- a/Controller/RoutingController.php +++ /dev/null @@ -1,43 +0,0 @@ -extractor = $extractor; - } - - /** - * Return the exposed routes as JSON - * This method does not have a route and is called directly from the twig template - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function routingData(SerializerInterface $serializer) : JsonResponse - { - $routes = $this->extractor->getRoutes(); - return JsonResponse::fromJsonString($serializer->serialize($routes, self::JSON_FORMAT)); - } -} - diff --git a/DependencyInjection/XactJSRoutingExtension.php b/DependencyInjection/XactJSRoutingExtension.php deleted file mode 100644 index e6fcb36..0000000 --- a/DependencyInjection/XactJSRoutingExtension.php +++ /dev/null @@ -1,31 +0,0 @@ -load('services.yaml'); - } - - public function prepend(ContainerBuilder $container) - { - $fileSystem = new Filesystem(); - $projectDir = $container->getParameter('kernel.project_dir'); - $templateDir = $fileSystem->makePathRelative(__DIR__ . '/../Resources/templates/', $projectDir); - - $twigConfig = []; - $twigConfig['paths'][$templateDir] = "XactJSRouting"; - $container->prependExtensionConfig('twig', $twigConfig); - } -} - diff --git a/Extractor/ExtractedRoute.php b/Extractor/ExtractedRoute.php deleted file mode 100644 index 8d24fc6..0000000 --- a/Extractor/ExtractedRoute.php +++ /dev/null @@ -1,119 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -class ExtractedRoute -{ - /** - * @var array - */ - private $tokens; - /** - * @var array - */ - private $defaults; - /** - * @var array - */ - private $requirements; - /** - * @var array - */ - private $hosttokens; - /** - * @var array - */ - private $methods; - /** - * @var array - */ - private $schemes; - - /** - * Constructor - * - * @param array $tokens - * @param array $defaults - * @param array $requirements - * @param array $hosttokens - * @param array $methods - * @param array $schemes - */ - public function __construct(array $tokens, array $defaults, array $requirements, array $hosttokens = [], array $methods = [], array $schemes = []) - { - $this->tokens = $tokens; - $this->defaults = $defaults; - $this->requirements = $requirements; - $this->hosttokens = $hosttokens; - $this->methods = $methods; - $this->schemes = $schemes; - } - - /** - * Return the route tokens - * - * @return array - */ - public function getTokens() - { - return $this->tokens; - } - - /** - * Return the route defaults - * - * @return array - */ - public function getDefaults() - { - return $this->defaults; - } - - /** - * Return the route requirements - * - * @return array - */ - public function getRequirements() - { - return $this->requirements; - } - - /** - * Return the route host tokens - * - * @return array - */ - public function getHosttokens() - { - return $this->hosttokens; - } - - /** - * Return the route methods - * - * @return array - */ - public function getMethods() - { - return $this->methods; - } - - /** - * Return the route schemes - * - * @return array - */ - public function getSchemes() - { - return $this->schemes; - } -} diff --git a/README.md b/README.md index 653fce6..95b9d6b 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,41 @@ XactJSRoutingBundle =============== -This bundle allows you to expose your Symfony routes and use them in your webpack managed JavaScript code. -It allows you to easily intergrate the functionality of the FOSJsRoutingBundle into webpack modules. +This bundle allows you to expose your Symfony routes and use them in your webpack or vite managed JavaScript code. +It allows you to easily integrate the functionality of the FOSJsRoutingBundle into ES modules. Documentation ------------- ### 1) Add JSRoutingBundle to your project ```bash -composer require XactSystems/js-routing-bundle +composer require xactsystems/js-routing-bundle +``` +For Symfony 3.4 use: +```bash +composer require xactsystems/js-routing-bundle:^3.4 ``` ### 2) Include the routing template in your base Twig template ```twig // templates/base.html.twig -{{ include("@XactJSRouting/js-routing.html.twig") }} +{{ include("@XactJSRouting/xact-routing.html.twig") }} ``` ### 3) Include the JS module in your App.js +The package installation will automatically update your package.json file to import xact-routing module. +After running composer, run: +```bash +npm install +``` +Add routing to your App.js file, and/or other scripts as required: ```javascript // assets/js/App.js -// Import the JS routing scripts -import '../../vendor/ianfoulds/js-routing/assets/js-routing.js'; +// Import the JS routing class +import Routing from 'xact-routing'; ``` -The actual path to the js-routing.js file may not be exactly as shown, you may need to adjust this for your own project. ### 4) Using the routing class, exactly as you would with FOS bundle ```javascript @@ -34,6 +43,25 @@ The actual path to the js-routing.js file may not be exactly as shown, you may n let url1 = Routing.generate('home'); let url2 = Routing.generate('some-other-route', {id: myLocalId, state: myLocalState}); ``` +### 5) For Symfony 3.4, if you are not using Flex and ENV you may need to add the following: +```php +// app/AppKernel.php + + public function registerBundles() + { + // You many need to do this to get the render(controller()) Twig method working for XactJSRoutingBundle + $_ENV["APP_ENV"] = $this->getEnvironment(); +``` +And for the Symfony Serializer component: +```yaml +// app/config/config.yml + +framework: + ... + # If you haven't already enabled the Symfony Serializer + serializer: { enabled: true } +``` + Credits ------- @@ -47,4 +75,4 @@ License This bundle is released under the MIT license. See the complete license in the bundle: -[LICENSE](https://github.com/ianfoulds/js-routing-bundle/blob/master/LICENSE) \ No newline at end of file +[LICENSE](https://github.com/ianfoulds/js-routing-bundle/blob/master/LICENSE) diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst deleted file mode 100644 index 49ab77e..0000000 --- a/Resources/doc/index.rst +++ /dev/null @@ -1,2 +0,0 @@ -JS Routing Documentation -======================== diff --git a/Resources/templates/js-routing.html.twig b/Resources/templates/js-routing.html.twig deleted file mode 100644 index 7d8c644..0000000 --- a/Resources/templates/js-routing.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -{% block js_routing %} -
-{% endblock %} diff --git a/XactJSRoutingBundle.php b/XactJSRoutingBundle.php deleted file mode 100644 index 972747c..0000000 --- a/XactJSRoutingBundle.php +++ /dev/null @@ -1,12 +0,0 @@ - { + route.hostTokens.forEach((token) => { let value; if ('text' === token[0]) { @@ -337,7 +329,7 @@ class Router { * tokens: (Array.>), * defaults: (Object.), * requirements: Object, - * hosttokens: (Array.) + * hostTokens: (Array.) * }} */ Router.Route; @@ -349,4 +341,4 @@ Router.Route; */ Router.Context; -module.exports = Router; \ No newline at end of file +export default Router; diff --git a/assets/xact-routing.js b/assets/xact-routing.js new file mode 100644 index 0000000..27eeef2 --- /dev/null +++ b/assets/xact-routing.js @@ -0,0 +1,27 @@ +/** + * Routing management service + */ +import Router from './router.js'; + +let routes = []; +let routesElement = document.getElementById('xact-js-routing-data'); +if(routesElement) { + routes = JSON.parse(routesElement.attributes['data-routing-data'].value); + routesElement.remove(); +} + +let context = { + scheme: window.location.protocol, + host: window.location.hostname, + port: window.location.port, + base_url: '', + routes: routes, +}; +if (window.location.pathname.startsWith('/app_dev.php')) { + context.base_url = '/app_dev.php'; +} + +let routing = new Router(); +routing.setRoutingData(context); + +export default routing; diff --git a/composer.json b/composer.json index cfdda9e..ba2d7d2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "xactsystems/js-routing-bundle", - "description": "A JS routing bundle for Symfony 4+ using webpack. Derived from the FOS JSRoutingBundle.", + "description": "A JS routing bundle for Symfony. Derived from the FOS JSRoutingBundle.", "type": "symfony-bundle", "license": "MIT", "authors": [ @@ -9,37 +9,42 @@ "email": "ianfoulds@x-act.co.uk" } ], - "extra": { - "branch-alias": { - "dev-master": "0.0.1-dev" - } - }, "autoload": { "psr-4": { - "Xact\\JSRoutingBundle\\": "" + "Xact\\JSRouting\\": "src/" } }, "autoload-dev": { "psr-4": { - "Xact\\JSRoutingBundle\\Tests\\": "Tests/" + "Xact\\JSRouting\\Tests\\": "tests/" } }, "minimum-stability": "dev", "require": { - "php": "^7.0", - "symfony/asset": "~3.4.* || ~4.0 || ~5.0", - "symfony/flex": "~1.3", - "symfony/form": "~4.0 || ~5.0", - "symfony/framework-bundle": "~4.0 || ~5.0", - "symfony/serializer-pack": "~1.0", - "symfony/twig-pack": "~1.0", - "symfony/webpack-encore-bundle": "^1.7", - "symfony/yaml": "~3.4.* || ~4.0 || ~5.0" + "php": ">=8.1", + "symfony/asset": "^6.4||^7.1", + "symfony/twig-bundle": "^6.4||^7.1", + "symfony/yaml": "*", + "symfony/serializer-pack": "^1.3", + "symfony/framework-bundle": "^6.4||^7.1", + "williarin/cook": "^1.3" }, "require-dev": { - "symfony/debug-pack": "*", - "symfony/maker-bundle": "^1.0", - "symfony/profiler-pack": "*", - "symfony/test-pack": "*" + "phpstan/extension-installer": "^1.4", + "phpstan/phpdoc-parser": "^1.29", + "phpstan/phpstan": "^1.11", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan-doctrine": "^1.5", + "phpstan/phpstan-symfony": "^1.4", + "slevomat/coding-standard": "^8.15", + "squizlabs/php_codesniffer": "^3.10", + "symfony/debug-bundle": "^7.1", + "symfony/phpunit-bridge": "^7.1" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/Resources/config/services.yaml b/config/services.yaml similarity index 53% rename from Resources/config/services.yaml rename to config/services.yaml index 4803fdc..7c76e9f 100644 --- a/Resources/config/services.yaml +++ b/config/services.yaml @@ -4,10 +4,14 @@ services: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. - Xact\JSRoutingBundle\: - resource: '../../*' - exclude: './{DependencyInjection,Resources,Tests,XactJSRoutingBundle.php}' + Xact\JSRouting\Controller\RoutingController: + public: true + tags: ['controller.service_arguments'] + bind: + $extractor: '@Xact\JSRouting\Extractor\RoutingExtractor' + $serializer: '@serializer' - Xact\JSRoutingBundle\Extractor\RoutingExtractor: + Xact\JSRouting\Extractor\RoutingExtractor: + $router: '@router' $cacheDir: '%kernel.cache_dir%' $appEnv: '%env(string:APP_ENV)%' diff --git a/cook.yaml b/cook.yaml new file mode 100644 index 0000000..1a5cb9c --- /dev/null +++ b/cook.yaml @@ -0,0 +1,22 @@ +files: + '%CONFIG_DIR%/bundles.php': + type: php_array + entries: + Xact\JSRouting\XactJSRoutingBundle: + dev: true + test: true + filters: + keys: [class_constant] + values: [single_line_array] + + '%ROOT_DIR%/package.json': + type: json + entries: + dependencies: + xact-routing: "file:vendor/xactsystems/js-routing-bundle/assets" + +post_install_output: | + + Your package.json file has been updated. + Please run 'npm install' to install the xact-routing module. + diff --git a/monolog.yaml b/monolog.yaml new file mode 100644 index 0000000..299948f --- /dev/null +++ b/monolog.yaml @@ -0,0 +1,13 @@ +monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + #excluded_http_codes: [404, 405] + excluded_404s: ~ + channels: ["!event"] + nested: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..f637fb0 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,120 @@ + + + A custom coding standard based on PSR12 + + + + + + + + vendor/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + config/bundles.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + config/ + public/ + src/ + tests/ + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0782d5a --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 9 + treatPhpDocTypesAsCertain: false + + paths: + - src + - tests diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9436890..4da2265 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,28 @@ - - + xsi:noNamespaceSchemaLocation="bin/.phpunit/phpunit.xsd" + bootstrap="vendor/autoload.php" + verbose="true" + backupGlobals="false" + colors="true"> + - + - - vendor/xactsystems/js-routing-bundle/Tests + + Tests - src + . diff --git a/src/Controller/RoutingController.php b/src/Controller/RoutingController.php new file mode 100644 index 0000000..98b23d8 --- /dev/null +++ b/src/Controller/RoutingController.php @@ -0,0 +1,31 @@ +extractor->getRoutes(); + return JsonResponse::fromJsonString($this->serializer->serialize($routes, self::JSON_FORMAT)); + } +} diff --git a/src/Extractor/ExtractedRoute.php b/src/Extractor/ExtractedRoute.php new file mode 100644 index 0000000..f452ca1 --- /dev/null +++ b/src/Extractor/ExtractedRoute.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +class ExtractedRoute +{ + /** + * Constructor + * + * @param string[] $tokens + * @param string[] $defaults + * @param string[] $requirements + * @param string[] $hostTokens + * @param string[] $methods + * @param string[] $schemes + */ + public function __construct( + private array $tokens, + private array $defaults, + private array $requirements, + private array $hostTokens = [], + private array $methods = [], + private array $schemes = [] + ) { + } + + /** + * @return string[] + */ + public function getTokens(): array + { + return $this->tokens; + } + + /** + * @return string[] + */ + public function getDefaults(): array + { + return $this->defaults; + } + + /** + * @return string[] + */ + public function getRequirements(): array + { + return $this->requirements; + } + + /** + * @return string[] + */ + public function getHostTokens(): array + { + return $this->hostTokens; + } + + /** + * @return string[] + */ + public function getMethods(): array + { + return $this->methods; + } + + /** + * @return string[] + */ + public function getSchemes(): array + { + return $this->schemes; + } +} diff --git a/Extractor/RoutingExtractor.php b/src/Extractor/RoutingExtractor.php similarity index 64% rename from Extractor/RoutingExtractor.php rename to src/Extractor/RoutingExtractor.php index 5126531..de5f70b 100644 --- a/Extractor/RoutingExtractor.php +++ b/src/Extractor/RoutingExtractor.php @@ -1,65 +1,42 @@ - * Dreived from the FOS routing bundle by William DURAND + * Derived from the FOS routing bundle by William DURAND */ class RoutingExtractor { /** - * @var RouterInterface - */ - protected $router; - - /** - * Base cache directory - * - * @var string - */ - protected $cacheDir; - - /** - * APP_ENV setting - * - * @var string - */ - protected $appEnv; - - /** - * Default constructor. - * - * @param RouterInterface $router - * @param string $cacheDir - * @param string $appEnv - * @param array $routesToExpose + * @param string[] $routesToExpose Array of routes names to expose */ - public function __construct(RouterInterface $router, $cacheDir, $appEnv, array $routesToExpose = []) - { - $this->router = $router; - $this->routesToExpose = $routesToExpose; - $this->cacheDir = $cacheDir; - $this->appEnv = $appEnv; + public function __construct( + protected RouterInterface $router, + protected string $cacheDir, + protected string $appEnv, + protected array $routesToExpose = [] + ) { } /** - * {@inheritDoc} + * @return array */ - public function getRoutes() + public function getRoutes(): array { $exposedRoutes = []; - /** @var Route $route */ foreach ($this->getExposedRoutes() as $name => $route) { // Maybe there is a better way to do that... $compiledRoute = $route->compile(); $defaults = array_intersect_key( $route->getDefaults(), - array_fill_keys($compiledRoute->getVariables(), NULL) + array_fill_keys($compiledRoute->getVariables(), null) ); $requirements = $route->getRequirements(); $hostTokens = method_exists($compiledRoute, 'getHostTokens') ? $compiledRoute->getHostTokens() : []; @@ -77,21 +54,23 @@ public function getRoutes() } /** - * {@inheritDoc} + * @return array */ - public function getExposedRoutes() + public function getExposedRoutes(): array { $routes = []; $collection = $this->router->getRouteCollection(); $pattern = $this->buildPattern(); foreach ($collection->all() as $name => $route) { - if (FALSE === $route->getOption('expose')) { + if (false === $route->getOption('expose')) { continue; } - if (($route->getOption('expose') && (TRUE === $route->getOption('expose') || 'true' === $route->getOption('expose'))) - || ('' !== $pattern && preg_match('#' . $pattern . '#', $name))) { + if ( + (true === $route->getOption('expose') || 'true' === $route->getOption('expose')) + || ('' !== $pattern && preg_match('#' . $pattern . '#', $name)) + ) { $routes[$name] = $route; } } @@ -99,18 +78,12 @@ public function getExposedRoutes() return $routes; } - /** - * {@inheritDoc} - */ - public function getBaseUrl() + public function getBaseUrl(): string { return $this->router->getContext()->getBaseUrl() ?: ''; } - /** - * {@inheritDoc} - */ - public function getHost() + public function getHost(): string { $requestContext = $this->router->getContext(); @@ -124,20 +97,7 @@ public function getHost() return $host; } - /** - * Check whether server is serving this request from a non-standard port. - * - * @return bool - */ - protected function usesNonStandardPort() - { - return $this->usesNonStandardHttpPort() || $this->usesNonStandardHttpsPort(); - } - - /** - * {@inheritDoc} - */ - public function getScheme() + public function getScheme(): string { return $this->router->getContext()->getScheme(); } @@ -145,7 +105,7 @@ public function getScheme() /** * {@inheritDoc} */ - public function getCachePath() + public function getCachePath(): string { $cachePath = $this->cacheDir . DIRECTORY_SEPARATOR . 'AppJsRouting'; if (!file_exists($cachePath)) { @@ -158,19 +118,25 @@ public function getCachePath() } /** - * {@inheritDoc} + * @return ResourceInterface[] */ - public function getResources() + public function getResources(): array { return $this->router->getRouteCollection()->getResources(); } + /** + * Check whether server is serving this request from a non-standard port. + */ + protected function usesNonStandardPort(): bool + { + return $this->usesNonStandardHttpPort() || $this->usesNonStandardHttpsPort(); + } + /** * Convert the routesToExpose array in a regular expression pattern. - * - * @return string */ - protected function buildPattern() + protected function buildPattern(): string { $patterns = []; foreach ($this->routesToExpose as $toExpose) { @@ -182,20 +148,16 @@ protected function buildPattern() /** * Checks whether server is serving HTTP over a non-standard port. - * - * @return bool */ - private function usesNonStandardHttpPort() + private function usesNonStandardHttpPort(): bool { return 'http' === $this->getScheme() && '80' != $this->router->getContext()->getHttpPort(); } /** * Checks whether server is serving HTTPS over a non-standard port. - * - * @return bool */ - private function usesNonStandardHttpsPort() + private function usesNonStandardHttpsPort(): bool { return 'https' === $this->getScheme() && '443' != $this->router->getContext()->getHttpsPort(); } diff --git a/src/XactJSRoutingBundle.php b/src/XactJSRoutingBundle.php new file mode 100644 index 0000000..169d72e --- /dev/null +++ b/src/XactJSRoutingBundle.php @@ -0,0 +1,18 @@ +import('../config/services.yaml'); + } +} diff --git a/templates/xact-routing.html.twig b/templates/xact-routing.html.twig new file mode 100644 index 0000000..a265f2f --- /dev/null +++ b/templates/xact-routing.html.twig @@ -0,0 +1,3 @@ +{% block js_routing %} +
+{% endblock %} diff --git a/Tests/RoutesTest.php b/tests/RoutesTest.php similarity index 79% rename from Tests/RoutesTest.php rename to tests/RoutesTest.php index 13e5865..31c3565 100644 --- a/Tests/RoutesTest.php +++ b/tests/RoutesTest.php @@ -1,6 +1,8 @@ getParameter('kernel.cache_dir'); + $cacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir'); $appEnv = 'test'; $expectedRoutes = new RouteCollection(); $expectedRoutes->add('literal', new Route('/literal', [], [], ['expose' => true])); @@ -35,12 +43,12 @@ public function testExtractedRoutes() $router = $this->getRouter($expectedRoutes); $extractor = new RoutingExtractor($router, $cacheDir, $appEnv); - $controller = new RoutingController($extractor); + $controller = new RoutingController($extractor, $serializer); - $response = $controller->routingData($serializer); + $response = $controller->routingData(); $this->assertEquals(200, $response->getStatusCode()); - + $content = $response->getContent(); /** @var ExtractedRoute[] $decodedRoutes */ $decodedRoutes = $serializer->deserialize($content, ExtractedRoute::class . '[]', self::JSON_FORMAT); @@ -68,12 +76,18 @@ public function testExtractedRoutes() $this->assertArrayNotHasKey('paramValue', $p2Defaults); } + /** + * Configure the kernel class + */ + protected static function getKernelClass(): string + { + return TestKernel::class; + } + /** * Get a mock object which represents a Router - * - * @return \Symfony\Component\Routing\Router */ - private function getRouter(RouteCollection $routes) : MockObject + protected function getRouter(RouteCollection $routes): MockObject { $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() @@ -86,4 +100,3 @@ private function getRouter(RouteCollection $routes) : MockObject return $router; } } - diff --git a/tests/TestKernel.php b/tests/TestKernel.php new file mode 100644 index 0000000..50944ad --- /dev/null +++ b/tests/TestKernel.php @@ -0,0 +1,30 @@ +