From 44151860d16f0d49a1a18851e04c0f2cff8ae7f3 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Tue, 21 Oct 2025 14:43:46 +0100 Subject: [PATCH 1/4] Use PhpFileLoader instead of YamlFileLoader --- composer.json | 2 + composer.lock | 102 +++++++++++++++++- phpstan.neon | 3 +- src/Resources/api.php | 45 ++++++++ src/Resources/api.yml | 32 ------ src/Resources/client.php | 43 ++++++++ src/Resources/client.yml | 32 ------ src/Resources/services.php | 17 +++ src/Resources/services.yml | 16 --- src/SupportPal.php | 5 +- test/Functional/SupportPalTest.php | 1 + test/PhpUnit/PhpUnitCompatibilityTrait.php | 18 ---- test/PhpUnit/RunnerVersion.php | 27 ----- test/PhpUnit/v8/TestCompatibilityTrait.php | 8 -- test/PhpUnit/v9/TestCompatibilityTrait.php | 10 -- test/TestCase.php | 4 +- test/Unit/ApiClientTest.php | 4 +- .../Cache/CacheStrategyConfiguratorTest.php | 1 + .../Cache/CacheableRequestMatcherTest.php | 4 +- test/Unit/Config/ApiContextTest.php | 4 +- 20 files changed, 223 insertions(+), 155 deletions(-) create mode 100644 src/Resources/api.php delete mode 100644 src/Resources/api.yml create mode 100644 src/Resources/client.php delete mode 100644 src/Resources/client.yml create mode 100644 src/Resources/services.php delete mode 100644 src/Resources/services.yml delete mode 100644 test/PhpUnit/PhpUnitCompatibilityTrait.php delete mode 100644 test/PhpUnit/RunnerVersion.php delete mode 100644 test/PhpUnit/v8/TestCompatibilityTrait.php delete mode 100644 test/PhpUnit/v9/TestCompatibilityTrait.php diff --git a/composer.json b/composer.json index c1dae58d..2e78892c 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,8 @@ "phpmd/phpmd": "^2.9", "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "2.1.31", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^9.3", "rregeer/phpunit-coverage-check": "^0.3.1", "slevomat/coding-standard": "^8.15", diff --git a/composer.lock b/composer.lock index 91205012..ed1f7353 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4417a9eda2f80f5ab49913736dbc8e72", + "content-hash": "48839666572fd88d00a792aec677e410", "packages": [ { "name": "brick/math", @@ -5179,6 +5179,106 @@ ], "time": "2025-10-10T14:14:11+00:00" }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "468e02c9176891cc901143da118f09dc9505fc2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/468e02c9176891cc901143da118f09dc9505fc2f", + "reference": "468e02c9176891cc901143da118f09dc9505fc2f", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.15" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.3" + }, + "time": "2025-05-14T10:56:57+00:00" + }, + { + "name": "phpstan/phpstan-phpunit", + "version": "2.0.7", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-phpunit.git", + "reference": "9a9b161baee88a5f5c58d816943cff354ff233dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/9a9b161baee88a5f5c58d816943cff354ff233dc", + "reference": "9a9b161baee88a5f5c58d816943cff354ff233dc", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.18" + }, + "conflict": { + "phpunit/phpunit": "<7.0" + }, + "require-dev": { + "nikic/php-parser": "^5", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPUnit extensions and rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-phpunit/issues", + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.7" + }, + "time": "2025-07-13T11:31:46+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.32", diff --git a/phpstan.neon b/phpstan.neon index 4b4297c7..f8300816 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,7 @@ includes: - vendor/jangregor/phpstan-prophecy/extension.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-phpunit/extension.neon parameters: level: 8 @@ -8,6 +10,5 @@ parameters: - test excludePaths: - test/DataFixtures - - test/PhpUnit parallel: processTimeout: 300.0 diff --git a/src/Resources/api.php b/src/Resources/api.php new file mode 100644 index 00000000..f375e533 --- /dev/null +++ b/src/Resources/api.php @@ -0,0 +1,45 @@ +services(); + + $services->defaults() + ->autowire() + ->autoconfigure(); + + $services->set(Api::class) + ->private(); + + $services->set(CoreApi::class) + ->public() + ->parent('SupportPal\ApiClient\Api\Api') + ->arg('$apiClient', service(CoreClient::class)); + + $services->set(SelfServiceApi::class) + ->public() + ->parent('SupportPal\ApiClient\Api\Api') + ->arg('$apiClient', service(SelfServiceClient::class)); + + $services->set(TicketApi::class) + ->public() + ->parent('SupportPal\ApiClient\Api\Api') + ->arg('$apiClient', service(TicketClient::class)); + + $services->set(UserApi::class) + ->public() + ->parent('SupportPal\ApiClient\Api\Api') + ->arg('$apiClient', service(UserClient::class)); +}; diff --git a/src/Resources/api.yml b/src/Resources/api.yml deleted file mode 100644 index aaabee62..00000000 --- a/src/Resources/api.yml +++ /dev/null @@ -1,32 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - SupportPal\ApiClient\Api\Api: - public: false - - SupportPal\ApiClient\Api\CoreApi: - public: true - parent: 'SupportPal\ApiClient\Api\Api' - arguments: - $apiClient: '@SupportPal\ApiClient\Http\CoreClient' - - SupportPal\ApiClient\Api\SelfServiceApi: - public: true - parent: 'SupportPal\ApiClient\Api\Api' - arguments: - $apiClient: '@SupportPal\ApiClient\Http\SelfServiceClient' - - SupportPal\ApiClient\Api\TicketApi: - public: true - parent: 'SupportPal\ApiClient\Api\Api' - arguments: - $apiClient: '@SupportPal\ApiClient\Http\TicketClient' - - SupportPal\ApiClient\Api\UserApi: - public: true - parent: 'SupportPal\ApiClient\Api\Api' - arguments: - $apiClient: '@SupportPal\ApiClient\Http\UserClient' diff --git a/src/Resources/client.php b/src/Resources/client.php new file mode 100644 index 00000000..74cd0738 --- /dev/null +++ b/src/Resources/client.php @@ -0,0 +1,43 @@ +services(); + + $services->defaults() + ->autowire() + ->autoconfigure(); + + $services->set(Client::class) + ->public() + ->arg('$httpClient', service(\GuzzleHttp\Client::class)); + + $services->set(CoreClient::class) + ->parent(Client::class); + + $services->set(SelfServiceClient::class) + ->parent(Client::class); + + $services->set(TicketClient::class) + ->parent(Client::class); + + $services->set(UserClient::class) + ->parent(Client::class); + + $services->set(Request::class) + ->public() + ->arg('$apiUrl', '%apiUrl%') + ->arg('$apiToken', '%apiToken%') + ->arg('$contentType', '%apiContentType%') + ->arg('$defaultBodyContent', '%defaultBodyContent%') + ->arg('$defaultParameters', '%defaultParameters%'); +}; diff --git a/src/Resources/client.yml b/src/Resources/client.yml deleted file mode 100644 index 0276653b..00000000 --- a/src/Resources/client.yml +++ /dev/null @@ -1,32 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - SupportPal\ApiClient\Http\Client: - public: true - arguments: - $httpClient: '@GuzzleHttp\Client' - - SupportPal\ApiClient\Http\CoreClient: - parent: 'SupportPal\ApiClient\Http\Client' - - SupportPal\ApiClient\Http\SelfServiceClient: - parent: 'SupportPal\ApiClient\Http\Client' - - SupportPal\ApiClient\Http\TicketClient: - parent: 'SupportPal\ApiClient\Http\Client' - - SupportPal\ApiClient\Http\UserClient: - parent: 'SupportPal\ApiClient\Http\Client' - - SupportPal\ApiClient\Http\Request: - public: true - arguments: - $apiUrl: '%apiUrl%' - $apiToken: '%apiToken%' - $contentType: '%apiContentType%' - $defaultBodyContent: '%defaultBodyContent%' - $defaultParameters: '%defaultParameters%' - diff --git a/src/Resources/services.php b/src/Resources/services.php new file mode 100644 index 00000000..a000cee2 --- /dev/null +++ b/src/Resources/services.php @@ -0,0 +1,17 @@ +import(__DIR__ . '/api.php'); + $containerConfigurator->import(__DIR__ . '/client.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set('apiContentType', 'application/json'); + $parameters->set('contentType', 'json'); + + $services = $containerConfigurator->services(); + $services->defaults() + ->autowire() + ->autoconfigure(); +}; diff --git a/src/Resources/services.yml b/src/Resources/services.yml deleted file mode 100644 index 2a3d497f..00000000 --- a/src/Resources/services.yml +++ /dev/null @@ -1,16 +0,0 @@ -imports: - - { resource: api.yml } - - { resource: client.yml } - -parameters: - apiContentType: 'application/json' - contentType: 'json' - -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - - diff --git a/src/SupportPal.php b/src/SupportPal.php index 027709ea..1bb76bd6 100644 --- a/src/SupportPal.php +++ b/src/SupportPal.php @@ -23,6 +23,7 @@ use SupportPal\ApiClient\Http\Request; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use function array_merge; @@ -50,8 +51,8 @@ public function __construct( $requestDefaults = $requestDefaults ?? new RequestDefaults; $containerBuilder = new ContainerBuilder; - $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); - $loader->load('Resources/services.yml'); + $loader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__)); + $loader->load('Resources/services.php'); $containerBuilder->setParameter('apiUrl', $this->escapeSpecialCharacters($apiContext->getApiUrl())); $containerBuilder->setParameter('apiToken', $this->escapeSpecialCharacters($apiContext->getApiToken())); $containerBuilder->setParameter('defaultParameters', $requestDefaults->getDefaultParameters()); diff --git a/test/Functional/SupportPalTest.php b/test/Functional/SupportPalTest.php index 651bd92d..b593f40c 100644 --- a/test/Functional/SupportPalTest.php +++ b/test/Functional/SupportPalTest.php @@ -19,6 +19,7 @@ class SupportPalTest extends ContainerAwareBaseTestCase { public function testGetRequestFactory(): void { + // @phpstan-ignore staticMethod.alreadyNarrowedType self::assertInstanceOf(Request::class, $this->getSupportPal()->getRequest()); } diff --git a/test/PhpUnit/PhpUnitCompatibilityTrait.php b/test/PhpUnit/PhpUnitCompatibilityTrait.php deleted file mode 100644 index ab56a980..00000000 --- a/test/PhpUnit/PhpUnitCompatibilityTrait.php +++ /dev/null @@ -1,18 +0,0 @@ - */ protected $genericErrorResponse = [ diff --git a/test/Unit/Cache/CacheStrategyConfiguratorTest.php b/test/Unit/Cache/CacheStrategyConfiguratorTest.php index 9b641369..10f91250 100644 --- a/test/Unit/Cache/CacheStrategyConfiguratorTest.php +++ b/test/Unit/Cache/CacheStrategyConfiguratorTest.php @@ -36,6 +36,7 @@ public function testConfigureCache(): void ->getCacheableApis('/api/')->shouldBeCalled() ->willReturn($apiCacheMap->getCacheableApis('/api/')); $strategy = $this->cacheConfigurator->buildCacheStrategy(sys_get_temp_dir(), '/api/'); + // @phpstan-ignore staticMethod.alreadyNarrowedType self::assertInstanceOf(CacheStrategyInterface::class, $strategy); } } diff --git a/test/Unit/Cache/CacheableRequestMatcherTest.php b/test/Unit/Cache/CacheableRequestMatcherTest.php index 17a7de33..1d7e239d 100644 --- a/test/Unit/Cache/CacheableRequestMatcherTest.php +++ b/test/Unit/Cache/CacheableRequestMatcherTest.php @@ -5,13 +5,13 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Uri; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SupportPal\ApiClient\Cache\CacheableRequestMatcher; use SupportPal\ApiClient\Dictionary\ApiDictionary; -use SupportPal\ApiClient\Tests\PhpUnit\PhpUnitCompatibilityTrait; class CacheableRequestMatcherTest extends TestCase { - use PhpUnitCompatibilityTrait; + use ProphecyTrait; /** @var CacheableRequestMatcher */ private $cacheableRequestMatcher; diff --git a/test/Unit/Config/ApiContextTest.php b/test/Unit/Config/ApiContextTest.php index b6289bd9..06c7ac59 100644 --- a/test/Unit/Config/ApiContextTest.php +++ b/test/Unit/Config/ApiContextTest.php @@ -3,13 +3,13 @@ namespace SupportPal\ApiClient\Tests\Unit\Config; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use SupportPal\ApiClient\Config\ApiContext; use SupportPal\ApiClient\Exception\InvalidArgumentException; -use SupportPal\ApiClient\Tests\PhpUnit\PhpUnitCompatibilityTrait; class ApiContextTest extends TestCase { - use PhpUnitCompatibilityTrait; + use ProphecyTrait; private const HOST = 'localhost'; From 6641a6eac17ae75a9341f41cd9eaecc561ca2160 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Tue, 21 Oct 2025 14:46:21 +0100 Subject: [PATCH 2/4] wip --- src/Resources/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resources/api.php b/src/Resources/api.php index f375e533..af8298e1 100644 --- a/src/Resources/api.php +++ b/src/Resources/api.php @@ -25,21 +25,21 @@ $services->set(CoreApi::class) ->public() - ->parent('SupportPal\ApiClient\Api\Api') + ->parent(Api::class) ->arg('$apiClient', service(CoreClient::class)); $services->set(SelfServiceApi::class) ->public() - ->parent('SupportPal\ApiClient\Api\Api') + ->parent(Api::class) ->arg('$apiClient', service(SelfServiceClient::class)); $services->set(TicketApi::class) ->public() - ->parent('SupportPal\ApiClient\Api\Api') + ->parent(Api::class) ->arg('$apiClient', service(TicketClient::class)); $services->set(UserApi::class) ->public() - ->parent('SupportPal\ApiClient\Api\Api') + ->parent(Api::class) ->arg('$apiClient', service(UserClient::class)); }; From 61970813e8add835324640fc297cf53e009ba115 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Tue, 21 Oct 2025 14:51:22 +0100 Subject: [PATCH 3/4] update services_test.yml --- test/ContainerAwareBaseTestCase.php | 6 ++--- test/E2E/BaseTestCase.php | 6 ++--- test/Resources/services_test.php | 37 +++++++++++++++++++++++++++++ test/Resources/services_test.yml | 31 ------------------------ 4 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 test/Resources/services_test.php delete mode 100644 test/Resources/services_test.yml diff --git a/test/ContainerAwareBaseTestCase.php b/test/ContainerAwareBaseTestCase.php index 104b3abc..a5969704 100644 --- a/test/ContainerAwareBaseTestCase.php +++ b/test/ContainerAwareBaseTestCase.php @@ -16,7 +16,7 @@ use SupportPal\ApiClient\SupportPal; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use function json_decode; use function json_encode; @@ -76,8 +76,8 @@ protected function setUp(): void * create container for test environment */ $containerBuilder = new ContainerBuilder; - $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); - $loader->load('Resources/services_test.yml'); + $loader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__)); + $loader->load(__DIR__.'/Resources/services_test.php'); $client = $this->getGuzzleClient(); $containerBuilder->set('GuzzleHttp\Client', $client); $containerBuilder->compile(); diff --git a/test/E2E/BaseTestCase.php b/test/E2E/BaseTestCase.php index dcb5175f..4013c971 100644 --- a/test/E2E/BaseTestCase.php +++ b/test/E2E/BaseTestCase.php @@ -15,7 +15,7 @@ use SupportPal\ApiClient\Tests\TestCase; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use function getenv; use function intval; @@ -44,8 +44,8 @@ public function setUp(): void $this->modelsTestLimit = $limit === 0 ? self::DEFAULT_LIMIT : $limit; $containerBuilder = new ContainerBuilder; - $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); - $loader->load('../Resources/services_test.yml'); + $loader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__)); + $loader->load(__DIR__.'/../Resources/services_test.php'); $containerBuilder->set(Client::class, new Client); $containerBuilder->compile(); diff --git a/test/Resources/services_test.php b/test/Resources/services_test.php new file mode 100644 index 00000000..32833c40 --- /dev/null +++ b/test/Resources/services_test.php @@ -0,0 +1,37 @@ +import(__DIR__ . '/../../src/Resources/services.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set('apiUrl', 'localhost:8080/api/'); + $parameters->set('apiToken', 'test2'); + $parameters->set('apiContentType', 'test3'); + $parameters->set('defaultBodyContent', ['test' => 'test']); + $parameters->set('defaultParameters', ['test' => 'test']); + + $services = $containerConfigurator->services(); + + $services->defaults() + ->autoconfigure() + ->autowire() + ->public(); + + $services->set(Request::class) + ->public() + ->arg('$apiUrl', '%apiUrl%') + ->arg('$apiToken', '%apiToken%') + ->arg('$contentType', '%apiContentType%') + ->arg('$defaultBodyContent', '%defaultBodyContent%') + ->arg('$defaultParameters', '%defaultParameters%'); + + $services->set(Client::class) + ->public() + ->arg('$httpClient', service(\GuzzleHttp\Client::class)); +}; diff --git a/test/Resources/services_test.yml b/test/Resources/services_test.yml deleted file mode 100644 index 7faa39f0..00000000 --- a/test/Resources/services_test.yml +++ /dev/null @@ -1,31 +0,0 @@ -imports: - - { resource: ../../src/Resources/services.yml } - -parameters: - apiUrl: 'localhost:8080/api/' - apiToken: 'test2' - apiContentType: 'test3' - defaultBodyContent: - test: 'test' - defaultParameters: - test: 'test' - -services: - _defaults: - autoconfigure: true - autowire: true - public: true - - SupportPal\ApiClient\Http\Request: - public: true - arguments: - $apiUrl: '%apiUrl%' - $apiToken: '%apiToken%' - $contentType: '%apiContentType%' - $defaultBodyContent: '%defaultBodyContent%' - $defaultParameters: '%defaultParameters%' - - SupportPal\ApiClient\Http\Client: - public: true - arguments: - $httpClient: '@GuzzleHttp\Client' From 8eb8ee9f3be79dde1aa0f3eec14b9f51549ee273 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Tue, 21 Oct 2025 14:52:01 +0100 Subject: [PATCH 4/4] phpcbf --- src/SupportPal.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SupportPal.php b/src/SupportPal.php index 1bb76bd6..8fba2e19 100644 --- a/src/SupportPal.php +++ b/src/SupportPal.php @@ -24,7 +24,6 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use function array_merge; use function str_replace;