diff --git a/composer.json b/composer.json index 1ed2449..faf57c8 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "require-dev": { "d3/testingtools": "^1.0", "phpunit/phpunit": "^9.6", - "friendsofphp/php-cs-fixer": "~3.13.0" + "friendsofphp/php-cs-fixer": "~3.13.0", + "phpstan/phpstan": "^1.10" }, "autoload": { "psr-4": { @@ -41,6 +42,9 @@ "scripts": { "php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/oxid-dic-handler/.php-cs-fixer.php", + "phpstan": "./vendor/bin/phpstan --configuration=vendor/d3/oxid-dic-handler/phpstan.neon analyse", + "phpstan-report": "./vendor/bin/phpstan --configuration=vendor/d3/ordermanager/phpstan.neon analyse --error-format=json > vendor/d3/ordermanager/tests/phpstan.report.json", + "phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/" } } diff --git a/definitionFileContainer.php b/definitionFileContainer.php index 12fd37a..a0d3931 100644 --- a/definitionFileContainer.php +++ b/definitionFileContainer.php @@ -35,13 +35,12 @@ class definitionFileContainer } /** - * @param $definitionFile - * @param $type - * @throws InvalidArgumentException + * @param string $definitionFile + * @param string $type * * @return void */ - public function addDefinitions($definitionFile, $type): void + public function addDefinitions(string $definitionFile, string $type): void { Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type'); Assert::that(rtrim(dirname(__FILE__, 3).'/').$definitionFile)->file('invalid definition file'); @@ -49,18 +48,22 @@ class definitionFileContainer $this->definitionFiles[$type][md5($definitionFile)] = $definitionFile; } - public function addYamlDefinitions($definitionFile): void + /** + * @param string $definitionFile + * + * @return void + */ + public function addYamlDefinitions(string $definitionFile): void { $this->addDefinitions($definitionFile, self::TYPE_YAML); } /** - * @param $type + * @param string $type * * @return array - * @throws InvalidArgumentException */ - public function getDefinitions($type): array + public function getDefinitions(string $type): array { Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type'); diff --git a/phpstan.neon b/phpstan.neon index ddb1a12..5cc0599 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,13 @@ parameters: + bootstrapFiles: + - ./tests/classAlias.php scanFiles: - ../../oxid-esales/oxideshop-ce/source/bootstrap.php - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php - ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php paths: - . - level: 0 + level: 8 phpVersion: 80300 checkMissingIterableValueType: false featureToggles: diff --git a/tests/classAlias.php b/tests/classAlias.php new file mode 100644 index 0000000..3decb97 --- /dev/null +++ b/tests/classAlias.php @@ -0,0 +1,18 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +use Symfony\Component\DependencyInjection\Container; + +class_alias(Container::class, d3DIContainerCache::class); diff --git a/tests/unit/d3DicHandlerTest.php b/tests/unit/d3DicHandlerTest.php index b44795a..d206d6b 100644 --- a/tests/unit/d3DicHandlerTest.php +++ b/tests/unit/d3DicHandlerTest.php @@ -152,7 +152,7 @@ class d3DicHandlerTest extends TestCase $this->assertMatchesRegularExpression( '/.*?\/tmp\/.*?DicContainer_\d+\.php$/m', - $this->callMethod( + (string) $this->callMethod( $sut, 'd3GetCacheFilePath' ) @@ -215,14 +215,12 @@ class d3DicHandlerTest extends TestCase $containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class) ->getMock(); - /** @var YamlFileLoader|MockObject $fileLoaderMock */ $fileLoaderMock = $this->getMockBuilder(YamlFileLoader::class) ->disableOriginalConstructor() ->onlyMethods(['load']) ->getMock(); $fileLoaderMock->expects($this->atLeastOnce())->method('load'); - /** @var d3DicHandler|MockObject $sut */ $sut = $this->getMockBuilder(d3DicHandler::class) ->onlyMethods(['d3GetFileLoader']) ->getMock(); @@ -254,15 +252,15 @@ class d3DicHandlerTest extends TestCase } /** + * @param bool $cacheExist * @test * @return void * @throws ReflectionException * @dataProvider cacheFileExistsTestDataProvider * @covers \D3\DIContainerHandler\d3DicHandler::cacheFileExists */ - public function cacheFileExistsTest($cacheExist) + public function cacheFileExistsTest(bool $cacheExist) { - /** @var d3DicHandler|MockObject $sut */ if (!$cacheExist) { $sut = $this->getMockBuilder(d3DicHandler::class) ->onlyMethods(['d3GetCacheFilePath']) @@ -309,18 +307,15 @@ class d3DicHandlerTest extends TestCase $cachedContainerMock = $this->getMockBuilder(d3DIContainerCache::class) ->getMock(); - /** @var ContainerBuilder|MockObject $containerBuilderMock */ $containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)->onlyMethods([ 'compile' ])->getMock(); $containerBuilderMock->expects($this->exactly((int) ! $cachedContainer))->method('compile'); - /** @var Config|MockObject $configMock */ $configMock = $this->getMockBuilder(Config::class) ->onlyMethods(['isProductiveMode', 'getConfigParam']) ->getMock(); $configMock->method('isProductiveMode')->willReturn($productive); $configMock->method('getConfigParam')->willReturnMap([['iDebug', $debug]]); - /** @var d3DicHandler|MockObject $sut */ $sut = $this->getMockBuilder(d3DicHandler::class) ->onlyMethods(['d3GetConfig', 'd3GetCacheContainer', 'getContainerBuilder', 'isNotInTest', 'cacheFileExists']) ->getMock(); diff --git a/tests/unit/d3DicUtilitiesTest.php b/tests/unit/d3DicUtilitiesTest.php index bcb0051..30f8f68 100644 --- a/tests/unit/d3DicUtilitiesTest.php +++ b/tests/unit/d3DicUtilitiesTest.php @@ -28,16 +28,17 @@ class d3DicUtilitiesTest extends TestCase /** * @test + * * @param string $className * @param string|null $additional - * @param $expected + * @param string $expected * * @return void * @throws ReflectionException - * @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId + * @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId * @dataProvider getServiceIdTestDataProvider */ - public function getServiceIdTest(string $className, string $additional = null, $expected): void + public function getServiceIdTest(string $className, string $additional = null, string $expected): void { $sut = oxNew(d3DicUtilities::class); @@ -60,16 +61,16 @@ class d3DicUtilitiesTest extends TestCase /** * @test * - * @param string $className - * @param string $argumentName - * @param $expected + * @param string $className + * @param string $argumentName + * @param string $expected * * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicUtilities::getArgumentId * @dataProvider getArgumentIdTestDataProvider */ - public function getArgumentIdTest(string $className, string $argumentName, $expected): void + public function getArgumentIdTest(string $className, string $argumentName, string $expected): void { $sut = oxNew(d3DicUtilities::class); @@ -99,7 +100,7 @@ class d3DicUtilitiesTest extends TestCase $sut = oxNew(d3DicUtilities::class); $this->assertDirectoryExists( - $this->callMethod( + (string) $this->callMethod( $sut, 'getVendorDir' ) diff --git a/tests/unit/definitionFileContainerTest.php b/tests/unit/definitionFileContainerTest.php index 9257cc4..db24f60 100644 --- a/tests/unit/definitionFileContainerTest.php +++ b/tests/unit/definitionFileContainerTest.php @@ -29,17 +29,17 @@ class definitionFileContainerTest extends TestCase /** * @test * - * @param $file - * @param $type - * @param $sumand - * @param bool $expectException + * @param string $file + * @param string $type + * @param int $sumand + * @param bool $expectException * * @return void * @throws ReflectionException * @dataProvider addDefinitionsTestDataProvider * @covers \D3\DIContainerHandler\definitionFileContainer::addDefinitions */ - public function addDefinitionsTest($file, $type, $sumand, bool $expectException): void + public function addDefinitionsTest(string $file, string $type, int $sumand, bool $expectException): void { $sut = oxNew(definitionFileContainer::class); $sut->clear(); @@ -188,7 +188,7 @@ class definitionFileContainerTest extends TestCase $this->assertCount( 0, - $this->callMethod( + (array) $this->callMethod( $sut, 'getAll' )