Files
pcm-icon-bundle/tests/Config/ConfigurationTest.php
2023-05-31 11:38:58 +01:00

89 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Pcm\IconBundle\Tests\Config;
use Pcm\IconBundle\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends TestCase
{
private Configuration $configuration;
private Processor $processor;
protected function setUp(): void
{
$this->configuration = new Configuration();
$this->processor = new Processor();
}
public function testThrowsIfDirectoriesIsEmpty()
{
$config = $this->getValidConfig();
$config['directories'] = [];
$this->expectExceptionMessage("Directories cannot be empty!");
$this->validateConfig($config);
}
public function testThrowsIfDirectoryIsNotFound(): void
{
$config = $this->getValidConfig();
$fakeDir = "abc/def/ghi";
$config['directories'] = [$fakeDir];
$this->expectExceptionMessage("\"abc\/def\/ghi\" is not a directory!");
$this->validateConfig($config);
}
public function testThrowsIfNoColoursExist(): void
{
$config = $this->getValidConfig();
$config['colours'] = [];
$this->expectExceptionMessage("Colours cannot be empty!");
$this->validateConfig($config);
}
public function testThrowsIfColourHasMissingClass(): void
{
$config = $this->getValidConfig();
unset($config['colours']['primary']['fill']);
$this->expectException(\Exception::class);
$this->validateConfig($config);
}
public function testThrowsIfColourHasExtraClass(): void
{
$config = $this->getValidConfig();
$config['colours']['primary']['extra'] = "test";
$this->expectException(\Exception::class);
$this->validateConfig($config);
}
private function validateConfig(array $config): void
{
$this->processor->processConfiguration($this->configuration, [$config]);
}
private function getValidConfig(): array
{
return [
'directories' => [
'./',
],
'colours' => [
'primary' => [
'fill' => 'fill-primary',
'stroke' => 'stroke-primary',
'fill-hover' => 'hover:fill-primary',
'stroke-hover' => 'hover:stroke-primary',
'fill-group-hover' => 'group-hover:fill-primary',
'stroke-group-hover' => 'group-hover:stroke-primary',
],
],
];
}
}