8
0
DIContainer/tests/unit/d3DicUtilitiesTest.php

120 Zeilen
3.3 KiB
PHP

2024-01-31 19:24:51 +01:00
<?php
/**
2024-06-15 23:10:49 +02:00
* 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.
2024-01-31 19:24:51 +01:00
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2024-06-15 23:10:49 +02:00
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
2024-01-31 19:24:51 +01:00
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
2024-06-16 00:01:36 +02:00
namespace D3\DIContainerHandler\tests\unit;
2024-01-31 19:24:51 +01:00
use D3\DIContainerHandler\d3DicHandler;
use D3\DIContainerHandler\d3DicUtilities;
2024-01-31 21:13:53 +01:00
use D3\TestingTools\Development\CanAccessRestricted;
2024-01-31 19:24:51 +01:00
use Generator;
use PHPUnit\Framework\TestCase;
use ReflectionException;
class d3DicUtilitiesTest extends TestCase
{
2024-01-31 21:13:53 +01:00
use CanAccessRestricted;
2024-01-31 19:24:51 +01:00
/**
* @test
2024-01-31 21:56:19 +01:00
*
2024-05-27 13:41:52 +02:00
* @param string $className
2024-01-31 19:24:51 +01:00
* @param string|null $additional
2024-05-27 13:41:52 +02:00
* @param string $expected
2024-01-31 19:24:51 +01:00
*
* @throws ReflectionException
2024-01-31 21:56:19 +01:00
* @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId
2024-01-31 19:24:51 +01:00
* @dataProvider getServiceIdTestDataProvider
*/
2024-02-19 08:36:41 +01:00
public function getServiceIdTest(string $className, ?string $additional, string $expected): void
2024-01-31 19:24:51 +01:00
{
$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
*/
2024-01-31 21:56:19 +01:00
public function getArgumentIdTest(string $className, string $argumentName, string $expected): void
2024-01-31 19:24:51 +01:00
{
$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()
2024-06-16 01:28:42 +02:00
* @dataProvider getVendorDirTestDataProvider
2024-01-31 19:24:51 +01:00
*/
2024-06-16 01:28:42 +02:00
public function getVendorDirTest(string $path): void
2024-01-31 19:24:51 +01:00
{
$sut = oxNew(d3DicUtilities::class);
2024-06-16 01:28:42 +02:00
$vendorDir = (string) $this->callMethod(
$sut,
'getVendorDir',
[$path]
);
$this->assertSame('/var/www/html/vendor/', $vendorDir);
2024-01-31 19:24:51 +01:00
$this->assertDirectoryExists(
2024-06-16 01:28:42 +02:00
$this->callMethod(
2024-01-31 19:24:51 +01:00
$sut,
'getVendorDir'
)
);
}
2024-06-16 01:28:42 +02:00
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 '];
}
2024-01-31 21:13:53 +01:00
}