1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<?php
declare(strict_types=1);
namespace DI\Test\IntegrationTest;
use DI\CompiledContainer;
use DI\Container;
use DI\ContainerBuilder;
use PHPUnit\Framework\TestCase;
/**
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
abstract class BaseContainerTest extends TestCase
{
public const COMPILATION_DIR = __DIR__ . '/tmp';
public static function setUpBeforeClass(): void
{
// Clear all files
array_map('unlink', glob(self::COMPILATION_DIR . '/*'));
parent::setUpBeforeClass();
}
public function setUp(): void
{
// Clear all files
array_map('unlink', glob(self::COMPILATION_DIR . '/*'));
parent::setUp();
}
public static function provideContainer() : array
{
// Clear all files
array_map('unlink', glob(self::COMPILATION_DIR . '/*'));
return [
'not-compiled' => [
new ContainerBuilder,
],
'compiled' => [
(new ContainerBuilder)->enableCompilation(
self::COMPILATION_DIR,
self::generateCompiledClassName()
),
],
];
}
protected static function generateCompiledClassName(): string
{
return 'Container' . uniqid();
}
/**
* Assert that the given entry is compiled when we are testing the compiled container.
*/
protected static function assertEntryIsCompiled(Container $container, string $entry)
{
if (!$container instanceof CompiledContainer) {
return;
}
$compiledEntries = $container::METHOD_MAPPING;
self::assertArrayHasKey($entry, $compiledEntries, "Entry $entry is not compiled");
}
/**
* Assert that the given entry is not compiled when we are testing the compiled container.
*/
protected static function assertEntryIsNotCompiled(Container $container, string $entry)
{
if (!$container instanceof CompiledContainer) {
return;
}
$compiledEntries = $container::METHOD_MAPPING;
self::assertArrayNotHasKey($entry, $compiledEntries, "Entry $entry is compiled");
}
}
|