Adjust tests to bit boot kernel

This commit is contained in:
Brabli
2022-08-14 18:31:32 +01:00
parent a668ed2b84
commit 55c61558c7
2 changed files with 31 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pcm\IconBundle\Tests\Twig\Functions;
use InvalidArgumentException;
use Pcm\IconBundle\DependencyInjection\PcmIconExtension;
use Pcm\IconBundle\Tests\TestKernel;
use Pcm\IconBundle\Twig\Functions\IconExtension;
@@ -21,9 +22,7 @@ class IconExtensionTest extends TestCase
protected function setUp(): void
{
$kernel = new TestKernel('test', true);
$kernel->boot();
$this->icon = $kernel->getContainer()->get('pcm_icon.icon_extension');
$this->icon = new IconExtension(['tests/icons']);
}
public function testInstanceOf(): void
@@ -31,14 +30,23 @@ class IconExtensionTest extends TestCase
$this->assertInstanceOf(IconExtension::class, $this->icon);
}
public function testDirectoriesArrayGetsInjected(): void
public function testThrowsIfDirectoriesIsEmpty(): void
{
$reflection = new \ReflectionClass($this->icon);
$property = $reflection->getProperty('directories');
$directories = $property->getValue($this->icon);
$this->assertIsArray($directories);
$this->assertCount(1, $directories);
$this->assertStringContainsString('tests/icons', $directories[0]);
$this->expectException(\InvalidArgumentException::class);
new IconExtension([]);
}
public function testThrowsIfDirectoriesContainsNonString(): void
{
$this->expectException(\TypeError::class);
new IconExtension([99]);
}
public function testThrowsIfDirectoriesContainsNonStringAmongStrings(): void
{
$this->expectException(\TypeError::class);
new IconExtension(['string', 99, 'string']);
}
public function testThrowsWhenPassedAnInvalidIconName(): void