Skip to content

Commit 9e9aef8

Browse files
author
Andrei Tomita
committed
Added unit tests
1 parent a35006d commit 9e9aef8

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

References.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function color(string $color): string
133133
*/
134134
public function colorspace(string $colorspace): string
135135
{
136-
$colorspace = \mb_strtolower(\trim($colorspace));
136+
$colorspace = \trim($colorspace);
137137

138138
$references = $this->getColorspaceValuesReference();
139139

Tests/CommandTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,78 @@ public function testResizeImage(): void
6868
$this->testConvertIdentifyImage($imageOutput, 'JPEG', '100x94+0+0', '8-bit');
6969
}
7070

71+
public function testDepthImage(): void
72+
{
73+
$command = new Command(IMAGEMAGICK_DIR);
74+
75+
$imageToResize = $this->resourcesDir.'/moon_180.jpg';
76+
$imageOutput = $this->resourcesDir.'/outputs/moon.jpg';
77+
static::assertFileExists($imageToResize);
78+
79+
$response = $command
80+
->convert($imageToResize)
81+
->depth(1)
82+
->file($imageOutput, false)
83+
->run()
84+
;
85+
86+
static::assertFalse($response->hasFailed(), "Errors when testing:\n".$response->getProcess()->getOutput()."\t".$response->getProcess()->getErrorOutput());
87+
88+
static::assertFileExists($this->resourcesDir.'/outputs/moon.jpg');
89+
90+
static::assertFalse($response->hasFailed());
91+
92+
$this->testConvertIdentifyImage($imageOutput, 'JPEG', '180x170+0+0', '8-bit');
93+
}
94+
95+
public function testFlattenImage(): void
96+
{
97+
$command = new Command(IMAGEMAGICK_DIR);
98+
99+
$imageToResize = $this->resourcesDir.'/moon_180.jpg';
100+
$imageOutput = $this->resourcesDir.'/outputs/moon.jpg';
101+
static::assertFileExists($imageToResize);
102+
103+
$response = $command
104+
->convert($imageToResize)
105+
->flatten()
106+
->file($imageOutput, false)
107+
->run()
108+
;
109+
110+
static::assertFalse($response->hasFailed(), "Errors when testing:\n".$response->getProcess()->getOutput()."\t".$response->getProcess()->getErrorOutput());
111+
112+
static::assertFileExists($this->resourcesDir.'/outputs/moon.jpg');
113+
114+
static::assertFalse($response->hasFailed());
115+
116+
$this->testConvertIdentifyImage($imageOutput, 'JPEG', '180x170+0+0', '8-bit');
117+
}
118+
119+
public function testColorspaceImage(): void
120+
{
121+
$command = new Command(IMAGEMAGICK_DIR);
122+
123+
$imageToResize = $this->resourcesDir.'/moon_180.jpg';
124+
$imageOutput = $this->resourcesDir.'/outputs/moon.jpg';
125+
static::assertFileExists($imageToResize);
126+
127+
$response = $command
128+
->convert($imageToResize)
129+
->colorspace('Gray')
130+
->file($imageOutput, false)
131+
->run()
132+
;
133+
134+
static::assertFalse($response->hasFailed(), "Errors when testing:\n".$response->getProcess()->getOutput()."\t".$response->getProcess()->getErrorOutput());
135+
136+
static::assertFileExists($this->resourcesDir.'/outputs/moon.jpg');
137+
138+
static::assertFalse($response->hasFailed());
139+
140+
$this->testConvertIdentifyImage($imageOutput, 'JPEG', '180x170+0+0', '8-bit');
141+
}
142+
71143
/**
72144
* @dataProvider provideImagesToIdentify
73145
*/
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the OrbitaleImageMagickPHP package.
7+
*
8+
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Orbitale\Component\ImageMagick\Tests\References;
15+
16+
use Orbitale\Component\ImageMagick\References;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class ColorspaceValuesTest extends TestCase
20+
{
21+
/**
22+
* @var References
23+
*/
24+
private $ref;
25+
26+
public function __construct($name = null, array $data = [], $dataName = '')
27+
{
28+
parent::__construct($name, $data, $dataName);
29+
$this->ref = new References();
30+
}
31+
32+
/**
33+
* @param string $colorspaceValue
34+
* @param string $expected
35+
*
36+
* @dataProvider provideValidColorspaceValues
37+
*/
38+
public function testValidColorspaceValue($colorspaceValue, $expected): void
39+
{
40+
$validatedType = $this->ref->colorspace($colorspaceValue);
41+
42+
static::assertSame($expected, $validatedType);
43+
}
44+
45+
public function provideValidColorspaceValues(): ?\Generator
46+
{
47+
yield ['CMY', 'CMY'];
48+
yield ['CMYK', 'CMYK'];
49+
yield ['Gray', 'Gray'];
50+
yield ['HCL', 'HCL'];
51+
yield ['HCLp', 'HCLp'];
52+
yield ['HSB', 'HSB'];
53+
yield ['HSI', 'HSI'];
54+
}
55+
56+
/**
57+
* @dataProvider provideInvalidColorspaceValues
58+
*/
59+
public function testInvalidColorspaceValues($colorspaceValue): void
60+
{
61+
$colorspaceValue = (string) $colorspaceValue;
62+
63+
$msg = '';
64+
try {
65+
$this->ref->colorspace($colorspaceValue);
66+
} catch (\InvalidArgumentException $e) {
67+
$msg = $e->getMessage();
68+
}
69+
static::assertContains(
70+
\sprintf('The specified colorspace value (%s) is invalid', \trim($colorspaceValue)),
71+
$msg
72+
);
73+
}
74+
75+
public function provideInvalidColorspaceValues(): ?\Generator
76+
{
77+
yield [1];
78+
yield ['2'];
79+
yield ['wow'];
80+
yield ['WoW'];
81+
yield [''];
82+
yield [' '];
83+
}
84+
}

0 commit comments

Comments
 (0)