Fix Colour stuff and add a test.
This commit is contained in:
parent
dd318c7dfa
commit
8fe7744da1
8 changed files with 1587 additions and 9 deletions
5
.styleci.yml
Normal file
5
.styleci.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
preset: psr2
|
||||
|
||||
disabled:
|
||||
- unalign_double_arrow
|
||||
- unalign_equals
|
16
.travis.yml
Normal file
16
.travis.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
cache:
|
||||
directories:
|
||||
- vendor
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.2
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- composer install
|
||||
|
||||
script: ./vendor/bin/phpunit
|
|
@ -1,6 +1,10 @@
|
|||
# Misuzu
|
||||
[](https://travis-ci.org/flashwave/misuzu)
|
||||
[](https://styleci.io/repos/114177358)
|
||||
[](https://www.codefactor.io/repository/github/flashwave/misuzu)
|
||||
[](https://packagist.org/packages/flashwave/misuzu)
|
||||
|
||||
## Requirement
|
||||
## Requirements
|
||||
- PHP 7.2
|
||||
- MySQL
|
||||
- Redis
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
"swiftmailer/swiftmailer": "~6.0",
|
||||
"erusev/parsedown": "~1.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Misuzu\\": "src/"
|
||||
|
|
1462
composer.lock
generated
1462
composer.lock
generated
File diff suppressed because it is too large
Load diff
17
phpunit.xml
Normal file
17
phpunit.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="misuzu.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Misuzu Tests">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
|
@ -23,9 +23,6 @@ class Colour {
|
|||
case 'blue':
|
||||
return $this->rawValue & 0xFF;
|
||||
|
||||
case 'none':
|
||||
return new static(self::INHERIT);
|
||||
|
||||
case 'hex':
|
||||
return dechex_pad($this->red) . dechex_pad($this->green) . dechex_pad($this->blue);
|
||||
}
|
||||
|
@ -95,10 +92,9 @@ class Colour {
|
|||
$hex = ltrim(strtolower($hex), '#');
|
||||
$hex_length = strlen($hex);
|
||||
|
||||
if ($hex_length == 3)
|
||||
if ($hex_length === 3)
|
||||
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
|
||||
|
||||
if ($hex_length != 6)
|
||||
elseif ($hex_length != 6)
|
||||
throw new \Exception('Invalid hex colour format! (find a more appropiate exception type)');
|
||||
|
||||
return static::fromRGB(
|
||||
|
@ -108,6 +104,10 @@ class Colour {
|
|||
);
|
||||
}
|
||||
|
||||
public static function none(): Colour {
|
||||
return new static(static::INHERIT);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return "#{$this->hex}";
|
||||
}
|
||||
|
|
75
tests/ColourTest.php
Normal file
75
tests/ColourTest.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use Misuzu\Colour;
|
||||
|
||||
class ColourTest extends TestCase {
|
||||
public const RED_HEX6 = 67;
|
||||
public const GREEN_HEX6 = 45;
|
||||
public const BLUE_HEX6 = 23;
|
||||
public const SSTR_HEX6 = '#432d17';
|
||||
public const STR_HEX6 = '432d17';
|
||||
public const RAW_HEX6 = 4402455;
|
||||
|
||||
public const RED_HEX3 = 51;
|
||||
public const GREEN_HEX3 = 136;
|
||||
public const BLUE_HEX3 = 221;
|
||||
public const SSTR_HEX3 = '#38d';
|
||||
public const STR_HEX3 = '3388dd';
|
||||
public const RAW_HEX3 = 3377373;
|
||||
|
||||
public function testNone() {
|
||||
$colour = Colour::none();
|
||||
|
||||
$this->assertTrue($colour->inherit);
|
||||
$this->assertEquals($colour->raw, 0x40000000);
|
||||
$this->assertEquals($colour->red, 0);
|
||||
$this->assertEquals($colour->green, 0);
|
||||
$this->assertEquals($colour->blue, 0);
|
||||
$this->assertEquals($colour->hex, '000000');
|
||||
}
|
||||
|
||||
public function testFromRaw() {
|
||||
$colour = new Colour(static::RAW_HEX6);
|
||||
|
||||
$this->assertEquals($colour->hex, static::STR_HEX6);
|
||||
$this->assertEquals($colour->raw, static::RAW_HEX6);
|
||||
$this->assertEquals($colour->red, static::RED_HEX6);
|
||||
$this->assertEquals($colour->green, static::GREEN_HEX6);
|
||||
$this->assertEquals($colour->blue, static::BLUE_HEX6);
|
||||
$this->assertFalse($colour->inherit);
|
||||
}
|
||||
|
||||
public function testFromRGB() {
|
||||
$colour = Colour::fromRGB(static::RED_HEX6, static::GREEN_HEX6, static::BLUE_HEX6);
|
||||
|
||||
$this->assertEquals($colour->hex, static::STR_HEX6);
|
||||
$this->assertEquals($colour->raw, static::RAW_HEX6);
|
||||
$this->assertEquals($colour->red, static::RED_HEX6);
|
||||
$this->assertEquals($colour->green, static::GREEN_HEX6);
|
||||
$this->assertEquals($colour->blue, static::BLUE_HEX6);
|
||||
$this->assertFalse($colour->inherit);
|
||||
}
|
||||
|
||||
public function testFromHex() {
|
||||
$colour = Colour::fromHex(static::SSTR_HEX6);
|
||||
|
||||
$this->assertEquals($colour->hex, static::STR_HEX6);
|
||||
$this->assertEquals($colour->raw, static::RAW_HEX6);
|
||||
$this->assertEquals($colour->red, static::RED_HEX6);
|
||||
$this->assertEquals($colour->green, static::GREEN_HEX6);
|
||||
$this->assertEquals($colour->blue, static::BLUE_HEX6);
|
||||
$this->assertFalse($colour->inherit);
|
||||
}
|
||||
|
||||
public function testFromHex3() {
|
||||
$colour = Colour::fromHex(static::SSTR_HEX3);
|
||||
|
||||
$this->assertEquals($colour->hex, static::STR_HEX3);
|
||||
$this->assertEquals($colour->raw, static::RAW_HEX3);
|
||||
$this->assertEquals($colour->red, static::RED_HEX3);
|
||||
$this->assertEquals($colour->green, static::GREEN_HEX3);
|
||||
$this->assertEquals($colour->blue, static::BLUE_HEX3);
|
||||
$this->assertFalse($colour->inherit);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue