improve code
This commit is contained in:
parent
b58f1b4156
commit
3a1c270932
@ -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/"
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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:
|
||||
|
18
tests/classAlias.php
Normal file
18
tests/classAlias.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
class_alias(Container::class, d3DIContainerCache::class);
|
@ -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();
|
||||
|
@ -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
|
||||
* @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);
|
||||
|
||||
@ -62,14 +63,14 @@ class d3DicUtilitiesTest extends TestCase
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $argumentName
|
||||
* @param $expected
|
||||
* @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'
|
||||
)
|
||||
|
@ -29,9 +29,9 @@ class definitionFileContainerTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $file
|
||||
* @param $type
|
||||
* @param $sumand
|
||||
* @param string $file
|
||||
* @param string $type
|
||||
* @param int $sumand
|
||||
* @param bool $expectException
|
||||
*
|
||||
* @return void
|
||||
@ -39,7 +39,7 @@ class definitionFileContainerTest extends TestCase
|
||||
* @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'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user