Validate args

This commit is contained in:
Brabli
2022-08-14 18:53:20 +01:00
parent 55c61558c7
commit 9a95804f3c
2 changed files with 64 additions and 6 deletions

View File

@@ -10,11 +10,24 @@ use Pcm\IconBundle\Tests\TestKernel;
use Pcm\IconBundle\Twig\Functions\IconExtension;
use Pcm\IconBundle\Twig\Functions\IconNotFound;
use PHPUnit\Framework\TestCase;
use TypeError;
class IconExtensionTest extends TestCase
{
private const ICON = 'test';
private const PALLETES = [
'primary' => [
'stroke' => 'stroke-primary',
'fill' => 'fill-primary'
],
'white' => [
'stroke' => 'stroke-white',
'fill' => 'fill-white'
],
];
/**
* @var IconExtension
*/
@@ -22,7 +35,7 @@ class IconExtensionTest extends TestCase
protected function setUp(): void
{
$this->icon = new IconExtension(['tests/icons']);
$this->icon = new IconExtension(['tests/icons'], self::PALLETES);
}
public function testInstanceOf(): void
@@ -33,20 +46,19 @@ class IconExtensionTest extends TestCase
public function testThrowsIfDirectoriesIsEmpty(): void
{
$this->expectException(\InvalidArgumentException::class);
new IconExtension([]);
new IconExtension([], self::PALLETES);
}
public function testThrowsIfDirectoriesContainsNonString(): void
{
$this->expectException(\TypeError::class);
new IconExtension([99]);
new IconExtension([99], self::PALLETES);
}
public function testThrowsIfDirectoriesContainsNonStringAmongStrings(): void
{
$this->expectException(\TypeError::class);
new IconExtension(['string', 99, 'string']);
new IconExtension(['string', 99, 'string'], self::PALLETES);
}
public function testThrowsWhenPassedAnInvalidIconName(): void
@@ -152,4 +164,34 @@ class IconExtensionTest extends TestCase
$timesMatched = preg_match_all($heightRegex, $content);
$this->assertSame(1, $timesMatched);
}
public function testThrowsIfPalletsIsEmpty(): void
{
$this->expectException(\InvalidArgumentException::class);
new IconExtension(['/'], []);
}
public function testThrowsIfPalletesContainsNonArray(): void
{
$this->expectException(\TypeError::class);
new IconExtension(['/'], [99]);
}
public function testThrowsIfPalletesContainsNonArrayInbetweenArrays(): void
{
$this->expectException(\TypeError::class);
new IconExtension(['/'], [[], 99, []]);
}
public function testThrowsIfChildArrayDoesntContainStrokeKey(): void
{
$this->expectException(\Exception::class);
new IconExtension(['/'], [['fill' => '']]);
}
public function testThrowsIfChildArrayDoesntContainFillKey(): void
{
$this->expectException(\Exception::class);
new IconExtension(['/'], [['stroke' => '']]);
}
}