From f8ababf66bc2bc1f2756e25ff6a9c3b904b425ee Mon Sep 17 00:00:00 2001 From: pidhorodetskyi <39693338+pidhorodetskyi@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:23:20 +0100 Subject: [PATCH] Symfony 6 support (#8) * Symfony 6 support * Symfony 6 support * Symfony 6 support * Symfony 6 support * update tests * Symfony 6 support * update tests to support php versions >=7.1 * GitHub action workflow (#1) --- .github/workflows/symfony.yml | 42 +++++++++++++++++++ ...nvertOnNormalizeNameConverterDecorator.php | 4 +- Service/Serializer/Encoder/JsonEncoder.php | 4 +- Service/Serializer/Encoder/UrlEncode.php | 4 +- Service/Serializer/Encoder/UrlEncoder.php | 4 +- Service/Serializer/Encoder/VoidEncoder.php | 4 +- .../EndpointsConfigurationLoaderTest.php | 4 +- .../Serializer/Encoder/UrlEncodeTest.php | 8 ++-- .../Serializer/Encoder/UrlEncoderTest.php | 10 ++--- composer.json | 23 +++++----- phpunit.xml.dist | 40 +++++++++--------- 11 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/symfony.yml diff --git a/.github/workflows/symfony.yml b/.github/workflows/symfony.yml new file mode 100644 index 0000000..e8d147c --- /dev/null +++ b/.github/workflows/symfony.yml @@ -0,0 +1,42 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Symfony + +on: + push: + branches: ['master'] + tags: ['*'] + pull_request: + branches: ['*'] + +permissions: + contents: read + +jobs: + symfony-tests: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ 'ubuntu-latest' ] + php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] + phpunit-versions: [ 'latest' ] + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl + ini-values: post_max_size=256M, max_execution_time=180 + coverage: xdebug + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout repository + uses: actions/checkout@v3 + - name: Composer update on php ${{ matrix.php }} and symfony + run: composer update --prefer-dist --no-progress + - name: Execute tests (Unit and Feature tests) via PHPUnit + run: vendor/bin/phpunit + diff --git a/Service/NameConverter/SkipConvertOnNormalizeNameConverterDecorator.php b/Service/NameConverter/SkipConvertOnNormalizeNameConverterDecorator.php index 166b39a..d97f6d5 100644 --- a/Service/NameConverter/SkipConvertOnNormalizeNameConverterDecorator.php +++ b/Service/NameConverter/SkipConvertOnNormalizeNameConverterDecorator.php @@ -29,7 +29,7 @@ public function __construct(NameConverterInterface $nameConverter) /** * {@inheritdoc} */ - public function normalize($propertyName) + public function normalize($propertyName): string { return $propertyName; } @@ -37,7 +37,7 @@ public function normalize($propertyName) /** * {@inheritdoc} */ - public function denormalize($propertyName) + public function denormalize($propertyName): string { return $this->nameConverter->denormalize($propertyName); } diff --git a/Service/Serializer/Encoder/JsonEncoder.php b/Service/Serializer/Encoder/JsonEncoder.php index 51a178d..6b59295 100644 --- a/Service/Serializer/Encoder/JsonEncoder.php +++ b/Service/Serializer/Encoder/JsonEncoder.php @@ -9,12 +9,12 @@ class JsonEncoder extends \Symfony\Component\Serializer\Encoder\JsonEncoder { const FORMAT_JSON_PATCH = 'json-patch'; - public function supportsEncoding($format) + public function supportsEncoding($format): bool { return static::FORMAT_JSON_PATCH === $format || parent::supportsEncoding($format); } - public function supportsDecoding($format) + public function supportsDecoding($format): bool { return static::FORMAT_JSON_PATCH === $format || parent::supportsDecoding($format); } diff --git a/Service/Serializer/Encoder/UrlEncode.php b/Service/Serializer/Encoder/UrlEncode.php index f2701a3..c759e41 100644 --- a/Service/Serializer/Encoder/UrlEncode.php +++ b/Service/Serializer/Encoder/UrlEncode.php @@ -11,7 +11,7 @@ class UrlEncode implements EncoderInterface * * {@inheritdoc} */ - public function encode($data, $format, array $context = []) + public function encode($data, $format, array $context = []): string { $data = $this->convertCamelCaseToSnakeCase($data); $encoded = http_build_query($data); @@ -22,7 +22,7 @@ public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding($format): bool { return UrlEncoder::FORMAT === $format; } diff --git a/Service/Serializer/Encoder/UrlEncoder.php b/Service/Serializer/Encoder/UrlEncoder.php index 0190605..563717f 100644 --- a/Service/Serializer/Encoder/UrlEncoder.php +++ b/Service/Serializer/Encoder/UrlEncoder.php @@ -21,7 +21,7 @@ public function __construct(UrlEncode $encodingImpl = null) /** * {@inheritdoc} */ - public function encode($data, $format, array $context = array()) + public function encode($data, $format, array $context = array()): string { return $this->encodingImpl->encode($data, self::FORMAT, $context); } @@ -29,7 +29,7 @@ public function encode($data, $format, array $context = array()) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding($format): bool { return self::FORMAT === $format; } diff --git a/Service/Serializer/Encoder/VoidEncoder.php b/Service/Serializer/Encoder/VoidEncoder.php index e1d188c..e655ac3 100644 --- a/Service/Serializer/Encoder/VoidEncoder.php +++ b/Service/Serializer/Encoder/VoidEncoder.php @@ -14,7 +14,7 @@ class VoidEncoder implements EncoderInterface /** * {@inheritdoc} */ - public function encode($data, $format, array $context = array()) + public function encode($data, $format, array $context = array()): string { return ''; } @@ -22,7 +22,7 @@ public function encode($data, $format, array $context = array()) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding($format): bool { return self::FORMAT === $format; } diff --git a/Tests/Service/Endpoint/EndpointsConfigurationLoaderTest.php b/Tests/Service/Endpoint/EndpointsConfigurationLoaderTest.php index 5e4475c..398d828 100644 --- a/Tests/Service/Endpoint/EndpointsConfigurationLoaderTest.php +++ b/Tests/Service/Endpoint/EndpointsConfigurationLoaderTest.php @@ -10,9 +10,9 @@ */ class EndpointsConfigurationLoaderTest extends TestCase { - public function testConstructor() + public function testConstructor(): void { $endpointsConfigurationLoader = new EndpointsConfigurationLoader('configFilePathString'); self::assertInstanceOf(EndpointsConfigurationLoader::class, $endpointsConfigurationLoader); } -} \ No newline at end of file +} diff --git a/Tests/Service/Serializer/Encoder/UrlEncodeTest.php b/Tests/Service/Serializer/Encoder/UrlEncodeTest.php index 54dd523..0c16412 100644 --- a/Tests/Service/Serializer/Encoder/UrlEncodeTest.php +++ b/Tests/Service/Serializer/Encoder/UrlEncodeTest.php @@ -13,12 +13,12 @@ class UrlEncodeTest extends TestCase */ private $encode; - protected function setUp() + protected function setUp(): void { $this->encode = new UrlEncode(); } - public function testSupportsEncoding() + public function testSupportsEncoding(): void { $this->assertTrue($this->encode->supportsEncoding(UrlEncoder::FORMAT)); $this->assertFalse($this->encode->supportsEncoding('foobar')); @@ -30,7 +30,7 @@ public function testSupportsEncoding() * @param array $toEncode * @param string $expected */ - public function testEncode(array $toEncode, string $expected) + public function testEncode(array $toEncode, string $expected): void { $this->assertEquals( $expected, @@ -41,7 +41,7 @@ public function testEncode(array $toEncode, string $expected) /** * @return array */ - public function encodeProvider() + public static function encodeProvider(): array { return [ 'empty' => [ diff --git a/Tests/Service/Serializer/Encoder/UrlEncoderTest.php b/Tests/Service/Serializer/Encoder/UrlEncoderTest.php index be44a98..a8a7555 100644 --- a/Tests/Service/Serializer/Encoder/UrlEncoderTest.php +++ b/Tests/Service/Serializer/Encoder/UrlEncoderTest.php @@ -22,13 +22,13 @@ class UrlEncoderTest extends TestCase /** * @return void */ - protected function setUp() + protected function setUp(): void { $this->encoder = new UrlEncoder(); $this->serializer = new Serializer(array(new CustomNormalizer()), array('url' => new UrlEncoder())); } - public function testEncodeSimple() + public function testEncodeSimple(): void { $obj = new \stdClass(); $obj->foo = 'foo'; @@ -38,7 +38,7 @@ public function testEncodeSimple() self::assertEquals($expected, $this->encoder->encode($obj, 'url')); } - public function testEncodeCamelToSnakeCaseNames() + public function testEncodeCamelToSnakeCaseNames(): void { $obj = $this->getObject(); @@ -50,7 +50,7 @@ public function testEncodeCamelToSnakeCaseNames() /** * @return string */ - protected function getUrlSource() + protected function getUrlSource(): string { return 'foo=foo&foo_bar=fooBar'; } @@ -58,7 +58,7 @@ protected function getUrlSource() /** * @return \stdClass */ - protected function getObject() + protected function getObject(): \stdClass { $obj = new \stdClass(); $obj->foo = 'foo'; diff --git a/composer.json b/composer.json index 98fb537..8e464b0 100644 --- a/composer.json +++ b/composer.json @@ -15,23 +15,22 @@ ], "require": { "php": ">=7.1.3", - "symfony/serializer" : "~4.2|~5.0", - "symfony/monolog-bridge": "~4.0|~5.0", - "symfony/dependency-injection": "~4.0|~5.0", - "symfony/config": "~4.0|~5.0", - "symfony/http-kernel": "~4.0|~5.0", - "symfony/property-info": "~4.0|~5.0", - "symfony/property-access": "~4.0|~5.0", - "symfony/yaml": "~4.0|~5.0", + "symfony/serializer": "~4.2|~5.0|~6.0", + "symfony/monolog-bridge": "~4.0|~5.0|~6.0", + "symfony/dependency-injection": "~4.0|~5.0|~6.0", + "symfony/config": "~4.0|~5.0|~6.0", + "symfony/http-kernel": "~4.0|~5.0|~6.0", + "symfony/property-info": "~4.0|~5.0|~6.0", + "symfony/property-access": "~4.0|~5.0|~6.0", + "symfony/yaml": "~4.0|~5.0|~6.0", "monolog/monolog": "~1.22", "fig/http-message-util": "^1.1.2", "auto1-oss/service-api-request": "^1.0" }, "require-dev": { - "symfony/console": "~3.0|~4.0|~5.0", - "phpunit/phpunit": "^5.7", - "symfony/phpunit-bridge": "^3.3.8", - "phpspec/prophecy": "^1.7.2" + "symfony/console": "~3.0|~4.0|~5.0|~6.0", + "phpunit/phpunit": "^7.5|^8.0|^9.0", + "phpspec/prophecy-phpunit": "^1.1" }, "autoload": { "psr-4": { "Auto1\\ServiceAPIComponentsBundle\\": "" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d9256d4..ecbf5e4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,26 +7,26 @@ colors="true" bootstrap="vendor/autoload.php" > - - - - + + + + - - - ./Tests - - + + + ./Tests + + - - - . - - ./_code_coverage - ./Resources - ./Tests - ./vendor - - - + + + . + + ./_code_coverage + ./Resources + ./Tests + ./vendor + + +