Updated tests, added phpcs

This commit is contained in:
Ismo Vuorinen
2022-06-26 18:40:33 +03:00
parent 1bd38c91a3
commit 264c35b39c
4 changed files with 53 additions and 18 deletions

View File

@@ -1,23 +1,27 @@
<?php
class PaletteTest extends \PHPUnit_Framework_TestCase
namespace ivuorinen\Palette\Tests;
use PHPUnit\Framework\TestCase;
class PaletteTest extends TestCase
{
public function test_class_is_found_and_has_default_attributes()
public function testClassIsFoundAndHasDefaultAttributes()
{
$palette = new \ivuorinen\Palette\Palette();
$this->assertInstanceOf('ivuorinen\Palette\Palette', $palette);
$this->assertInternalType('integer', $palette->precision);
$this->assertInternalType('integer', $palette->returnColors);
$this->assertInternalType('array', $palette->colorsArray);
$this->assertInternalType('null', $palette->filename);
$this->assertInternalType('string', $palette->destination);
$this->assertIsInt($palette->precision);
$this->assertIsInt($palette->returnColors);
$this->assertIsArray($palette->colorsArray);
$this->assertNull($palette->filename);
$this->assertIsString($palette->destination);
}
public function test_known_images_with_one_color()
public function testKnownImagesWithOneColor()
{
$location = __DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
$images = ['black.png' => '000000', 'red.png' => 'CC3333'];
$images = [ 'black.png' => '000000', 'red.png' => 'CC3333' ];
foreach ($images as $imageFile => $hex) {
$image = $location . $imageFile;
@@ -30,10 +34,10 @@ class PaletteTest extends \PHPUnit_Framework_TestCase
}
}
public function test_known_images_with_many_colors()
public function testKnownImagesWithManyColors()
{
$location = __DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
$images = ['example.gif', 'example.jpg', 'example.png'];
$images = [ 'example.gif', 'example.jpg', 'example.png' ];
foreach ($images as $imageFile) {
$image = $location . $imageFile;
@@ -45,20 +49,21 @@ class PaletteTest extends \PHPUnit_Framework_TestCase
}
}
public function test_failure_no_image()
public function testFailureNoImage()
{
$palette = new \ivuorinen\Palette\Palette('');
$this->expectException(ErrorException::class);
$this->expectException(\ErrorException::class);
$this->expectExceptionMessage('Image was not provided');
$palette->getPalette();
}
public function test_failure_not_an_image()
public function testFailureNotAnImage()
{
$palette = new \ivuorinen\Palette\Palette();
$palette = new \ivuorinen\Palette\Palette();
$palette->filename = 'NOT_HERE';
$this->expectException(ErrorException::class);
$this->expectException(\ErrorException::class);
$this->expectExceptionMessage('Image ' . $palette->filename . ' is not readable');
$palette->getPalette();
}
}