mirror of
https://github.com/ivuorinen/palette.git
synced 2026-01-26 03:24:08 +00:00
Updated tests, added phpcs
This commit is contained in:
2
.github/workflows/php.yml
vendored
2
.github/workflows/php.yml
vendored
@@ -36,4 +36,4 @@ jobs:
|
||||
# Docs: https://getcomposer.org/doc/articles/scripts.md
|
||||
|
||||
- name: Run test suite
|
||||
run: vendor/bin/phpunit
|
||||
run: composer run-script test
|
||||
|
||||
@@ -19,10 +19,19 @@
|
||||
"psr-0": { "ivuorinen\\Palette\\": "src/" },
|
||||
"classmap": ["src/"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-0": {
|
||||
"ivuorinen\\Palette\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "9.5.21"
|
||||
"phpunit/phpunit": "9.5.21",
|
||||
"squizlabs/php_codesniffer": "^3.7"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
}
|
||||
}
|
||||
|
||||
21
phpcs.xml.dist
Normal file
21
phpcs.xml.dist
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset
|
||||
name="PHP_CodeSniffer"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
|
||||
>
|
||||
<description>PHP Code Sniffer configuration file.</description>
|
||||
|
||||
<file>.</file>
|
||||
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="colors"/>
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="parallel" value="10"/>
|
||||
|
||||
<!-- base rule: set to PSR12-->
|
||||
<!-- https://www.php-fig.org/psr/psr-12/ -->
|
||||
<rule ref="PSR12">
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
</rule>
|
||||
</ruleset>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user