Skip to content

Commit fd2f344

Browse files
committed
Add tests for the -threshold option.
1 parent d2ae78b commit fd2f344

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

Tests/References/ThresholdTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 ThresholdTest 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+
* @dataProvider provideValidThresholdValues
34+
*/
35+
public function testValidThreshold(string $value): void
36+
{
37+
$threshold = $this->ref->threshold($value);
38+
39+
self::assertSame($threshold, $value);
40+
}
41+
42+
public function provideValidThresholdValues(): \Generator
43+
{
44+
yield '100' => ['100'];
45+
yield '-100' => ['-100'];
46+
yield '0' => ['0'];
47+
yield '100%' => ['100%'];
48+
yield '-100%' => ['-100%'];
49+
yield '0%' => ['0%'];
50+
}
51+
52+
/**
53+
* @dataProvider provideInvalidThresholdValues
54+
*/
55+
public function testInvalidThreshold(string $value): void
56+
{
57+
$this->expectException(\InvalidArgumentException::class);
58+
$this->expectExceptionMessage(\sprintf(
59+
'The specified threshold parameter (%s) is invalid.'."\n".'The value must be an integer or a percentage value'."\n".'Please refer to ImageMagick command line documentation:'."\n%s",
60+
$value,
61+
'http://www.imagemagick.org/script/command-line-options.php#threshold'
62+
));
63+
64+
$this->ref->threshold($value);
65+
}
66+
67+
public function provideInvalidThresholdValues(): \Generator
68+
{
69+
yield 'Empty string' => [''];
70+
yield 'a' => ['a'];
71+
yield '-' => ['-'];
72+
yield '.' => ['.'];
73+
yield '1_00' => ['1_00'];
74+
yield '%' => ['%'];
75+
yield 'a%' => ['a%'];
76+
yield '-%' => ['-%'];
77+
yield '.%' => ['.%'];
78+
yield '1_00%' => ['1_00%'];
79+
}
80+
}

0 commit comments

Comments
 (0)