From 2576b432ae30a389f435bf8738c40e18199ace8f Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Sun, 17 Mar 2024 00:28:12 +0100 Subject: [PATCH 01/17] Updating dependencies and refactoring ResponseFactoryTest and Serializer/FactoryTest This commit updates the version numbers of several dependencies in composer.json and performs a significant refactoring of ResponseFactoryTest and Serializer/FactoryTest. The changes in ResponseFactoryTest include refactoring the test names and adding new test methods. At the same time, additional test methods were added and existing methods were revised. A new file, XmlDummy.php, is also created for testing purposes. --- composer.json | 28 ++-- tests/Http/Responses/ResponseFactoryTest.php | 147 ++++++++++++++----- tests/ResponseFactory/XmlDummy.php | 19 +++ tests/Serializer/FactoryTest.php | 94 ++++++++++++ 4 files changed, 241 insertions(+), 47 deletions(-) create mode 100644 tests/ResponseFactory/XmlDummy.php diff --git a/composer.json b/composer.json index 57b55cb..939e732 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ } ], "require": { - "php": "^8.1", - "illuminate/http": "^9.0|^10.0", - "illuminate/support": "^9.0|^10.0", - "illuminate/contracts": "^9.0|^10.0", - "jms/serializer": "^3.27" + "php": "^8.1|^8.2", + "illuminate/http": "^9.0|^10.0|^11.0", + "illuminate/support": "^9.0|^10.0|^11.0", + "illuminate/contracts": "^9.0|^10.0|^11.0", + "jms/serializer": "^3.30" }, "autoload": { "psr-4": { @@ -37,17 +37,17 @@ }, "require-dev": { "roave/security-advisories": "dev-latest", - "friendsofphp/php-cs-fixer": "^3.23", - "phpunit/phpunit": "^10.3", - "nunomaduro/larastan": "^2.6", - "orchestra/testbench": "^8.9", + "friendsofphp/php-cs-fixer": "^3.51", + "phpunit/phpunit": "^10.0", + "larastan/larastan": "^2.9", + "orchestra/testbench": "^8.9|^9.0", "phpstan/phpstan-phpunit": "^1.3", "php-parallel-lint/php-parallel-lint": "^1.3", - "symfony/cache": "^6.3", - "vimeo/psalm": "^5.15", - "psalm/plugin-laravel": "^2.8", - "psalm/plugin-phpunit": "^0.18.4", - "infection/infection": "^0.27.6" + "symfony/cache": "^6.3|^7.0", + "vimeo/psalm": "^5.23", + "psalm/plugin-laravel": "^2.10", + "psalm/plugin-phpunit": "^0.19", + "infection/infection": "^0.27.10" }, "scripts": { "lint": "parallel-lint --exclude .git --exclude vendor .", diff --git a/tests/Http/Responses/ResponseFactoryTest.php b/tests/Http/Responses/ResponseFactoryTest.php index 139d386..17cd7a0 100644 --- a/tests/Http/Responses/ResponseFactoryTest.php +++ b/tests/Http/Responses/ResponseFactoryTest.php @@ -10,8 +10,13 @@ use Dropelikeit\LaravelJmsSerializer\Serializer\Factory; use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\Dummy; use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\Response; +use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\XmlDummy; use Illuminate\Http\Response as LaravelResponse; +use InvalidArgumentException; use JMS\Serializer\SerializationContext; +use JMS\Serializer\SerializerInterface; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -20,10 +25,8 @@ */ final class ResponseFactoryTest extends TestCase { - /** - * @psalm-var MockObject&Contracts\Config - */ - private MockObject $config; + private readonly MockObject&Contracts\Config $config; + private readonly MockObject&SerializerInterface $serializer; public function setUp(): void { @@ -33,11 +36,13 @@ public function setUp(): void ->getMockBuilder(Contracts\Config::class) ->disableOriginalConstructor() ->getMock(); + + $this->serializer = $this + ->getMockBuilder(SerializerInterface::class) + ->getMock(); } - /** - * @test - */ + #[Test] public function canCreateResponse(): void { $this->config @@ -63,9 +68,7 @@ public function canCreateResponse(): void self::assertEquals('{"amount":12,"text":"Hello World!"}', $response->getContent()); } - /** - * @test - */ + #[Test] public function canCreateFromArrayIterator(): void { $this->config @@ -91,9 +94,7 @@ public function canCreateFromArrayIterator(): void self::assertEquals('[{"key":"magic_number","value":12}]', $response->getContent()); } - /** - * @test - */ + #[Test] public function canCreateJsonResponseFromArray(): void { $this->config @@ -122,9 +123,7 @@ public function canCreateJsonResponseFromArray(): void ); } - /** - * @test - */ + #[Test] public function canCreateXmlResponseFromArray(): void { $this->config @@ -140,7 +139,7 @@ public function canCreateXmlResponseFromArray(): void $this->config ->expects(self::once()) ->method('getSerializeType') - ->willReturn(Contracts\Config::SERIALIZE_TYPE_XML); + ->willReturn('xml'); $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); @@ -165,9 +164,7 @@ public function canCreateXmlResponseFromArray(): void ); } - /** - * @test - */ + #[Test] public function canChangeStatusCode(): void { $this->config @@ -195,9 +192,7 @@ public function canChangeStatusCode(): void self::assertEquals('{"amount":12,"text":"Hello World!"}', $response->getContent()); } - /** - * @test - */ + #[Test] public function canUseGivenContext(): void { $this->config @@ -225,11 +220,9 @@ public function canUseGivenContext(): void /** * @psalm-param Contracts\Config::SERIALIZE_TYPE_* $changeSerializeTypeTo - * @param string $expectedResult - * - * @test - * @dataProvider dataProviderCanSerializeWithSerializeType */ + #[Test] + #[DataProvider(methodName: 'dataProviderCanSerializeWithSerializeType')] public function canSerializeWithSerializeType(string $changeSerializeTypeTo, string $expectedResult): void { $this->config @@ -282,9 +275,7 @@ public static function dataProviderCanSerializeWithSerializeType(): array ]; } - /** - * @test - */ + #[Test] public function canNotCreateWithUnknownSerializeType(): void { $this->expectException(SerializeType::class); @@ -310,9 +301,7 @@ public function canNotCreateWithUnknownSerializeType(): void $responseFactory->withSerializeType('array'); } - /** - * @test - */ + #[Test] public function canCreateQuietResponse(): void { $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); @@ -321,4 +310,96 @@ public function canCreateQuietResponse(): void $this->assertEquals(new LaravelResponse(status: 204), $response); } + + #[Test] + public function throwInvalidArgumentExceptionIfContentOnCreateMethodIsEmpty(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(0); + $this->expectExceptionMessage('Expected a different value than "".'); + + $object = new Dummy(); + + $this->config + ->expects(self::never()) + ->method('getCacheDir'); + + $this->config + ->expects(self::never()) + ->method('debug'); + + $this->config + ->expects(self::once()) + ->method('getSerializeType') + ->willReturn(Contracts\Config::SERIALIZE_TYPE_JSON); + + $this->serializer + ->expects(self::once()) + ->method('serialize') + ->with($object, 'json', null, null) + ->wilLReturn(''); + + (new ResponseFactory($this->serializer, $this->config))->create($object); + } + + #[Test] + public function throwInvalidArgumentExceptionIfContentOnCreateFromArrayMethodIsEmpty(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(0); + $this->expectExceptionMessage('Expected a different value than "".'); + + $object = new Dummy(); + + $this->config + ->expects(self::never()) + ->method('getCacheDir'); + + $this->config + ->expects(self::never()) + ->method('debug'); + + $this->config + ->expects(self::once()) + ->method('getSerializeType') + ->willReturn(Contracts\Config::SERIALIZE_TYPE_JSON); + + $this->serializer + ->expects(self::once()) + ->method('serialize') + ->with([$object], 'json', null) + ->wilLReturn(''); + + (new ResponseFactory($this->serializer, $this->config))->createFromArray([$object]); + } + + #[Test] + public function canDetectIfSerializeTypeIsXmlResultResponseHasXml(): void + { + $this->config + ->expects(self::once()) + ->method('getCacheDir') + ->willReturn(__DIR__); + + $this->config + ->expects(self::once()) + ->method('debug') + ->willReturn(true); + + $this->config + ->expects(self::once()) + ->method('getSerializeType') + ->willReturn('xml'); + + $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); + + $response = $responseFactory->create(new XmlDummy()); + + $this->assertEquals( + ' + +', + $response->getContent(), + ); + } } diff --git a/tests/ResponseFactory/XmlDummy.php b/tests/ResponseFactory/XmlDummy.php new file mode 100644 index 0000000..8f80c47 --- /dev/null +++ b/tests/ResponseFactory/XmlDummy.php @@ -0,0 +1,19 @@ +title = 'My test'; + } +} diff --git a/tests/Serializer/FactoryTest.php b/tests/Serializer/FactoryTest.php index eea904f..4dbe513 100644 --- a/tests/Serializer/FactoryTest.php +++ b/tests/Serializer/FactoryTest.php @@ -10,9 +10,16 @@ use Dropelikeit\LaravelJmsSerializer\Tests\Serializer\data\CustomHandler; use InvalidArgumentException; use JMS\Serializer\Context; +use JMS\Serializer\Handler\HandlerRegistry; use JMS\Serializer\JsonSerializationVisitor; +use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; +use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; +use JMS\Serializer\SerializationContext; use JMS\Serializer\Serializer; +use JMS\Serializer\SerializerBuilder; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Webmozart\Assert\Assert; /** * @author Marcel Strahl @@ -138,4 +145,91 @@ public function canNotCreateSerializerWithInvalidCustomHandler(): void ], ])); } + + #[Test] + public function detectIfSerializerHasDefaultListeners(): void + { + $expectedSerializer = $this->getSerializer(); + + /** @var array{serialize_null: bool, cache_dir: string, serialize_type: string, debug: bool, add_default_handlers: bool, custom_handlers: array} $config */ + $config = [ + 'serialize_null' => true, + 'serialize_type' => 'json', + 'cache_dir' => 'tmp', + 'debug' => false, + 'add_default_handlers' => true, + 'custom_handlers' => [ + CustomHandler::class, + ], + ]; + + $serializer = (new Factory())->getSerializer(Config::fromConfig($config)); + + $this->assertEquals($expectedSerializer, $serializer); + } + + private function getSerializer(): Serializer + { + $config = Config::fromConfig([ + 'serialize_null' => true, + 'serialize_type' => 'json', + 'cache_dir' => 'tmp', + 'debug' => false, + 'add_default_handlers' => true, + 'custom_handlers' => [ + CustomHandler::class, + ], + ]); + + $builder = SerializerBuilder::create() + ->setPropertyNamingStrategy( + new SerializedNameAnnotationStrategy( + new IdenticalPropertyNamingStrategy() + ) + ) + ->addDefaultListeners() + ->setSerializationContextFactory(static function () use ($config): SerializationContext { + return SerializationContext::create()->setSerializeNull($config->shouldSerializeNull()); + }); + + if ($config->shouldAddDefaultHeaders()) { + $builder->addDefaultHandlers(); + } + + $customHandlers = $config->getCustomHandlers(); + if ($customHandlers !== []) { + $builder->configureHandlers(function (HandlerRegistry $registry) use ($customHandlers): void { + foreach ($customHandlers as $customHandler) { + if (is_string($customHandler) && class_exists($customHandler)) { + $customHandler = new $customHandler(); + } + + Assert::implementsInterface( + $customHandler, + CustomHandlerConfiguration::class, + sprintf( + 'Its required to implement the "%s" interface', + CustomHandlerConfiguration::class + ) + ); + /** @phpstan-ignore-next-line */ + assert($customHandler instanceof CustomHandlerConfiguration); + + $registry->registerHandler( + $customHandler->getDirection(), + $customHandler->getTypeName(), + $customHandler->getFormat(), + $customHandler->getCallable(), + ); + } + }); + } + + $cacheDir = $config->getCacheDir(); + if ($cacheDir !== '') { + $builder->setCacheDir($cacheDir); + } + + return $builder->setDebug($config->debug())->build(); + } } From 12cb8deb72854ba1c877ed972168ea0634c2a353 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Sun, 17 Mar 2024 00:32:58 +0100 Subject: [PATCH 02/17] Updating dependencies and refactoring ResponseFactoryTest and Serializer/FactoryTest This commit updates the version numbers of several dependencies in composer.json and performs a significant refactoring of ResponseFactoryTest and Serializer/FactoryTest. The changes in ResponseFactoryTest include refactoring the test names and adding new test methods. At the same time, additional test methods were added and existing methods were revised. A new file, XmlDummy.php, is also created for testing purposes. --- phpstan.neon.dist | 2 +- tests/ResponseFactory/XmlDummy.php | 5 +++++ tests/Serializer/FactoryTest.php | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ea67adc..de030a2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ includes: - - vendor/nunomaduro/larastan/extension.neon + - vendor/larastan/larastan/extension.neon - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon parameters: diff --git a/tests/ResponseFactory/XmlDummy.php b/tests/ResponseFactory/XmlDummy.php index 8f80c47..e5e88d6 100644 --- a/tests/ResponseFactory/XmlDummy.php +++ b/tests/ResponseFactory/XmlDummy.php @@ -16,4 +16,9 @@ public function __construct() { $this->title = 'My test'; } + + public function getTitle(): string + { + return $this->title; + } } diff --git a/tests/Serializer/FactoryTest.php b/tests/Serializer/FactoryTest.php index 4dbe513..b8d2b04 100644 --- a/tests/Serializer/FactoryTest.php +++ b/tests/Serializer/FactoryTest.php @@ -170,7 +170,8 @@ public function detectIfSerializerHasDefaultListeners(): void private function getSerializer(): Serializer { - $config = Config::fromConfig([ + /** @var array{serialize_null: bool, cache_dir: string, serialize_type: string, debug: bool, add_default_handlers: bool, custom_handlers: array} $options */ + $options = [ 'serialize_null' => true, 'serialize_type' => 'json', 'cache_dir' => 'tmp', @@ -179,7 +180,9 @@ private function getSerializer(): Serializer 'custom_handlers' => [ CustomHandler::class, ], - ]); + ]; + + $config = Config::fromConfig($options); $builder = SerializerBuilder::create() ->setPropertyNamingStrategy( From 9864709371faf6297767a61400bc15ae6c35771a Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Tue, 19 Mar 2024 06:50:38 +0100 Subject: [PATCH 03/17] Update php-cs-fixer version and revise support note in README This commit increases the php-cs-fixer version in the composer.json file from "^3.51" to "^3.52". Furthermore, the support note section in the README.md file has been revised to present supported Laravel and PHP versions in a more detailed tabulated format. --- README.md | 10 ++++++++-- composer.json | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d3d9706..3b17380 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,14 @@ You are also welcome to use the Issue Tracker to set bugs, improvements or upgra ``` composer require dropelikeit/laravel-jms-serializer ``` ### Support note -- Laravel 6 and 7 are no longer supported with release v4.0.0 and higher. -- Laravel 5.* is no longer supported with release v2.0.0 and higher. +| Laravel | PHP | Package Version | Status | +|:-------:|:------------------:|:---------------:|:-------------:| +| 11 | 8.2, 8.3 | v5.x.x | Support | +| 10 | 8.1, 8.2, 8.3 | v5.x.x | Support | +| 9 | 8.0, 8.1, 8.2 | v4.x.x - v5.1.0 | Not supported | +| 8 | 7.3, 7.4, 8.0, 8.1 | v3.x.x - v4.0.0 | Not supported | +| 7 | 7.2, 7.3, 7.4, 8.0 | v2.x.x - v3.0.0 | Not supported | +| 6 | 7.2, 7.3, 7.4, 8.0 | v1.x.x - v3.0.0 | Not supported | ### How to use diff --git a/composer.json b/composer.json index 939e732..32465e5 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "require-dev": { "roave/security-advisories": "dev-latest", - "friendsofphp/php-cs-fixer": "^3.51", + "friendsofphp/php-cs-fixer": "^3.52", "phpunit/phpunit": "^10.0", "larastan/larastan": "^2.9", "orchestra/testbench": "^8.9|^9.0", From 24a380e7b5de3b8635f068e3bc16db2fb46a34eb Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Tue, 19 Mar 2024 06:52:05 +0100 Subject: [PATCH 04/17] Update package versions and support status in README The versions for Laravel 11 and 10 packages were updated in the support note section. Package version for Laravel 11 was changed to v6.x.x, and for Laravel 10 was updated to indicate it now supports versions greater than or equal to v5.x.x. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b17380..a464f82 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ You are also welcome to use the Issue Tracker to set bugs, improvements or upgra ### Support note | Laravel | PHP | Package Version | Status | |:-------:|:------------------:|:---------------:|:-------------:| -| 11 | 8.2, 8.3 | v5.x.x | Support | -| 10 | 8.1, 8.2, 8.3 | v5.x.x | Support | +| 11 | 8.2, 8.3 | v6.x.x | Support | +| 10 | 8.1, 8.2, 8.3 | >=v5.x.x | Support | | 9 | 8.0, 8.1, 8.2 | v4.x.x - v5.1.0 | Not supported | | 8 | 7.3, 7.4, 8.0, 8.1 | v3.x.x - v4.0.0 | Not supported | | 7 | 7.2, 7.3, 7.4, 8.0 | v2.x.x - v3.0.0 | Not supported | From 0a7cda50e518d4f23700498b3a2ee1b4984d5d1c Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Tue, 19 Mar 2024 19:52:16 +0100 Subject: [PATCH 05/17] Simplify GitHub CI workflow and update PHP version The CI workflow in Github has been simplified by removing coverage and coveralls, and modifying the composer test command execution. The PHP version in composer.json was updated to include PHP 8.3. --- .github/workflows/ci.yml | 18 ++++-------------- composer.json | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2927c9..11aefce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,12 +30,7 @@ jobs: run: "composer install --no-interaction --prefer-dist" - name: "Run PHPUnit Tests" - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer test - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v + run: "composer test" - name: "Run PHP CS Check" run: "composer cs-check" @@ -50,8 +45,6 @@ jobs: run: "composer lint" - name: "Run infection" - env: - INFECTION_BADGE_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} run: "composer infection" php82: @@ -79,12 +72,7 @@ jobs: run: "composer install --no-interaction --prefer-dist" - name: "Run PHPUnit Tests" - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer test - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v + run: "composer test" - name: "Run PHP CS Check" run: "PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check" @@ -146,4 +134,6 @@ jobs: run: "composer lint" - name: "Run infection" + env: + INFECTION_BADGE_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} run: "composer infection" \ No newline at end of file diff --git a/composer.json b/composer.json index 32465e5..f55db94 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8.1|^8.2", + "php": "^8.1|^8.2|^8.3", "illuminate/http": "^9.0|^10.0|^11.0", "illuminate/support": "^9.0|^10.0|^11.0", "illuminate/contracts": "^9.0|^10.0|^11.0", From aaa0491b6a067a1743cfb7743244992792653a49 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Tue, 19 Mar 2024 20:18:31 +0100 Subject: [PATCH 06/17] Update GitHub CI workflow and composer settings for PHP versions The CI workflow has been updated to reflect changes in the file path and caching keys for more specific PHP versions (8.1, 8.2, 8.3). The changes were made in the composer test command execution in the .github/workflows/ci.yml file. --- .github/workflows/ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11aefce..66ad783 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,9 @@ jobs: - name: "Cache composer packages" uses: "actions/cache@v3" with: - path: "~/.composer/cache" - key: "php-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-composer-locked-" + path: "vendor" + key: "php-composer-locked-php-8.1-${{ hashFiles('**/composer.lock') }}" + restore-keys: "php-composer-locked-php-8.1-" - name: "Install dependencies with composer" run: "composer install --no-interaction --prefer-dist" @@ -64,9 +64,9 @@ jobs: - name: "Cache composer packages" uses: "actions/cache@v3" with: - path: "~/.composer/cache" - key: "php-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-composer-locked-" + path: "vendor" + key: "php-composer-locked-php-8.2-${{ hashFiles('**/composer.lock') }}" + restore-keys: "php-composer-locked-php-8.2-" - name: "Install dependencies with composer" run: "composer install --no-interaction --prefer-dist" @@ -106,9 +106,9 @@ jobs: - name: "Cache composer packages" uses: "actions/cache@v3" with: - path: "~/.composer/cache" - key: "php-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-composer-locked-" + path: "vendor" + key: "php-composer-locked-php-8.3-${{ hashFiles('**/composer.lock') }}" + restore-keys: "php-composer-locked-php-8.3-" - name: "Install dependencies with composer" run: "composer install --no-interaction --prefer-dist" From 89b60d831ce3b7fb2361342bf5c260b84131c07b Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Tue, 19 Mar 2024 20:28:37 +0100 Subject: [PATCH 07/17] Upgrade version of actions/checkout action in CI workflow The "actions/checkout" action version has been updated from v3 to v4 in the CI workflow file (.github/workflows/ci.yml). This change applies to multiple steps in the file, making the workflow use the more recent version of the action during the Checkout process. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66ad783..b541bc6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" with: fetch-depth: 2 @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" with: fetch-depth: 2 @@ -94,7 +94,7 @@ jobs: runs-on: ubuntu-latest steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" with: fetch-depth: 2 From 2787d2f704c2c58a508a03cc507e64c34e96e074 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 12:19:01 +0200 Subject: [PATCH 08/17] Refactor tests and enhance JSON response The tests have been restructured and json response has been enhanced. All test-related things within the "ResponseFactory" directory have been moved to a new "data" directory. Also, the composer.json file and ServiceProvider.php have been updated with new dependencies and adjustments. Updates to ResponseFactoryTest.php now allow JSON responses as well. --- .gitignore | 2 + composer.json | 7 ++- infection.json5 | 10 ++-- src/Http/Responses/ResponseFactory.php | 1 - src/ServiceProvider.php | 4 +- tests/Http/Responses/ResponseFactoryTest.php | 59 +++++++++++++++---- tests/{ => data}/ResponseFactory/Dummy.php | 6 +- tests/data/ResponseFactory/JsonDummy.php | 22 +++++++ tests/{ => data}/ResponseFactory/Response.php | 8 +-- .../ResponseFactory/Response/Item.php | 2 +- tests/{ => data}/ResponseFactory/XmlDummy.php | 2 +- .../ResponseFactory/dummy_array.php | 0 12 files changed, 93 insertions(+), 30 deletions(-) rename tests/{ => data}/ResponseFactory/Dummy.php (82%) create mode 100644 tests/data/ResponseFactory/JsonDummy.php rename tests/{ => data}/ResponseFactory/Response.php (74%) rename tests/{ => data}/ResponseFactory/Response/Item.php (88%) rename tests/{ => data}/ResponseFactory/XmlDummy.php (84%) rename tests/{ => data}/ResponseFactory/dummy_array.php (100%) diff --git a/.gitignore b/.gitignore index bf80923..66d109b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ Homestead.json composer.lock /tmp +/build +/tests/Http/Responses/metadata diff --git a/composer.json b/composer.json index f55db94..4e3fae0 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,9 @@ "vimeo/psalm": "^5.23", "psalm/plugin-laravel": "^2.10", "psalm/plugin-phpunit": "^0.19", - "infection/infection": "^0.27.10" + "infection/infection": "^0.27.10", + "phpat/phpat": "^0.10.15", + "phpstan/extension-installer": "^1.3" }, "scripts": { "lint": "parallel-lint --exclude .git --exclude vendor .", @@ -69,7 +71,8 @@ }, "config": { "allow-plugins": { - "infection/extension-installer": true + "infection/extension-installer": true, + "phpstan/extension-installer": true } } } diff --git a/infection.json5 b/infection.json5 index fd7aaae..6b8eef0 100644 --- a/infection.json5 +++ b/infection.json5 @@ -12,14 +12,14 @@ "@default": true }, "logs": { - "html": "infection.html", - "summary": "summary.log", - "json": "infection-log.json", - "perMutator": "per-mutator.md", + "html": "build/infection/infection.html", + "summary": "build/infection/summary.log", + "json": "build/infection/infection-log.json", + "perMutator": "build/infection/per-mutator.md", "github": true, "stryker": { "badge": "master" }, - "summaryJson": "summary.json" + "summaryJson": "build/infection/summary.json" }, } \ No newline at end of file diff --git a/src/Http/Responses/ResponseFactory.php b/src/Http/Responses/ResponseFactory.php index e4fa03e..2e74ea3 100644 --- a/src/Http/Responses/ResponseFactory.php +++ b/src/Http/Responses/ResponseFactory.php @@ -129,7 +129,6 @@ private function getResponse(string $content): Response return new JsonResponse( data: $content, status: $this->status, - headers: [self::HEADER_NAME_CONTENT_TYPE => self::HEADER_VALUE_APPLICATION_JSON], json: true ); } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 346f6c0..ec10d4b 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -9,6 +9,7 @@ use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory; use Dropelikeit\LaravelJmsSerializer\Serializer\Factory; use Illuminate\Config\Repository; +use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Storage; use Illuminate\Support\ServiceProvider as BaseServiceProvider; use function sprintf; @@ -64,8 +65,7 @@ public function register(): void $this->app->bind(ResponseBuilder::class, ResponseFactory::class); - $app = $this->app; - $this->app->bind('ResponseFactory', static function ($app): ResponseFactory { + $this->app->bind('ResponseFactory', static function (Application $app): ResponseFactory { return $app->get(ResponseFactory::class); }); } diff --git a/tests/Http/Responses/ResponseFactoryTest.php b/tests/Http/Responses/ResponseFactoryTest.php index 17cd7a0..2a86c04 100644 --- a/tests/Http/Responses/ResponseFactoryTest.php +++ b/tests/Http/Responses/ResponseFactoryTest.php @@ -8,9 +8,10 @@ use Dropelikeit\LaravelJmsSerializer\Exception\SerializeType; use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory; use Dropelikeit\LaravelJmsSerializer\Serializer\Factory; -use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\Dummy; -use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\Response; -use Dropelikeit\LaravelJmsSerializer\Tests\ResponseFactory\XmlDummy; +use Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\Dummy; +use Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\JsonDummy; +use Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\Response; +use Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\XmlDummy; use Illuminate\Http\Response as LaravelResponse; use InvalidArgumentException; use JMS\Serializer\SerializationContext; @@ -19,6 +20,7 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\JsonResponse; /** * @author Marcel Strahl @@ -88,7 +90,7 @@ public function canCreateFromArrayIterator(): void $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); - $response = $responseFactory->create(Response::create([new Response\Item()])); + $response = $responseFactory->create(Response::create([new \Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\Response\Item()])); self::assertEquals(200, $response->getStatusCode()); self::assertEquals('[{"key":"magic_number","value":12}]', $response->getContent()); @@ -114,7 +116,7 @@ public function canCreateJsonResponseFromArray(): void $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); - $response = $responseFactory->createFromArray(require __DIR__ . '/../../ResponseFactory/dummy_array.php'); + $response = $responseFactory->createFromArray(require __DIR__ . '/../../data/ResponseFactory/dummy_array.php'); self::assertEquals(200, $response->getStatusCode()); self::assertEquals( @@ -143,7 +145,7 @@ public function canCreateXmlResponseFromArray(): void $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); - $response = $responseFactory->createFromArray(require __DIR__ . '/../../ResponseFactory/dummy_array.php'); + $response = $responseFactory->createFromArray(require __DIR__ . '/../../data/ResponseFactory/dummy_array.php'); self::assertEquals(200, $response->getStatusCode()); self::assertEquals( @@ -376,6 +378,14 @@ public function throwInvalidArgumentExceptionIfContentOnCreateFromArrayMethodIsE #[Test] public function canDetectIfSerializeTypeIsXmlResultResponseHasXml(): void { + $expectedResponse = new LaravelResponse( + content: ' + +', + status: 200, + headers: ['Content-Type' => 'application/xml'] + ); + $this->config ->expects(self::once()) ->method('getCacheDir') @@ -395,11 +405,38 @@ public function canDetectIfSerializeTypeIsXmlResultResponseHasXml(): void $response = $responseFactory->create(new XmlDummy()); - $this->assertEquals( - ' - -', - $response->getContent(), + $this->assertEquals($expectedResponse, $response); + } + + #[Test] + public function canDetectIfSerializeTypeIsJSONResultResponseHasJSON(): void + { + $expectedResponse = new JsonResponse( + data: '{"title":"My test"}', + status: 200, + headers: ['Content-Type' => 'application/json'], + json: true ); + + $this->config + ->expects(self::once()) + ->method('getCacheDir') + ->willReturn(__DIR__); + + $this->config + ->expects(self::once()) + ->method('debug') + ->willReturn(true); + + $this->config + ->expects(self::once()) + ->method('getSerializeType') + ->willReturn('json'); + + $responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config); + + $response = $responseFactory->create(new JsonDummy()); + + $this->assertEquals($expectedResponse, $response); } } diff --git a/tests/ResponseFactory/Dummy.php b/tests/data/ResponseFactory/Dummy.php similarity index 82% rename from tests/ResponseFactory/Dummy.php rename to tests/data/ResponseFactory/Dummy.php index 44d9287..f956957 100644 --- a/tests/ResponseFactory/Dummy.php +++ b/tests/data/ResponseFactory/Dummy.php @@ -1,9 +1,9 @@ ") * @var array|null - * @psalm-param list + * @psalm-param Item */ public ?array $items = null; diff --git a/tests/data/ResponseFactory/JsonDummy.php b/tests/data/ResponseFactory/JsonDummy.php new file mode 100644 index 0000000..e7d765e --- /dev/null +++ b/tests/data/ResponseFactory/JsonDummy.php @@ -0,0 +1,22 @@ +title = 'My test'; + } + + public function getTitle(): string + { + return $this->title; + } +} \ No newline at end of file diff --git a/tests/ResponseFactory/Response.php b/tests/data/ResponseFactory/Response.php similarity index 74% rename from tests/ResponseFactory/Response.php rename to tests/data/ResponseFactory/Response.php index 7332ea1..1c06c08 100644 --- a/tests/ResponseFactory/Response.php +++ b/tests/data/ResponseFactory/Response.php @@ -1,10 +1,10 @@ $items - * @psalm-param list $items + * @psalm-param Item $items */ private function __construct(array $items) { @@ -27,7 +27,7 @@ private function __construct(array $items) /** * @param array $items - * @psalm-param list $items + * @psalm-param Item $items * * @return self */ diff --git a/tests/ResponseFactory/Response/Item.php b/tests/data/ResponseFactory/Response/Item.php similarity index 88% rename from tests/ResponseFactory/Response/Item.php rename to tests/data/ResponseFactory/Response/Item.php index 3b6d5a0..714b365 100644 --- a/tests/ResponseFactory/Response/Item.php +++ b/tests/data/ResponseFactory/Response/Item.php @@ -1,7 +1,7 @@ Date: Mon, 13 May 2024 12:20:49 +0200 Subject: [PATCH 09/17] Update .gitignore file The .gitignore file was modified to optimize it for the project's current needs. Unnecessary Laravel specific ignores were removed and PHPUnit, Composer, and Package specific ignores were added. This change will ensure that irrelevant files are not tracked by the version control system. --- .gitignore | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 66d109b..bec9efc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,11 @@ -/vendor/ -node_modules/ -npm-debug.log -yarn-error.log - -# Laravel 4 specific -bootstrap/compiled.php -app/storage/ - -# Laravel 5 & Lumen specific -public/storage -public/hot - -# Laravel 5 & Lumen specific with changed public path -public_html/storage -public_html/hot - -storage/*.key -.env -Homestead.yaml -Homestead.json -/.vagrant +# PHPUnit specific .phpunit.result.cache # Composer +/vendor/ composer.lock +# Package specific /tmp /build /tests/Http/Responses/metadata From 2128da0b0812390fb27a6813563ed1b9f259dd7a Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 12:27:31 +0200 Subject: [PATCH 10/17] Fix deprecation issues --- .php-cs-fixer.dist.php | 4 ++-- tests/data/ResponseFactory/JsonDummy.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e30a4a9..e031ee7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -25,7 +25,7 @@ 'magic_constant_casing' => true, 'modernize_types_casting' => true, 'native_function_casing' => true, - 'new_with_braces' => true, + 'new_with_parentheses' => true, 'no_alternative_syntax' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, @@ -41,7 +41,7 @@ 'no_superfluous_elseif' => true, 'no_trailing_comma_in_singleline' => true, 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, + 'no_unneeded_braces' => true, 'no_unneeded_final_method' => true, 'no_unused_imports' => true, 'no_useless_else' => true, diff --git a/tests/data/ResponseFactory/JsonDummy.php b/tests/data/ResponseFactory/JsonDummy.php index e7d765e..b9548cb 100644 --- a/tests/data/ResponseFactory/JsonDummy.php +++ b/tests/data/ResponseFactory/JsonDummy.php @@ -19,4 +19,4 @@ public function getTitle(): string { return $this->title; } -} \ No newline at end of file +} From e62633bd7d524b3333b3edf4f9a70e835716311c Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 12:39:00 +0200 Subject: [PATCH 11/17] Remove unused code and update tests The commit involves the removal of several unused lines of constants and code from ResponseFactory and composer.json. In addition, tests have also been updated to assert the instance type of ResponseFactory whenever it's gotten from the application container. Improvements were made to the type annotations in the ResponseFactory tests for clarity. --- composer.json | 7 ++----- src/Http/Responses/ResponseFactory.php | 1 - src/ServiceProvider.php | 5 ++++- tests/data/ResponseFactory/Response.php | 6 ++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 4e3fae0..f55db94 100644 --- a/composer.json +++ b/composer.json @@ -47,9 +47,7 @@ "vimeo/psalm": "^5.23", "psalm/plugin-laravel": "^2.10", "psalm/plugin-phpunit": "^0.19", - "infection/infection": "^0.27.10", - "phpat/phpat": "^0.10.15", - "phpstan/extension-installer": "^1.3" + "infection/infection": "^0.27.10" }, "scripts": { "lint": "parallel-lint --exclude .git --exclude vendor .", @@ -71,8 +69,7 @@ }, "config": { "allow-plugins": { - "infection/extension-installer": true, - "phpstan/extension-installer": true + "infection/extension-installer": true } } } diff --git a/src/Http/Responses/ResponseFactory.php b/src/Http/Responses/ResponseFactory.php index 2e74ea3..d8517b3 100644 --- a/src/Http/Responses/ResponseFactory.php +++ b/src/Http/Responses/ResponseFactory.php @@ -22,7 +22,6 @@ final class ResponseFactory implements Contracts\ResponseBuilder { private const HEADER_NAME_CONTENT_TYPE = 'Content-Type'; - private const HEADER_VALUE_APPLICATION_JSON = 'application/json'; private const HEADER_VALUE_APPLICATION_XML = 'application/xml'; private const SERIALIZER_INITIAL_TYPE_ARRAY = 'array'; diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index ec10d4b..660ccb3 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -66,7 +66,10 @@ public function register(): void $this->app->bind(ResponseBuilder::class, ResponseFactory::class); $this->app->bind('ResponseFactory', static function (Application $app): ResponseFactory { - return $app->get(ResponseFactory::class); + $responseFactory = $app->get(ResponseFactory::class); + Assert::isInstanceOf($responseFactory, ResponseFactory::class); + + return $responseFactory; }); } diff --git a/tests/data/ResponseFactory/Response.php b/tests/data/ResponseFactory/Response.php index 1c06c08..da9e0bc 100644 --- a/tests/data/ResponseFactory/Response.php +++ b/tests/data/ResponseFactory/Response.php @@ -15,7 +15,7 @@ final class Response extends ArrayIterator { /** * @param array $items - * @psalm-param Item $items + * @psalm-param list $items */ private function __construct(array $items) { @@ -27,9 +27,7 @@ private function __construct(array $items) /** * @param array $items - * @psalm-param Item $items - * - * @return self + * @psalm-param list $items */ public static function create(array $items): self { From 58ccece977c9c6508bef81938f97692be2f71c78 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 12:49:09 +0200 Subject: [PATCH 12/17] Upgrade actions/cache to v4 in CI workflow The CI workflow has been updated to use the latest version of actions/cache (v4) for caching composer packages. This change was made in the configurations for PHP versions 8.1, 8.2, and 8.3 to ensure consistent usage of the updated cache action across all versions. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b541bc6..7d64a4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: php-version: "8.1" - name: "Cache composer packages" - uses: "actions/cache@v3" + uses: "actions/cache@v4" with: path: "vendor" key: "php-composer-locked-php-8.1-${{ hashFiles('**/composer.lock') }}" @@ -62,7 +62,7 @@ jobs: php-version: "8.2" - name: "Cache composer packages" - uses: "actions/cache@v3" + uses: "actions/cache@v4" with: path: "vendor" key: "php-composer-locked-php-8.2-${{ hashFiles('**/composer.lock') }}" @@ -104,7 +104,7 @@ jobs: php-version: "8.3" - name: "Cache composer packages" - uses: "actions/cache@v3" + uses: "actions/cache@v4" with: path: "vendor" key: "php-composer-locked-php-8.3-${{ hashFiles('**/composer.lock') }}" From f8ab32a9f024fbda2919e32b7e10c11dfbd04880 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 13:36:46 +0200 Subject: [PATCH 13/17] Update composer and CI workflow for better test coverage Updated composer.json to enhance PHPUnit test coverage options and added 'infection-ci' for CI testing. Modified CI workflow to use 'infection-ci' for more efficient infection testing across different PHP versions. --- .github/workflows/ci.yml | 6 +++--- composer.json | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d64a4b..7bb4e26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: run: "composer lint" - name: "Run infection" - run: "composer infection" + run: "composer infection-ci" php82: name: PHP 8.2 @@ -87,7 +87,7 @@ jobs: run: "composer lint" - name: "Run infection" - run: "composer infection" + run: "composer infection-ci" php83: name: PHP 8.3 @@ -136,4 +136,4 @@ jobs: - name: "Run infection" env: INFECTION_BADGE_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - run: "composer infection" \ No newline at end of file + run: "composer infection-ci" \ No newline at end of file diff --git a/composer.json b/composer.json index f55db94..7c599a3 100644 --- a/composer.json +++ b/composer.json @@ -54,10 +54,11 @@ "cs-check": "php-cs-fixer -v --dry-run --using-cache=no fix", "cs-fix": "php-cs-fixer --using-cache=no fix", "test": "export XDEBUG_MODE=coverage && phpunit", - "test-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-clover build/logs/clover.xml --coverage-html build/logs/clover.html", + "test-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-xml build/logs --coverage-clover build/logs/clover.xml --coverage-html build/logs/clover.html --log-junit build/logs/junit.xml", "analyze": "phpstan analyze --no-progress --memory-limit=-1 --xdebug", "psalm": "psalm --no-cache -c psalm.xml", "infection": "infection --threads=4", + "infection-ci": "infection --coverage=build/logs --threads=16", "check": [ "@cs-check", "@analyze", From 0d5068e656edf65072cfcdf92a193094110488e9 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 13:40:16 +0200 Subject: [PATCH 14/17] Update test command in CI workflow The command for running tests in the CI workflow file has been changed from "composer test" to "composer test-coverage". This will aid in providing more detailed test coverage reports during the continuous integration process, thus helping in identifying untested areas of code and improving overall code quality and reliability. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb4e26..a76186e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: run: "composer install --no-interaction --prefer-dist" - name: "Run PHPUnit Tests" - run: "composer test" + run: "composer test-coverage" - name: "Run PHP CS Check" run: "composer cs-check" @@ -72,7 +72,7 @@ jobs: run: "composer install --no-interaction --prefer-dist" - name: "Run PHPUnit Tests" - run: "composer test" + run: "composer test-coverage" - name: "Run PHP CS Check" run: "PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check" @@ -117,7 +117,7 @@ jobs: env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer test + composer test-coverage composer global require php-coveralls/php-coveralls php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v From 24a7365f20dae1d3b12c892ee4da8b38f2c8f756 Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 13:43:41 +0200 Subject: [PATCH 15/17] Add CI trigger for main branch An addition was made to the CI workflow file to include triggers on push events to the main branch. Providing continuous integration support for the main branch will help ensure code stability and quality. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a76186e..442bf04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ name: "CI Tests" on: pull_request: push: + branches: + - main jobs: php81: From d6f04b665d2121f0d02e6e13e68cb712fac8792c Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 13:49:33 +0200 Subject: [PATCH 16/17] Simplify PHPUnit Tests in GitHub Actions The commit removes the Coveralls report generation from the GitHub Actions workflow. Now, the workflow only executes the test coverage without performing the extra steps for Coveralls report generation. This streamlines the GitHub Actions process by reducing complex steps. --- .github/workflows/ci.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 442bf04..5848358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,12 +116,7 @@ jobs: run: "composer install --no-interaction --prefer-dist" - name: "Run PHPUnit Tests" - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer test-coverage - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v + run: "composer test-coverage" - name: "Run PHP CS Check" run: "PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check" From 86f2703153f655e27d76191f3e177682c8e351ee Mon Sep 17 00:00:00 2001 From: Marcel Strahl Date: Mon, 13 May 2024 13:53:24 +0200 Subject: [PATCH 17/17] Update thread count for infection-ci in composer.json Reduced the number of threads used by the 'infection-ci' command in the composer.json file. The change decreases the thread usage from 16 to 4, which may impact the execution speed but helps to reduce resource consumption. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c599a3..0876212 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "analyze": "phpstan analyze --no-progress --memory-limit=-1 --xdebug", "psalm": "psalm --no-cache -c psalm.xml", "infection": "infection --threads=4", - "infection-ci": "infection --coverage=build/logs --threads=16", + "infection-ci": "infection --coverage=build/logs --threads=4", "check": [ "@cs-check", "@analyze",