Erweiterung der Farbmodel-Tests. Dabei wurden mehrfach verwendete Methoden in eine eigene Klasse ausgelagert.

This commit is contained in:
2021-03-01 16:57:16 +01:00
parent 4300484e85
commit 22d2eaf5a3
4 changed files with 258 additions and 25 deletions
@@ -0,0 +1,36 @@
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
use Codeception\Test\Unit;
abstract class AbstractColorModelUnit extends Unit
{
abstract public function testConstruct();
/**
* @return float[][]
*/
public function invalidValueProvider(): array
{
return [
'zu klein' => [-0.1],
'zu gross' => [1.1],
];
}
/**
* @return float[][]
*/
public function validValueProvider(): array
{
return [
'niedrigster Wert' => [0.0],
'mittlerer Wert' => [0.45],
'maximaler Wert' => [1.0],
];
}
}
@@ -0,0 +1,124 @@
<?php
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
use InvalidArgumentException;
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
{
public function testConstruct()
{
$color = new CyanMagentaYellowKey();
$this->assertEquals(0.0, $color->getCyan());
$this->assertEquals(0.0, $color->getMagenta());
$this->assertEquals(0.0, $color->getYellow());
$this->assertEquals(0.0, $color->getKey());
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetCyanWithValidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$color->setCyan($value);
$this->assertEquals($value, $color->getCyan());
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetMagentaWithValidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$color->setMagenta($value);
$this->assertEquals($value, $color->getMagenta());
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetYellowWithValidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$color->setYellow($value);
$this->assertEquals($value, $color->getYellow());
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetKeyWithValidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$color->setKey($value);
$this->assertEquals($value, $color->getKey());
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetCyanWithInvalidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$this->expectException(InvalidArgumentException::class);
$color->setCyan($value);
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetMagentaWithInvalidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$this->expectException(InvalidArgumentException::class);
$color->setMagenta($value);
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetYellowWithInvalidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$this->expectException(InvalidArgumentException::class);
$color->setYellow($value);
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetKeyWithInvalidValue(float $value)
{
$color = new CyanMagentaYellowKey();
$this->expectException(InvalidArgumentException::class);
$color->setKey($value);
}
}
+1 -25
View File
@@ -2,11 +2,10 @@
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
use Codeception\Test\Unit;
use InvalidArgumentException;
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
class RedGreenBlueTest extends Unit
class RedGreenBlueTest extends AbstractColorModelUnit
{
public function testConstruct()
@@ -18,29 +17,6 @@ class RedGreenBlueTest extends Unit
$this->assertEquals(1.0, $color->getBlue());
}
/**
* @return float[][]
*/
public function invalidValueProvider(): array
{
return [
'zu klein' => [-0.1],
'zu gross' => [1.1],
];
}
/**
* @return float[][]
*/
public function validValueProvider(): array
{
return [
'niedrigster Wert' => [0.0],
'mittlerer Wert' => [0.45],
'maximaler Wert' => [1.0],
];
}
/**
* @param float $value
*