Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
943adfaa5e | |||
3a1c270932 | |||
b58f1b4156 | |||
8345a843c3 | |||
f5afd4617f | |||
8cc981902b | |||
dd077688ad | |||
53a9effeac | |||
5e573a2435 | |||
814bf56964 |
13
.php-cs-fixer.php
Normal file
13
.php-cs-fixer.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$finder = PhpCsFixer\Finder::create()
|
||||||
|
->in(__DIR__)
|
||||||
|
;
|
||||||
|
|
||||||
|
$config = new PhpCsFixer\Config();
|
||||||
|
return $config->setRules([
|
||||||
|
'@PHP80Migration' => true,
|
||||||
|
'@PSR12' => true
|
||||||
|
])
|
||||||
|
->setFinder($finder)
|
||||||
|
;
|
@ -14,12 +14,12 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use D3\DIContainerHandler\d3DicHandler;
|
use D3\DIContainerHandler\d3DicHandler;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ContainerBuilder
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function d3GetOxidDIC(): ContainerBuilder
|
function d3GetOxidDIC(): Container
|
||||||
{
|
{
|
||||||
return d3DicHandler::getInstance();
|
return d3DicHandler::getInstance();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,15 @@
|
|||||||
"MIT"
|
"MIT"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"symfony/dependency-injection": "^3.1|^5.4.11|^6.0"
|
"symfony/dependency-injection": "^3.1|^5.4.11|^6.0",
|
||||||
|
"beberlei/assert": "^3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"d3/testingtools": "^1.0",
|
||||||
|
"phpunit/phpunit": "^9.6",
|
||||||
|
"friendsofphp/php-cs-fixer": "~3.13.0",
|
||||||
|
"phpstan/phpstan": "^1.10",
|
||||||
|
"rector/rector": "^0.18.13"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -31,5 +39,15 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"autoload/functions_oxDIC.php"
|
"autoload/functions_oxDIC.php"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"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/",
|
||||||
|
|
||||||
|
"rector": "./vendor/bin/rector process --dry-run --config ./vendor/d3/oxid-dic-handler/rector.php"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
108
d3DicHandler.php
108
d3DicHandler.php
@ -17,37 +17,35 @@ namespace D3\DIContainerHandler;
|
|||||||
|
|
||||||
use d3DIContainerCache;
|
use d3DIContainerCache;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use OxidEsales\Eshop\Core\Config;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use OxidEsales\Facts\Config\ConfigFile;
|
use OxidEsales\Facts\Config\ConfigFile;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
|
|
||||||
class d3DicHandler implements d3DicHandlerInterface
|
class d3DicHandler implements d3DicHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
protected static Container|null $_instance = null;
|
||||||
* instance
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected static $_instance;
|
|
||||||
|
|
||||||
public static $circularReferenceMethodNames = array(
|
public static array $circularReferenceMethodNames = [
|
||||||
'getViewConfig'
|
'getViewConfig',
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get instance
|
* get instance
|
||||||
* @return ContainerBuilder
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance(): Container
|
||||||
{
|
{
|
||||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$caller = $trace[1];
|
$caller = $trace[1];
|
||||||
$functionName = $caller['function'];
|
$functionName = $caller['function'];
|
||||||
|
|
||||||
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames)))
|
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
|
||||||
{
|
|
||||||
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
|
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,16 +59,16 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get instance
|
* get instance
|
||||||
* @return ContainerBuilder
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function getUncompiledInstance()
|
public static function getUncompiledInstance(): Container
|
||||||
{
|
{
|
||||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$caller = $trace[1];
|
$caller = $trace[1];
|
||||||
$functionName = $caller['function'];
|
$functionName = $caller['function'];
|
||||||
|
|
||||||
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames)))
|
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
|
||||||
{
|
|
||||||
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
|
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,78 +78,80 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function removeInstance()
|
public static function removeInstance(): void
|
||||||
{
|
{
|
||||||
self::$_instance = null;
|
self::$_instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function d3GetConfig(): Config
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function d3GetConfig()
|
|
||||||
{
|
{
|
||||||
return Registry::getConfig();
|
return Registry::getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function d3GetCacheFilePath()
|
public function d3GetCacheFilePath(): string
|
||||||
{
|
{
|
||||||
return $this->d3GetConfig()->getConfigParam('sCompileDir').'/d3DicContainer_'.Registry::getConfig()->getShopId().'.php';
|
return $this->d3GetConfig()->getConfigParam('sCompileDir').'/d3DicContainer_'.Registry::getConfig()->getShopId().'.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function d3GetCacheContainer(): Container
|
||||||
* @return d3DIContainerCache|object
|
|
||||||
*/
|
|
||||||
public function d3GetCacheContainer()
|
|
||||||
{
|
{
|
||||||
require_once $this->d3GetCacheFilePath();
|
require_once $this->d3GetCacheFilePath();
|
||||||
return oxNew(d3DIContainerCache::class);
|
return oxNew(d3DIContainerCache::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader
|
||||||
* @param $container
|
|
||||||
* @return YamlFileLoader
|
|
||||||
*/
|
|
||||||
public function d3GetFileLoader($container)
|
|
||||||
{
|
{
|
||||||
/** @var YamlFileLoader $fileLoader */
|
/** @var YamlFileLoader $fileLoader */
|
||||||
$fileLoader = oxNew(YamlFileLoader::class,
|
$fileLoader = oxNew(
|
||||||
|
YamlFileLoader::class,
|
||||||
$container,
|
$container,
|
||||||
oxNew(FileLocator::class, $this->d3GetConfig()->getModulesDir())
|
oxNew(FileLocator::class, d3DicUtilities::getVendorDir())
|
||||||
);
|
);
|
||||||
|
|
||||||
return $fileLoader;
|
return $fileLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $container
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function loadFiles($container)
|
public function loadFiles(ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
$loader = $this->d3GetFileLoader($container);
|
$loader = $this->d3GetFileLoader($container);
|
||||||
|
|
||||||
$fileContainer = oxNew(definitionFileContainer::class);
|
$fileContainer = oxNew(definitionFileContainer::class);
|
||||||
foreach ($fileContainer->getYamlDefinitions() as $file) {
|
foreach ($fileContainer->getYamlDefinitions() as $file) {
|
||||||
$fullPath = $this->d3GetConfig()->getModulesDir().$file;
|
$fullPath = d3DicUtilities::getVendorDir().$file;
|
||||||
if (is_file($fullPath)) {
|
if (is_file($fullPath)) {
|
||||||
$loader->load($file);
|
$loader->load($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function isNotInTest(): bool
|
||||||
* @param bool $compileAndDump
|
|
||||||
* @return ContainerBuilder
|
|
||||||
*/
|
|
||||||
public function buildContainer(bool $compileAndDump = true)
|
|
||||||
{
|
{
|
||||||
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) startProfile(__METHOD__);
|
return false == defined('OXID_PHP_UNIT') || true == defined('D3_MODCFG_TEST');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cacheFileExists(): bool
|
||||||
|
{
|
||||||
|
return file_exists($this->d3GetCacheFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function buildContainer(bool $compileAndDump = true): Container
|
||||||
|
{
|
||||||
|
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
|
||||||
|
startProfile(__METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
$config = $this->d3GetConfig();
|
$config = $this->d3GetConfig();
|
||||||
|
|
||||||
if ($config->isProductiveMode()
|
if ($config->isProductiveMode()
|
||||||
&& false == $config->getConfigParam('iDebug')
|
&& ! $config->getConfigParam('iDebug')
|
||||||
&& (false == defined('OXID_PHP_UNIT') || true == defined('D3_MODCFG_TEST'))
|
&& $this->isNotInTest()
|
||||||
&& file_exists($this->d3GetCacheFilePath())
|
&& $this->cacheFileExists()
|
||||||
) {
|
) {
|
||||||
$container = $this->d3GetCacheContainer();
|
$container = $this->d3GetCacheContainer();
|
||||||
} else {
|
} else {
|
||||||
@ -161,19 +161,21 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
if ($compileAndDump) {
|
if ($compileAndDump) {
|
||||||
$container->compile();
|
$container->compile();
|
||||||
|
|
||||||
if (false == defined('OXID_PHP_UNIT')) {
|
if ($this->isNotInTest()) {
|
||||||
$dumper = new PhpDumper($container);
|
$dumper = new PhpDumper($container);
|
||||||
file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(array('class' => 'd3DIContainerCache')));
|
file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(['class' => 'd3DIContainerCache']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) stopProfile(__METHOD__);
|
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
|
||||||
|
stopProfile(__METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContainerBuilder()
|
public function getContainerBuilder(): ContainerBuilder
|
||||||
{
|
{
|
||||||
return oxNew(ContainerBuilder::class);
|
return oxNew(ContainerBuilder::class);
|
||||||
}
|
}
|
||||||
@ -181,10 +183,14 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
/**
|
/**
|
||||||
* clone
|
* clone
|
||||||
*/
|
*/
|
||||||
public function __clone() {}
|
public function __clone()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*/
|
*/
|
||||||
public function __construct() {}
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\DIContainerHandler;
|
namespace D3\DIContainerHandler;
|
||||||
|
|
||||||
/**
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
* Interface d3DicHandlerInterface
|
|
||||||
*/
|
|
||||||
interface d3DicHandlerInterface
|
interface d3DicHandlerInterface
|
||||||
{
|
{
|
||||||
public static function getInstance();
|
public static function getInstance(): Container;
|
||||||
}
|
}
|
@ -18,11 +18,10 @@ namespace D3\DIContainerHandler;
|
|||||||
class d3DicUtilities
|
class d3DicUtilities
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $classNameSpace
|
* @param string|null $additional
|
||||||
* @param bool $additional
|
*
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getServiceId($classNameSpace, $additional = false)
|
public static function getServiceId(string $classNameSpace, string $additional = null): string
|
||||||
{
|
{
|
||||||
return strtolower(
|
return strtolower(
|
||||||
($additional ? $additional.'.' : '').
|
($additional ? $additional.'.' : '').
|
||||||
@ -30,12 +29,7 @@ class d3DicUtilities
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function getArgumentId(string $classNamespace, string $argumentName): string
|
||||||
* @param $classNameSpace
|
|
||||||
* @param $argumentName
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getArgumentId($classNamespace, $argumentName)
|
|
||||||
{
|
{
|
||||||
return strtolower(
|
return strtolower(
|
||||||
$classNamespace.
|
$classNamespace.
|
||||||
@ -43,4 +37,9 @@ class d3DicUtilities
|
|||||||
$argumentName
|
$argumentName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getVendorDir(): string
|
||||||
|
{
|
||||||
|
return rtrim(dirname(__FILE__, 3), '/') . '/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,66 +15,59 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\DIContainerHandler;
|
namespace D3\DIContainerHandler;
|
||||||
|
|
||||||
|
use Assert\Assert;
|
||||||
|
use Assert\InvalidArgumentException;
|
||||||
|
|
||||||
class definitionFileContainer
|
class definitionFileContainer
|
||||||
{
|
{
|
||||||
public const TYPE_YAML = 'yml';
|
public const TYPE_YAML = 'yml';
|
||||||
|
|
||||||
protected $definitionFiles = [
|
protected array $definitionFiles = [
|
||||||
self::TYPE_YAML => []
|
self::TYPE_YAML => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $allowedTypes = [
|
protected array $allowedTypes = [
|
||||||
self::TYPE_YAML
|
self::TYPE_YAML,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->addYamlDefinitions('d3/modcfg/Config/services.yaml');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDefinitions($definitionFile, $type)
|
public function addDefinitions(string $definitionFile, string $type): void
|
||||||
{
|
{
|
||||||
if (!in_array($type, $this->allowedTypes)) {
|
Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type');
|
||||||
throw new \InvalidArgumentException('invalid definition file type');
|
Assert::that(rtrim(dirname(__FILE__, 3).'/').$definitionFile)->file('invalid definition file');
|
||||||
}
|
|
||||||
|
|
||||||
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
|
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addYamlDefinitions($definitionFile)
|
public function addYamlDefinitions(string $definitionFile): void
|
||||||
{
|
{
|
||||||
$this->addDefinitions($definitionFile, self::TYPE_YAML);
|
$this->addDefinitions($definitionFile, self::TYPE_YAML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefinitions($type)
|
public function getDefinitions(string $type): array
|
||||||
{
|
{
|
||||||
if (!in_array($type, $this->allowedTypes)) {
|
Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type');
|
||||||
throw new \InvalidArgumentException('invalid definition file type');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->definitionFiles[$type];
|
return $this->definitionFiles[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getYamlDefinitions()
|
public function getYamlDefinitions(): array
|
||||||
{
|
{
|
||||||
return $this->getDefinitions(self::TYPE_YAML);
|
return $this->getDefinitions(self::TYPE_YAML);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $definitionFile
|
* @return array[]
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function has($definitionFile): bool
|
public function getAll(): array
|
||||||
{
|
|
||||||
return isset($this->definitionFiles[md5($definitionFile)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAll()
|
|
||||||
{
|
{
|
||||||
return $this->definitionFiles;
|
return $this->definitionFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clear()
|
public function clear(): void
|
||||||
{
|
{
|
||||||
$this->definitionFiles = [];
|
$this->definitionFiles = [];
|
||||||
}
|
}
|
||||||
|
14
phpstan.neon
Normal file
14
phpstan.neon
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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: 8
|
||||||
|
phpVersion: 80300
|
||||||
|
checkMissingIterableValueType: false
|
||||||
|
featureToggles:
|
||||||
|
disableRuntimeReflectionProvider: true
|
55
rector.php
Normal file
55
rector.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
|
||||||
|
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
|
||||||
|
use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector;
|
||||||
|
use Rector\Config\RectorConfig;
|
||||||
|
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
|
||||||
|
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
|
||||||
|
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
|
||||||
|
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
|
||||||
|
use Rector\Set\ValueObject\LevelSetList;
|
||||||
|
use Rector\Set\ValueObject\SetList;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
|
||||||
|
|
||||||
|
return static function (RectorConfig $rectorConfig): void {
|
||||||
|
$rectorConfig->paths([
|
||||||
|
__DIR__ . '/.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rectorConfig->bootstrapFiles([
|
||||||
|
__DIR__.'/../../oxid-esales/oxideshop-ce/source/oxfunctions.php',
|
||||||
|
__DIR__.'/../../oxid-esales/oxideshop-ce/source/overridablefunctions.php',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rectorConfig->skip(
|
||||||
|
[
|
||||||
|
MixedTypeRector::class, // shouldn't remove argument annotations
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// define sets of rules
|
||||||
|
$rectorConfig->sets([
|
||||||
|
LevelSetList::UP_TO_PHP_80, // lowest possible PHP version for this plugin is 8.0
|
||||||
|
SetList::TYPE_DECLARATION,
|
||||||
|
SetList::INSTANCEOF,
|
||||||
|
SetList::EARLY_RETURN,
|
||||||
|
SetList::DEAD_CODE,
|
||||||
|
SetList::CODE_QUALITY,
|
||||||
|
SetList::CODING_STYLE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rectorConfig->importNames();
|
||||||
|
};
|
1
tests/.gitignore
vendored
Normal file
1
tests/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.phpunit.result.cache
|
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);
|
28
tests/phpunit.xml
Normal file
28
tests/phpunit.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
backupGlobals="true"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||||
|
colors="false"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="false"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
forceCoversAnnotation="false"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnError="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
stopOnIncomplete="false"
|
||||||
|
stopOnSkipped="false"
|
||||||
|
verbose="false"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
|
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">../</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Unit">
|
||||||
|
<directory>unit/</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
38
tests/unit/autoload/functions_oxDICTest.php
Normal file
38
tests/unit/autoload/functions_oxDICTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
namespace D3\DIContainerHandler\tests\autoload;
|
||||||
|
|
||||||
|
use D3\TestingTools\Development\CanAccessRestricted;
|
||||||
|
use Exception;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
class functions_oxDICTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanAccessRestricted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function d3GetOxidDICTest(): void
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
ContainerBuilder::class,
|
||||||
|
d3GetOxidDIC()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
344
tests/unit/d3DicHandlerTest.php
Normal file
344
tests/unit/d3DicHandlerTest.php
Normal file
@ -0,0 +1,344 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
namespace D3\DIContainerHandler\tests;
|
||||||
|
|
||||||
|
use D3\DIContainerHandler\d3DicHandler;
|
||||||
|
use D3\TestingTools\Development\CanAccessRestricted;
|
||||||
|
use d3DIContainerCache;
|
||||||
|
use Generator;
|
||||||
|
use OxidEsales\Eshop\Core\Config;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionException;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
|
|
||||||
|
define('D3_MODCFG_TEST', true);
|
||||||
|
|
||||||
|
class d3DicHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanAccessRestricted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::getInstance
|
||||||
|
*/
|
||||||
|
public function getInstanceTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->setValue(
|
||||||
|
$sut,
|
||||||
|
'_instance',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$containerBuilder = $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getInstance'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
ContainerBuilder::class,
|
||||||
|
$containerBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$containerBuilder,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getInstance'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue($containerBuilder->isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::getUncompiledInstance
|
||||||
|
*/
|
||||||
|
public function getUncompiledInstanceTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$containerBuilder = $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getUncompiledInstance'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
ContainerBuilder::class,
|
||||||
|
$containerBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse($containerBuilder->isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::removeInstance
|
||||||
|
*/
|
||||||
|
public function removeInstanceTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$containerBuilder = $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getInstance'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'removeInstance'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertNotSame(
|
||||||
|
$containerBuilder,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getInstance'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::d3GetConfig
|
||||||
|
*/
|
||||||
|
public function d3GetConfigTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
Config::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'd3GetConfig'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::d3GetCacheFilePath
|
||||||
|
*/
|
||||||
|
public function d3GetCacheFilePathTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
'/.*?\/tmp\/.*?DicContainer_\d+\.php$/m',
|
||||||
|
(string) $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'd3GetCacheFilePath'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::d3GetCacheContainer
|
||||||
|
*/
|
||||||
|
public function d3GetCacheContainerTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->callMethod($sut, 'buildContainer');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
d3DIContainerCache::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'd3GetCacheContainer'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::d3GetFileLoader
|
||||||
|
*/
|
||||||
|
public function d3GetFileLoaderTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
YamlFileLoader::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'd3GetFileLoader',
|
||||||
|
[$containerBuilderMock]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::loadFiles
|
||||||
|
*/
|
||||||
|
public function loadFilesTest(): void
|
||||||
|
{
|
||||||
|
/** @var ContainerBuilder|MockObject $containerBuilderMock */
|
||||||
|
$containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$fileLoaderMock = $this->getMockBuilder(YamlFileLoader::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['load'])
|
||||||
|
->getMock();
|
||||||
|
$fileLoaderMock->expects($this->atLeastOnce())->method('load');
|
||||||
|
|
||||||
|
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||||
|
->onlyMethods(['d3GetFileLoader'])
|
||||||
|
->getMock();
|
||||||
|
$sut->method('d3GetFileLoader')->willReturn($fileLoaderMock);
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'loadFiles',
|
||||||
|
[$containerBuilderMock]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::isNotInTest
|
||||||
|
*/
|
||||||
|
public function isNotInTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'isNotInTest'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @dataProvider cacheFileExistsTestDataProvider
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::cacheFileExists
|
||||||
|
*/
|
||||||
|
public function cacheFileExistsTest(bool $cacheExist): void
|
||||||
|
{
|
||||||
|
if (!$cacheExist) {
|
||||||
|
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||||
|
->onlyMethods(['d3GetCacheFilePath'])
|
||||||
|
->getMock();
|
||||||
|
$sut->method('d3GetCacheFilePath')->willReturn('foo');
|
||||||
|
} else {
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$cacheExist,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'cacheFileExists'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cacheFileExistsTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'cacheExist' => [true];
|
||||||
|
yield 'cacheMissing'=> [false];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @dataProvider buildContainerTestDataProvider
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::buildContainer
|
||||||
|
*/
|
||||||
|
public function buildContainerTest(bool $productive, int $debug, bool $notInTest, bool $cacheFileExist, bool $cachedContainer): void
|
||||||
|
{
|
||||||
|
$cachedContainerMock = $this->getMockBuilder(d3DIContainerCache::class)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)->onlyMethods([ 'compile' ])->getMock();
|
||||||
|
$containerBuilderMock->expects($this->exactly((int) ! $cachedContainer))->method('compile');
|
||||||
|
|
||||||
|
$configMock = $this->getMockBuilder(Config::class)
|
||||||
|
->onlyMethods(['isProductiveMode', 'getConfigParam'])
|
||||||
|
->getMock();
|
||||||
|
$configMock->method('isProductiveMode')->willReturn($productive);
|
||||||
|
$configMock->method('getConfigParam')->willReturnMap([['iDebug', $debug]]);
|
||||||
|
|
||||||
|
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||||
|
->onlyMethods(['d3GetConfig', 'd3GetCacheContainer', 'getContainerBuilder', 'isNotInTest', 'cacheFileExists'])
|
||||||
|
->getMock();
|
||||||
|
$sut->method('d3GetConfig')->willReturn($configMock);
|
||||||
|
$sut->expects($this->exactly((int) $cachedContainer))->method('d3GetCacheContainer')->willReturn($cachedContainerMock);
|
||||||
|
$sut->expects($this->exactly((int) !$cachedContainer))->method('getContainerBuilder')->willReturn($containerBuilderMock);
|
||||||
|
$sut->method('isNotInTest')->willReturn($notInTest);
|
||||||
|
$sut->method('cacheFileExists')->willReturn($cacheFileExist);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$cachedContainer ? $cachedContainerMock : $containerBuilderMock,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'buildContainer',
|
||||||
|
['false']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildContainerTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'notProductive' => [false, 0, false, true, false];
|
||||||
|
yield 'debug' => [true, 1, false, true, false];
|
||||||
|
yield 'inTest' => [true, 0, false, true, false];
|
||||||
|
yield 'cacheFileNotExist' => [true, 0, false, false, false];
|
||||||
|
yield 'cachedContainer' => [true, 0, true, true, true];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicHandler::getContainerBuilder
|
||||||
|
*/
|
||||||
|
public function getContainerBuilderTest(): void
|
||||||
|
{
|
||||||
|
$sut = new d3DicHandler();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
ContainerBuilder::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getContainerBuilder'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
101
tests/unit/d3DicUtilitiesTest.php
Normal file
101
tests/unit/d3DicUtilitiesTest.php
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
namespace D3\DIContainerHandler\tests;
|
||||||
|
|
||||||
|
use D3\DIContainerHandler\d3DicHandler;
|
||||||
|
use D3\DIContainerHandler\d3DicUtilities;
|
||||||
|
use D3\TestingTools\Development\CanAccessRestricted;
|
||||||
|
use Generator;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
|
class d3DicUtilitiesTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanAccessRestricted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
* @param string|null $additional
|
||||||
|
*
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId
|
||||||
|
* @dataProvider getServiceIdTestDataProvider
|
||||||
|
*/
|
||||||
|
public function getServiceIdTest(string $className, string $additional = null, string $expected): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(d3DicUtilities::class);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getServiceId',
|
||||||
|
[$className, $additional]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServiceIdTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'NS only' => [d3DicHandler::class, null, 'd3\dicontainerhandler\d3dichandler'];
|
||||||
|
yield 'NS + additional' => [d3DicHandler::class, 'additional', 'additional.d3\dicontainerhandler\d3dichandler'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicUtilities::getArgumentId
|
||||||
|
* @dataProvider getArgumentIdTestDataProvider
|
||||||
|
*/
|
||||||
|
public function getArgumentIdTest(string $className, string $argumentName, string $expected): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(d3DicUtilities::class);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getArgumentId',
|
||||||
|
[ $className, $argumentName]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArgumentIdTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'default' => [d3DicHandler::class, 'argumentName', 'd3\dicontainerhandler\d3dichandler.args.argumentname'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\d3DicUtilities::getVendorDir()
|
||||||
|
*/
|
||||||
|
public function getVendorDirTest(): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(d3DicUtilities::class);
|
||||||
|
|
||||||
|
$this->assertDirectoryExists(
|
||||||
|
(string) $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getVendorDir'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
179
tests/unit/definitionFileContainerTest.php
Normal file
179
tests/unit/definitionFileContainerTest.php
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
namespace D3\DIContainerHandler\tests;
|
||||||
|
|
||||||
|
use Assert\InvalidArgumentException;
|
||||||
|
use D3\DIContainerHandler\definitionFileContainer;
|
||||||
|
use D3\TestingTools\Development\CanAccessRestricted;
|
||||||
|
use Generator;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
|
class definitionFileContainerTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanAccessRestricted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @dataProvider addDefinitionsTestDataProvider
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::addDefinitions
|
||||||
|
*/
|
||||||
|
public function addDefinitionsTest(string $file, string $type, int $sumand, bool $expectException): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(definitionFileContainer::class);
|
||||||
|
$sut->clear();
|
||||||
|
|
||||||
|
$currentCount = count($sut->getAll());
|
||||||
|
|
||||||
|
if ($expectException) {
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'addDefinitions',
|
||||||
|
[$file, $type]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(
|
||||||
|
$currentCount + $sumand,
|
||||||
|
$sut->getAll()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addDefinitionsTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'invalid file' => ['foo.txt', definitionFileContainer::TYPE_YAML, 0, true];
|
||||||
|
yield 'invalid type' => ['d3/modcfg/Config/services.yaml', 'txt', 0, true];
|
||||||
|
yield 'ok' => ['d3/modcfg/Config/services.yaml', definitionFileContainer::TYPE_YAML, 1, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::addYamlDefinitions
|
||||||
|
*/
|
||||||
|
public function addYamlDefinitionsTest(): void
|
||||||
|
{
|
||||||
|
$sut = $this->getMockBuilder(definitionFileContainer::class)
|
||||||
|
->onlyMethods(['addDefinitions'])
|
||||||
|
->getMock();
|
||||||
|
$sut->expects($this->once())->method('addDefinitions');
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'addYamlDefinitions',
|
||||||
|
['d3/modcfg/Config/services.yaml']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::getDefinitions
|
||||||
|
* @dataProvider getDefinitionsTestDataProvider
|
||||||
|
*/
|
||||||
|
public function getDefinitionsTest(string $type, bool $expectException): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(definitionFileContainer::class);
|
||||||
|
|
||||||
|
if ($expectException) {
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$definitions = $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getDefinitions',
|
||||||
|
[$type]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertIsArray($definitions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefinitionsTestDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield 'type ok' => [definitionFileContainer::TYPE_YAML, false];
|
||||||
|
yield 'type not ok' => ['txt', true];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::getYamlDefinitions
|
||||||
|
*/
|
||||||
|
public function getYamlDefinitionsTest(): void
|
||||||
|
{
|
||||||
|
$sut = $this->getMockBuilder(definitionFileContainer::class)
|
||||||
|
->onlyMethods(['getDefinitions'])
|
||||||
|
->getMock();
|
||||||
|
$sut->expects($this->once())->method('getDefinitions');
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getYamlDefinitions'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::getAll
|
||||||
|
*/
|
||||||
|
public function getAllTest(): void
|
||||||
|
{
|
||||||
|
$fixture = ['foo'];
|
||||||
|
|
||||||
|
$sut = oxNew(definitionFileContainer::class);
|
||||||
|
$this->setValue(
|
||||||
|
$sut,
|
||||||
|
'definitionFiles',
|
||||||
|
$fixture
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$fixture,
|
||||||
|
$this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getAll'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\DIContainerHandler\definitionFileContainer::clear
|
||||||
|
*/
|
||||||
|
public function clearTest(): void
|
||||||
|
{
|
||||||
|
$sut = oxNew(definitionFileContainer::class);
|
||||||
|
$sut->addYamlDefinitions('d3/modcfg/Config/services.yaml');
|
||||||
|
$sut->clear();
|
||||||
|
|
||||||
|
$this->assertCount(
|
||||||
|
0,
|
||||||
|
(array) $this->callMethod(
|
||||||
|
$sut,
|
||||||
|
'getAll'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user