Skip to content

Commit

Permalink
Merge branch 'master' into feature/tests-php82
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-93 committed Jul 4, 2023
2 parents 186b4ee + bcee50e commit dc2a726
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.* export-ignore
Tests export-ignore
phpunit export-ignore
phpunit.xml.dist export-ignore
4 changes: 1 addition & 3 deletions Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ private function doDump(InputInterface $input, OutputInterface $output): void

$output->writeln('<info>[file+]</info> '.$targetPath);

$baseUrl = null !== $this->requestContextBaseUrl ?
$this->requestContextBaseUrl :
$this->extractor->getBaseUrl()
$baseUrl = $this->requestContextBaseUrl ?? $this->extractor->getBaseUrl()
;

if ($input->getOption('pretty-print')) {
Expand Down
7 changes: 3 additions & 4 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
* Controller class.
Expand Down Expand Up @@ -82,9 +82,8 @@ public function indexAction(Request $request, $_format): Response
$content = $this->serializer->serialize($routesResponse, 'json');

if (null !== $callback = $request->query->get('callback')) {
$validator = new \JsonpCallbackValidator();
if (!$validator->validate($callback)) {
throw new HttpException(400, 'Invalid JSONP callback value');
if (!\JsonpCallbackValidator::validate($callback)) {
throw new BadRequestHttpException('Invalid JSONP callback value');
}

$content = '/**/'.$callback.'('.$content.');';
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/FOSJsRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setParameter(
'fos_js_routing.request_context_base_url',
$config['request_context_base_url'] ? $config['request_context_base_url'] : null
$config['request_context_base_url'] ?: null
);

if (isset($config['cache_control'])) {
Expand Down
2 changes: 1 addition & 1 deletion Extractor/ExposedRoutesExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected function getDomainByRouteMatches($matches, $name): int|string|null

$matches = array_flip(array_intersect_key($matches, array_flip($this->availableDomains)));

return isset($matches[$name]) ? $matches[$name] : null;
return $matches[$name] ?? null;
}

protected function extractDomainPatterns($routesToExpose): array
Expand Down
3 changes: 3 additions & 0 deletions Resources/js/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
router.test.js export-ignore
router_test.html export-ignore
run_jsunit.js export-ignore
5 changes: 5 additions & 0 deletions Serializer/Denormalizer/RouteCollectionDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public function supportsDenormalization(mixed $data, string $type, string $forma

return true;
}

public function getSupportedTypes(?string $format): array
{
return ['*' => false];
}
}
5 changes: 5 additions & 0 deletions Serializer/Normalizer/RouteCollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof RouteCollection;
}

public function getSupportedTypes(?string $format): array
{
return [RouteCollection::class => true];
}
}
5 changes: 5 additions & 0 deletions Serializer/Normalizer/RoutesResponseNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof RoutesResponse;
}

public function getSupportedTypes(?string $format): array
{
return [RoutesResponse::class => true];
}
}
9 changes: 6 additions & 3 deletions Tests/Command/DumpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use FOS\JsRoutingBundle\Command\DumpCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Routing\Router;
use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor;

class DumpCommandTest extends TestCase
{
Expand All @@ -25,15 +28,15 @@ class DumpCommandTest extends TestCase

public function setUp(): void
{
$this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor')
$this->extractor = $this->getMockBuilder(ExposedRoutesExtractor::class)
->disableOriginalConstructor()
->getMock();

$this->router = $this->getMockBuilder('Symfony\Component\Routing\Router')
$this->router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();

$this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')
$this->serializer = $this->getMockBuilder(SerializerInterface::class)
->disableOriginalConstructor()
->getMock();
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/Command/RouterDebugExposedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router;
use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor;

class RouterDebugExposedCommandTest extends TestCase
{
Expand All @@ -26,11 +28,11 @@ class RouterDebugExposedCommandTest extends TestCase

public function setUp(): void
{
$this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor')
$this->extractor = $this->getMockBuilder(ExposedRoutesExtractor::class)
->disableOriginalConstructor()
->getMock();

$this->router = $this->getMockBuilder('Symfony\Component\Routing\Router')
$this->router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();
}
Expand Down
13 changes: 7 additions & 6 deletions Tests/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Serializer;
use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface;

class ControllerTest extends TestCase
{
private $cachePath;
private string $cachePath;

public function setUp(): void
{
Expand Down Expand Up @@ -119,7 +120,7 @@ public function testGenerateWithCallback($callback): void
);
}

public static function dataProviderForTestGenerateWithCallback()
public static function dataProviderForTestGenerateWithCallback(): array
{
return [
['fos.Router.data'],
Expand Down Expand Up @@ -223,7 +224,7 @@ private function getExtractor(RouteCollection $exposedRoutes = null, $baseUrl =
$exposedRoutes = new RouteCollection();
}

$extractor = $this->getMockBuilder('FOS\\JsRoutingBundle\\Extractor\\ExposedRoutesExtractorInterface')->getMock();
$extractor = $this->getMockBuilder(ExposedRoutesExtractorInterface::class)->getMock();
$extractor
->expects($this->any())
->method('getRoutes')
Expand Down Expand Up @@ -258,9 +259,9 @@ private function getExtractor(RouteCollection $exposedRoutes = null, $baseUrl =
return $extractor;
}

private function getSerializer()
private function getSerializer(): Serializer
{
if (!class_exists('Symfony\\Component\\Serializer\\Serializer')) {
if (!class_exists(Serializer::class)) {
$this->markTestSkipped('The Serializer component is not available.');
}

Expand All @@ -273,7 +274,7 @@ private function getSerializer()
]);
}

private function getRequest($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
private function getRequest($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null): Request
{
return Request::create($uri, $method, $parameters, $cookies, $files, $server, $content);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/FOSJsRoutingExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FOSJsRoutingExtensionTest extends TestCase
{
public function setUp(): void
{
if (!class_exists('Symfony\Component\DependencyInjection\ContainerBuilder')) {
if (!class_exists(ContainerBuilder::class)) {
$this->markTestSkipped('The DependencyInjection component is not available.');
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testLoadSetupsSerializerIfNotGiven(): void
$this->assertEquals('{"foo":"bar"}', $serializer->serialize(['foo' => 'bar'], 'json'));
}

private function load(array $configs)
private function load(array $configs): ContainerBuilder
{
$container = new ContainerBuilder();

Expand Down
24 changes: 10 additions & 14 deletions Tests/Extractor/ExposedRoutesExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router;

/**
* ExposedRoutesExtractorTest class.
Expand All @@ -26,11 +27,11 @@
*/
class ExposedRoutesExtractorTest extends TestCase
{
private $cacheDir;
private string $cacheDir;

public function setUp(): void
{
if (!class_exists('Symfony\\Component\\Routing\\Route')) {
if (!class_exists(Route::class)) {
$this->markTestSkipped('The Routing component is not available.');
}

Expand Down Expand Up @@ -85,7 +86,7 @@ public function testGetRoutesWithPatterns(): void

public function testGetCachePath(): void
{
$router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router')
$router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -100,7 +101,7 @@ public function testGetHostOverHttp($host, $httpPort, $expected): void
{
$requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'http', $httpPort);

$router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router')
$router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();
$router->expects($this->atLeastOnce())
Expand All @@ -115,7 +116,7 @@ public function testGetHostOverHttp($host, $httpPort, $expected): void
/**
* @return array
*/
public function provideTestGetHostOverHttp()
public function provideTestGetHostOverHttp(): array
{
return [
'HTTP Standard' => ['127.0.0.1', 80, '127.0.0.1'],
Expand All @@ -130,7 +131,7 @@ public function testGetHostOverHttps($host, $httpsPort, $expected): void
{
$requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'https', 80, $httpsPort);

$router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router')
$router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();
$router->expects($this->atLeastOnce())
Expand Down Expand Up @@ -167,10 +168,7 @@ public function testExposeFalse(): void
}
}

/**
* @return array
*/
public function provideTestGetHostOverHttps()
public function provideTestGetHostOverHttps(): array
{
return [
'HTTPS Standard' => ['127.0.0.1', 443, '127.0.0.1'],
Expand All @@ -180,12 +178,10 @@ public function provideTestGetHostOverHttps()

/**
* Get a mock object which represents a Router.
*
* @return \Symfony\Component\Routing\Router
*/
private function getRouter(RouteCollection $routes)
private function getRouter(RouteCollection $routes): \Symfony\Component\Routing\Router
{
$router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router')
$router = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();
$router
Expand Down
7 changes: 4 additions & 3 deletions Tests/Serializer/Normalizer/RouteCollectionNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCompiler;

/**
* Class RouteCollectionNormalizerTest.
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testNormalize(): void
'defaults' => [],
'requirements' => [],
'options' => [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
'compiler_class' => RouteCompiler::class,
],
'schemes' => [],
'methods' => [],
Expand All @@ -59,7 +60,7 @@ public function testNormalize(): void
'defaults' => [],
'requirements' => [],
'options' => [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
'compiler_class' => RouteCompiler::class,
],
'schemes' => [],
'methods' => [],
Expand All @@ -71,7 +72,7 @@ public function testNormalize(): void
'defaults' => [],
'requirements' => [],
'options' => [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
'compiler_class' => RouteCompiler::class,
],
'schemes' => [],
'methods' => [],
Expand Down
5 changes: 3 additions & 2 deletions Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
use FOS\JsRoutingBundle\Serializer\Normalizer\RouteCollectionNormalizer;
use FOS\JsRoutingBundle\Serializer\Normalizer\RoutesResponseNormalizer;
use PHPUnit\Framework\TestCase;
use FOS\JsRoutingBundle\Response\RoutesResponse;

class RoutesResponseNormalizerTest extends TestCase
{
public function testSupportsNormalization(): void
{
$normalizer = new RoutesResponseNormalizer(new RouteCollectionNormalizer());
$response = $this->getMockBuilder('FOS\JsRoutingBundle\Response\RoutesResponse')
$response = $this->getMockBuilder(RoutesResponse::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -33,7 +34,7 @@ public function testSupportsNormalization(): void
public function testNormalize(): void
{
$normalizer = new RoutesResponseNormalizer(new RouteCollectionNormalizer());
$response = $this->getMockBuilder('FOS\JsRoutingBundle\Response\RoutesResponse')
$response = $this->getMockBuilder(RoutesResponse::class)
->disableOriginalConstructor()
->getMock();

Expand Down
36 changes: 19 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="FOSJsRoutingBundle Test Suite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources/</directory>
<directory>./Tests/</directory>
<directory>./vendor/</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="./vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./Resources/</directory>
<directory>./Tests/</directory>
<directory>./vendor/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="FOSJsRoutingBundle Test Suite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit dc2a726

Please sign in to comment.