Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
f3ae2334e5 | |||
b7cc4d70ba | |||
2408572bae | |||
7fc781af80 | |||
90b8a71e12 | |||
6ab8a5c0f3 | |||
5856469068 | |||
f31f766cfa | |||
c07fb6c714 |
@ -1,13 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->in(__DIR__)
|
||||
;
|
||||
|
||||
$header = <<<EOF
|
||||
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
|
||||
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 <info@shopmodule.com>
|
||||
@link https://www.oxidmodule.com
|
||||
EOF;
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
return $config->setRules([
|
||||
'@PHP80Migration' => true,
|
||||
'@PSR12' => true
|
||||
'@PSR12' => true,
|
||||
'header_comment' => [
|
||||
'comment_type' => 'PHPDoc',
|
||||
'header' => $header,
|
||||
'location' => 'after_open',
|
||||
'separate' => 'both',
|
||||
],
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
||||
;
|
@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased](https://git.d3data.de/D3Public/DIContainer/compare/2.1.0.0...rel_2.x)
|
||||
## [Unreleased](https://git.d3data.de/D3Public/DIContainer/compare/2.1.1.0...rel_2.x)
|
||||
|
||||
## [2.1.1.0](https://git.d3data.de/D3Public/DIContainer/compare/2.1.0.0...2.1.1.0) - 2024-08-30
|
||||
### Changed
|
||||
- ensure that an uncompiled instance weren't changed by a compiled one
|
||||
|
||||
## [2.1.0.0](https://git.d3data.de/D3Public/DIContainer/compare/2.0.0.0...2.1.0.0) - 2024-06-05
|
||||
### Changed
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
@ -33,7 +35,7 @@ function d3GetOxidDIC(): Container
|
||||
{
|
||||
try {
|
||||
return d3GetOxidDIC_withExceptions();
|
||||
// @codeCoverageIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (d3DicException $exception) {
|
||||
trigger_error($exception->getMessage(), E_USER_ERROR);
|
||||
}
|
||||
|
@ -31,7 +31,8 @@
|
||||
"friendsofphp/php-cs-fixer": "~3.13.0",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"rector/rector": "^0.18.13",
|
||||
"mikey179/vfsstream": "^1.6.8"
|
||||
"mikey179/vfsstream": "^1.6.8",
|
||||
"infection/infection": "^0.29.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -41,14 +42,22 @@
|
||||
"autoload/functions_oxDIC.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"D3\\DIContainerHandler\\tests": "./tests"
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"phpstan-report": "./vendor/bin/phpstan --configuration=vendor/d3/ordermanager/phpstan.neon analyse --error-format=json > reports/phpstan/oxid-dic-handler/phpstan.report.json",
|
||||
|
||||
"phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/",
|
||||
"phpunit-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/ --coverage-html=vendor/d3/oxid-dic-handler/tests/result/coverage",
|
||||
"phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --config=vendor/d3/oxid-dic-handler/tests/ --no-coverage",
|
||||
"phpunit-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --config=vendor/d3/oxid-dic-handler/tests/ --coverage-html=reports/phpunit/oxid-dic-handler",
|
||||
"phpunit-path-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --config=vendor/d3/oxid-dic-handler/tests/ --coverage-html=reports/phpunit/oxid-dic-handler --path-coverage",
|
||||
|
||||
"infection": "./vendor/bin/infection --configuration=vendor/d3/oxid-dic-handler/infection.json5",
|
||||
|
||||
"rector": "./vendor/bin/rector process --dry-run --config ./vendor/d3/oxid-dic-handler/rector.php"
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
@ -19,7 +21,6 @@ use d3DIContainerCache;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Facts\Config\ConfigFile;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
@ -49,6 +50,7 @@ class d3DicHandler implements d3DicHandlerInterface
|
||||
*/
|
||||
public static function getUncompiledInstance(): Container
|
||||
{
|
||||
if (self::$_instance !== null && self::$_instance->isCompiled()) {self::removeInstance();}
|
||||
return oxNew(d3DicHandler::class)->createInstance(false);
|
||||
}
|
||||
|
||||
@ -176,6 +178,6 @@ class d3DicHandler implements d3DicHandlerInterface
|
||||
|
||||
public function getPhpDumper(ContainerBuilder $containerBuilder): PhpDumper
|
||||
{
|
||||
return new PhpDumper( $containerBuilder);
|
||||
return new PhpDumper($containerBuilder);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
@ -38,8 +40,8 @@ class d3DicUtilities
|
||||
);
|
||||
}
|
||||
|
||||
public static function getVendorDir(): string
|
||||
public static function getVendorDir($current = __FILE__): string
|
||||
{
|
||||
return rtrim(dirname(__FILE__, 3), '/') . '/';
|
||||
return dirname($current, 3). '/';
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
@ -37,7 +39,7 @@ class definitionFileContainer
|
||||
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');
|
||||
Assert::that(dirname(__FILE__, 3).'/'.$definitionFile)->file('invalid definition file');
|
||||
|
||||
$this->definitionFiles[$type][md5($definitionFile)] = $definitionFile;
|
||||
}
|
||||
|
35
infection.json5
Normal file
35
infection.json5
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"source": {
|
||||
"directories": [
|
||||
"vendor/d3/oxid-dic-handler"
|
||||
],
|
||||
"excludes": [
|
||||
".php-cs-fixer.php",
|
||||
"rector.php",
|
||||
"tests"
|
||||
]
|
||||
},
|
||||
"timeout": 60,
|
||||
"logs": {
|
||||
"text": "../../../reports/infection/d3DICHandler/infection.log",
|
||||
"html": "../../../reports/infection/d3DICHandler/infection.html",
|
||||
"summary": "../../../reports/infection/d3DICHandler/summary.log",
|
||||
"json": "../../../reports/infection/d3DICHandler/infection-log.json",
|
||||
"perMutator": "../../../reports/infection/d3DICHandler/per-mutator.md",
|
||||
"summaryJson": "../../../reports/infection/d3DICHandler/summary.json"
|
||||
},
|
||||
"tmpDir": "./infection/tmp",
|
||||
"phpUnit": {
|
||||
"configDir": "tests"
|
||||
},
|
||||
"mutators": {
|
||||
"@default": true,
|
||||
"@function_signature": false,
|
||||
"global-ignoreSourceCodeByRegex": [
|
||||
".*\\sstartProfile\\(.*",
|
||||
".*\\sstopProfile\\(.*"
|
||||
]
|
||||
},
|
||||
"testFramework":"phpunit",
|
||||
"bootstrap":"source/bootstrap.php"
|
||||
}
|
13
rector.php
13
rector.php
@ -1,5 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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 <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
backupGlobals="true"
|
||||
backupStaticAttributes="false"
|
||||
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||
bootstrap="../../../../source/bootstrap.php"
|
||||
colors="false"
|
||||
backupStaticAttributes="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="false"
|
||||
convertWarningsToExceptions="true"
|
||||
@ -13,8 +13,14 @@
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||
verbose="false"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory>unit/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">../</directory>
|
||||
@ -25,9 +31,4 @@
|
||||
<file>../.php-cs-fixer.php</file>
|
||||
</exclude>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory>unit/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DIContainerHandler\tests\autoload;
|
||||
namespace D3\DIContainerHandler\tests\unit\autoload;
|
||||
|
||||
use D3\DIContainerHandler\d3DicException;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DIContainerHandler\tests;
|
||||
namespace D3\DIContainerHandler\tests\unit;
|
||||
|
||||
use D3\DIContainerHandler\d3DicException;
|
||||
use InvalidArgumentException;
|
||||
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DIContainerHandler\tests;
|
||||
namespace D3\DIContainerHandler\tests\unit;
|
||||
|
||||
use D3\DIContainerHandler\d3DicException;
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
@ -39,7 +41,7 @@ class d3DicHandlerTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
d3DicHandler::removeInstance();
|
||||
d3DicHandler::removeInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,6 +89,7 @@ class d3DicHandlerTest extends TestCase
|
||||
{
|
||||
$sut = new d3DicHandler();
|
||||
|
||||
// test new instance
|
||||
$containerBuilder = $this->callMethod(
|
||||
$sut,
|
||||
'getUncompiledInstance'
|
||||
@ -98,6 +101,22 @@ class d3DicHandlerTest extends TestCase
|
||||
);
|
||||
|
||||
$this->assertFalse($containerBuilder->isCompiled());
|
||||
|
||||
// test if compiled instance is getting resetted
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'removeInstance'
|
||||
);
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getInstance'
|
||||
);
|
||||
|
||||
$containerBuilder = $this->callMethod(
|
||||
$sut,
|
||||
'getUncompiledInstance'
|
||||
);
|
||||
$this->assertFalse($containerBuilder->isCompiled());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,27 +149,30 @@ class d3DicHandlerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param bool $throwException
|
||||
* @param bool $expectException
|
||||
* @param bool $throwException
|
||||
* @param bool $expectException
|
||||
* @param string $circularReferenceMethod
|
||||
*
|
||||
* @param string $expectedExceptionMessage
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\DIContainerHandler\d3DicHandler::createInstance
|
||||
* @covers \D3\DIContainerHandler\d3DicHandler::createInstance
|
||||
* @dataProvider canCreateInstanceDataProvider
|
||||
*/
|
||||
public function canCreateInstance(bool $throwException, bool $expectException, string $circularReferenceMethod = '')
|
||||
public function canCreateInstance(bool $throwException, bool $expectException, string $circularReferenceMethod = '', string $expectedExceptionMessage = ''): void
|
||||
{
|
||||
/** @var d3DicHandler|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||
->onlyMethods(['buildContainer', 'getFunctionNameFromTrace'])
|
||||
->getMock();
|
||||
if ($throwException)
|
||||
$sut->method( 'buildContainer' )->willThrowException( new Exception( 'fixture' ) );
|
||||
if ($throwException) {
|
||||
$sut->method('buildContainer')->willThrowException(new Exception('fixture'));
|
||||
}
|
||||
|
||||
$sut->method('getFunctionNameFromTrace')->willReturn($circularReferenceMethod);
|
||||
if ($expectException)
|
||||
if ($expectException) {
|
||||
$this->expectException(d3DicException::class);
|
||||
$this->expectExceptionMessage($expectedExceptionMessage);
|
||||
}
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
@ -161,8 +183,8 @@ class d3DicHandlerTest extends TestCase
|
||||
public function canCreateInstanceDataProvider(): Generator
|
||||
{
|
||||
yield "don't throw exception" => [false, false];
|
||||
yield "throw exception" => [true, true];
|
||||
yield "has circular reference method name" => [false, true, 'getViewConfig'];
|
||||
yield "throw exception" => [true, true, '', 'fixture'];
|
||||
yield "has circular reference method name" => [false, true, 'getViewConfig', 'method getViewConfig can\'t use DIC due the danger of circular reference'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,13 +352,13 @@ class d3DicHandlerTest extends TestCase
|
||||
* @test
|
||||
* @param bool $useCacheContainer
|
||||
* @param bool $compile
|
||||
*
|
||||
* @param bool $useDefault
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider buildContainerTestDataProvider
|
||||
* @covers \D3\DIContainerHandler\d3DicHandler::buildContainer
|
||||
*/
|
||||
public function buildContainerTest(bool $useCacheContainer, bool $compile): void
|
||||
public function buildContainerTest(bool $useCacheContainer, bool $compile, bool $useDefault = false): void
|
||||
{
|
||||
$structure = [
|
||||
'source_directory' => [],
|
||||
@ -352,26 +374,46 @@ class d3DicHandlerTest extends TestCase
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(get_class_methods(PhpDumper::class))
|
||||
->getMock();
|
||||
$phpDumperMock->expects($this->exactly((int) (!$useCacheContainer && $compile)))->method('dump');
|
||||
$phpDumperMock->expects($this->exactly((int) (!$useCacheContainer && $compile)))->method('dump')->willReturn('fixture');
|
||||
|
||||
/** @var d3DicHandler|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||
->onlyMethods(['d3UseCachedContainer', 'd3GetCacheContainer', 'getContainerBuilder', 'd3GetCacheFilePath', 'getPhpDumper'])
|
||||
->onlyMethods(
|
||||
[
|
||||
'd3UseCachedContainer', 'd3GetCacheContainer', 'getContainerBuilder',
|
||||
'loadFiles','d3GetCacheFilePath', 'getPhpDumper'
|
||||
])
|
||||
->getMock();
|
||||
$sut->expects($this->once())->method('d3UseCachedContainer')->willReturn($useCacheContainer);
|
||||
$sut->expects($this->exactly((int) $useCacheContainer))->method('d3GetCacheContainer');
|
||||
$sut->expects($this->exactly((int) !$useCacheContainer))->method('getContainerBuilder')->willReturn($containerBuilderMock);
|
||||
$sut->method('d3GetCacheFilePath')->willReturn($fsRoot->getChild('source_directory')->path().'/DIContainer.php');
|
||||
$sut->expects($this->exactly((int) !$useCacheContainer))->method('loadFiles');
|
||||
$sut->method('d3GetCacheFilePath')->willReturn($fsRoot->getChild('source_directory')->url().'/DIContainer.php');
|
||||
$sut->method('getPhpDumper')->willReturn($phpDumperMock);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Container::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'buildContainer',
|
||||
[$compile]
|
||||
)
|
||||
);
|
||||
$useDefault ?
|
||||
$this->assertInstanceOf(
|
||||
Container::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'buildContainer'
|
||||
)
|
||||
):
|
||||
$this->assertInstanceOf(
|
||||
Container::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'buildContainer',
|
||||
[$compile]
|
||||
)
|
||||
);
|
||||
|
||||
if (!$useCacheContainer && $compile) {
|
||||
$this->assertSame(
|
||||
'fixture',
|
||||
file_get_contents($fsRoot->getChild('source_directory')->url() . '/DIContainer.php')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function buildContainerTestDataProvider(): Generator
|
||||
@ -379,6 +421,7 @@ class d3DicHandlerTest extends TestCase
|
||||
yield "can't use cached container, do compile" => [false, true];
|
||||
yield "can't use cached container, don't compile" => [false, false];
|
||||
yield "use cached container" => [true, false];
|
||||
yield "can't use cached container, do compile, default" => [false, true, true];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -400,7 +443,7 @@ class d3DicHandlerTest extends TestCase
|
||||
->onlyMethods(['isProductiveMode', 'getConfigParam'])
|
||||
->getMock();
|
||||
$configMock->method('isProductiveMode')->willReturn($productive);
|
||||
$configMock->method('getConfigParam')->willReturnMap([['iDebug', NULL, $debug]]);
|
||||
$configMock->method('getConfigParam')->willReturnMap([['iDebug', null, $debug]]);
|
||||
|
||||
/** @var d3DicHandler|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(d3DicHandler::class)
|
||||
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DIContainerHandler\tests;
|
||||
namespace D3\DIContainerHandler\tests\unit;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\DIContainerHandler\d3DicUtilities;
|
||||
@ -88,16 +90,30 @@ class d3DicUtilitiesTest extends TestCase
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\DIContainerHandler\d3DicUtilities::getVendorDir()
|
||||
* @dataProvider getVendorDirTestDataProvider
|
||||
*/
|
||||
public function getVendorDirTest(): void
|
||||
public function getVendorDirTest(string $path): void
|
||||
{
|
||||
$sut = oxNew(d3DicUtilities::class);
|
||||
|
||||
$vendorDir = (string) $this->callMethod(
|
||||
$sut,
|
||||
'getVendorDir',
|
||||
[$path]
|
||||
);
|
||||
|
||||
$this->assertSame('/var/www/html/vendor/', $vendorDir);
|
||||
$this->assertDirectoryExists(
|
||||
(string) $this->callMethod(
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getVendorDir'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getVendorDirTestDataProvider(): Generator
|
||||
{
|
||||
yield 'default' => ['/var/www/html/vendor/d3/oxid-dic-handler/d3DicUtilities.php'];
|
||||
yield 'space after' => ['/var/www/html/vendor/d3/oxid-dic-handler/d3DicUtilities.php '];
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* 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>
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DIContainerHandler\tests;
|
||||
namespace D3\DIContainerHandler\tests\unit;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\DIContainerHandler\definitionFileContainer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user