Skip to content

Commit 8384d1d

Browse files
committed
fix deprecations and support sf 7
1 parent f06c5d0 commit 8384d1d

18 files changed

Lines changed: 192 additions & 269 deletions

‎composer.json‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
"license": "MIT",
2020
"require": {
2121
"php": "^8.0",
22-
"symfony/http-kernel": "^5.4 || ^6.0",
23-
"symfony/http-foundation": "^5.4 || ^6.0",
24-
"symfony/serializer": "^5.4 || ^6.0",
25-
"symfony/validator": "^5.4 || ^6.0",
26-
"symfony/dependency-injection": "^5.4 || ^6.0",
27-
"symfony/property-access": "^5.4 || ^6.0"
22+
"symfony/http-kernel": "^6.2 | ^7.0",
23+
"symfony/http-foundation": "^6.2 |^7.0",
24+
"symfony/serializer": "^6.2 |^7.0",
25+
"symfony/validator": "^6.2 |^7.0",
26+
"symfony/dependency-injection": "^6.2 |^7.0",
27+
"symfony/property-access": "^6.2 |^7.0"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^9.5",
31-
"symfony/framework-bundle": "^5.4 || ^6.0",
32-
"phpspec/prophecy-phpunit": "^2.0",
33-
"friendsofphp/php-cs-fixer": "^3.13",
30+
"phpunit/phpunit": "^10.0",
31+
"symfony/framework-bundle": "^6.2 | ^7.0",
32+
"friendsofphp/php-cs-fixer": "^3.5",
3433
"phpstan/phpstan": "^1.9"
3534
},
3635
"autoload": {

‎phpunit.xml.dist‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="vendor/autoload.php">
3-
<coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
3+
<testsuites>
4+
<testsuite name="RequestInputBundle for the Symfony Framework">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
49
<include>
510
<directory>.</directory>
611
</include>
712
<exclude>
813
<directory>./tests</directory>
914
<directory>./vendor</directory>
1015
</exclude>
11-
</coverage>
12-
<testsuites>
13-
<testsuite name="RequestInputBundle for the Symfony Framework">
14-
<directory>./tests</directory>
15-
</testsuite>
16-
</testsuites>
16+
</source>
1717
</phpunit>

‎src/ArgumentResolver/InputArgumentResolver.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/DependencyInjection/RequestInputExtension.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Sfmok\RequestInput\DependencyInjection;
66

7-
use Sfmok\RequestInput\ArgumentResolver\InputArgumentResolver;
87
use Sfmok\RequestInput\Factory\InputFactory;
98
use Sfmok\RequestInput\Factory\InputFactoryInterface;
109
use Sfmok\RequestInput\Metadata\InputMetadataFactory;
1110
use Sfmok\RequestInput\Metadata\InputMetadataFactoryInterface;
1211
use Sfmok\RequestInput\EventListener\ReadInputListener;
1312
use Sfmok\RequestInput\EventListener\ExceptionListener;
13+
use Sfmok\RequestInput\ValueResolver\InputValueResolver;
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Reference;
1616
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -46,7 +46,7 @@ public function load(array $configs, ContainerBuilder $container): void
4646
$container->setAlias(InputFactoryInterface::class, InputFactory::class)->setPublic(false);
4747
$container->setAlias(InputMetadataFactoryInterface::class, InputMetadataFactory::class)->setPublic(false);
4848

49-
$container->register(InputArgumentResolver::class)
49+
$container->register(InputValueResolver::class)
5050
->setArguments([
5151
'$inputFactory' => new Reference(InputFactoryInterface::class),
5252
])

‎src/EventListener/ExceptionListener.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function onKernelException(ExceptionEvent $event): void
2525
return;
2626
}
2727

28-
$headers = ['Content-Type' => 'application/problem+json; charset=utf-8'];
28+
$headers = ['Content-Type' => 'application/json; charset=utf-8'];
2929

3030
if ($exception instanceof ValidationException) {
3131
$event->setResponse(new Response(

‎src/Factory/InputFactory.php‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ public function __construct(
2727
) {
2828
}
2929

30-
public function createFromRequest(Request $request, string $type): InputInterface
30+
public function createFromRequest(Request $request, string $type): iterable
3131
{
32-
// @codeCoverageIgnoreStart
33-
if (\func_num_args() > 2) {
34-
@trigger_error("Third argument of 'InputFactory::createFromRequest' is not in use and is removed, however the argument in the callers code can be removed without side-effects.", \E_USER_DEPRECATED);
32+
if (!is_subclass_of($type, InputInterface::class)) {
33+
return [];
3534
}
36-
// @codeCoverageIgnoreEnd
3735

3836
$contentType = $request->headers->get('CONTENT_TYPE');
3937
if (null === $contentType || '' === $contentType) {
@@ -49,7 +47,7 @@ public function createFromRequest(Request $request, string $type): InputInterfac
4947
}
5048

5149
$data = $request->getContent();
52-
$format = $request->getContentType();
50+
$format = $request->getContentTypeFormat();
5351
if (Input::INPUT_FORM_FORMAT === $format) {
5452
$data = json_encode($request->request->all());
5553
$format = Input::INPUT_JSON_FORMAT;
@@ -70,14 +68,14 @@ public function createFromRequest(Request $request, string $type): InputInterfac
7068
}
7169
}
7270

73-
return $input;
71+
return [$input];
7472
}
7573

7674
private function getSupportedMimeTypes(Request $request, array $formats): array
7775
{
7876
$mimeTypes = [];
7977
foreach ($formats as $format) {
80-
$mimeTypes = [...$mimeTypes, ...$request->getMimeTypes($format)];
78+
$mimeTypes = array_merge($mimeTypes, $request->getMimeTypes($format));
8179
}
8280

8381
return $mimeTypes;

‎src/Factory/InputFactoryInterface.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
interface InputFactoryInterface
1111
{
12-
public function createFromRequest(Request $request, string $type): InputInterface;
12+
public function createFromRequest(Request $request, string $type): iterable;
1313
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sfmok\RequestInput\ValueResolver;
6+
7+
use Symfony\Component\HttpFoundation\Request;
8+
use Sfmok\RequestInput\Factory\InputFactoryInterface;
9+
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
10+
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
11+
12+
class InputValueResolver implements ValueResolverInterface
13+
{
14+
public function __construct(private InputFactoryInterface $inputFactory)
15+
{
16+
}
17+
18+
public function resolve(Request $request, ArgumentMetadata $argument): iterable
19+
{
20+
return $this->inputFactory->createFromRequest($request, $argument->getType());
21+
}
22+
}

‎tests/ArgumentResolver/InputArgumentResolverTest.php‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎tests/DependencyInjection/ConfigurationTest.php‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sfmok\RequestInput\Tests\DependencyInjection;
66

7+
use PHPUnit\Framework\Attributes\DataProvider;
78
use PHPUnit\Framework\TestCase;
89
use Sfmok\RequestInput\DependencyInjection\Configuration;
910
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -13,21 +14,13 @@
1314

1415
class ConfigurationTest extends TestCase
1516
{
16-
private Configuration $configuration;
17-
private Processor $processor;
18-
19-
protected function setUp(): void
20-
{
21-
$this->configuration = new Configuration();
22-
$this->processor = new Processor();
23-
}
24-
2517
public function testDefaultConfig(): void
2618
{
27-
$treeBuilder = $this->configuration->getConfigTreeBuilder();
28-
$config = $this->processor->processConfiguration($this->configuration, []);
19+
$configuration = new Configuration();
20+
$treeBuilder = $configuration->getConfigTreeBuilder();
21+
$config = (new Processor())->processConfiguration($configuration, []);
2922

30-
$this->assertInstanceOf(ConfigurationInterface::class, $this->configuration);
23+
$this->assertInstanceOf(ConfigurationInterface::class, $configuration);
3124
$this->assertInstanceOf(TreeBuilder::class, $treeBuilder);
3225
$this->assertEquals([
3326
'enabled' => true,
@@ -37,26 +30,24 @@ public function testDefaultConfig(): void
3730

3831
}
3932

40-
public function invalidFormatsProvider(): iterable
41-
{
42-
yield [['js']];
43-
yield [['html']];
44-
yield [['json', 'xml', 'form', 'txt']];
45-
yield [['form', 'pdf']];
46-
}
47-
48-
/**
49-
* @dataProvider invalidFormatsProvider
50-
*/
33+
#[DataProvider('invalidFormatsProvider')]
5134
public function testInvalidFormatsConfig(array $formats): void
5235
{
5336
self::expectException(InvalidConfigurationException::class);
5437
self::expectExceptionMessageMatches('/Only the formats .+ are supported. Got .+./');
5538

56-
$this->processor->processConfiguration($this->configuration, [
39+
(new Processor())->processConfiguration((new Configuration()), [
5740
'request_input' => [
5841
'formats' => $formats
5942
]
6043
]);
6144
}
45+
46+
public static function invalidFormatsProvider(): iterable
47+
{
48+
yield [['js']];
49+
yield [['html']];
50+
yield [['json', 'xml', 'form', 'txt']];
51+
yield [['form', 'pdf']];
52+
}
6253
}

0 commit comments

Comments
 (0)