Skip to content

Commit 9529eed

Browse files
committed
More tests
1 parent 941816a commit 9529eed

5 files changed

Lines changed: 145 additions & 14 deletions

File tree

phpunit.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
<phpunit
33
bootstrap="vendor/autoload.php"
44
colors="true"
5-
displayDetailsOnTestsThatTriggerDeprecations="true"
6-
displayDetailsOnTestsThatTriggerErrors="true"
7-
displayDetailsOnTestsThatTriggerNotices="true"
8-
displayDetailsOnTestsThatTriggerWarnings="true"
5+
cacheResult ="false"
6+
displayDetailsOnAllIssues="true"
97
>
108
<php>
119
<const name="_DEBUG_LEVEL" value="0"/>

tests/GhostscriptParametersTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
use Fawno\Ghostscript\GhostscriptParameters;
77

88
class GhostscriptParametersTest extends TestCase {
9-
public function testCreateParameters () : void {
9+
public function testDefaultParameters () : void {
1010
$params = GhostscriptParameters::create();
1111

1212
$this->assertInstanceOf(GhostscriptParameters::class, $params);
1313

1414
$params = $params->getParameters();
1515
$this->assertIsArray($params);
16-
$this->assertCount(8, $params);
17-
$this->assertContains('-dQUIET', $params);
18-
$this->assertContains('-dSAFER', $params);
19-
$this->assertContains('-dBATCH', $params);
20-
$this->assertContains('-dNOPAUSE', $params);
21-
$this->assertContains('-sDEVICE=pdfwrite', $params);
22-
$this->assertContains('-dPDFSETTINGS=/ebook', $params);
23-
$this->assertContains('-dCompatibilityLevel=1.4', $params);
24-
$this->assertContains('-dProcessColorModel=/DeviceRGB', $params);
16+
$this->assertEquals([
17+
'-dQUIET',
18+
'-dSAFER',
19+
'-dBATCH',
20+
'-dNOPAUSE',
21+
'-sDEVICE=pdfwrite',
22+
'-dPDFSETTINGS=/ebook',
23+
'-dCompatibilityLevel=1.4',
24+
'-dProcessColorModel=/DeviceRGB',
25+
], $params);
2526
}
2627
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fawno\PDFOptimizer\Tests\Parameters;
5+
6+
use Fawno\PDFOptimizer\Tests\TestCase;
7+
use ReflectionClass;
8+
use ReflectionNamedType;
9+
use ReflectionProperty;
10+
use ReflectionUnionType;
11+
12+
class TestParameterCase extends TestCase {
13+
public function assertIsTrait (string $trait, string $message = '') : void {
14+
$trait = new ReflectionClass($trait);
15+
$this->assertTrue($trait->isTrait(), $message);
16+
}
17+
18+
public function assertClassHasProperty (string $class, string $expected) : void {
19+
new ReflectionProperty($class, $expected);
20+
}
21+
22+
public function assertClassPropertyIsType (string $class, string $name, string|array $expected) : void {
23+
$expected = is_string($expected) ? [$expected] : $expected;
24+
25+
$property = new ReflectionProperty($class, $name);
26+
$type = $property->getType();
27+
28+
if (($type = $property->getType()) instanceof ReflectionUnionType) {
29+
$actual = array_map(function(ReflectionNamedType $t) {
30+
return $t->getName();
31+
}, $type->getTypes());
32+
} else {
33+
$actual = [$type->getName()];
34+
if ($type->allowsNull()) {
35+
$actual[] = 'null';
36+
}
37+
}
38+
39+
$this->assertEquals($expected, $actual);
40+
}
41+
}

tests/Parameters/dQUIETTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fawno\PDFOptimizer\Tests\Parameters;
5+
6+
use Fawno\Ghostscript\GhostscriptParameters;
7+
use Fawno\Ghostscript\Parameters\dQUIET;
8+
9+
class dQUIETTest extends TestParameterCase {
10+
public function testdQUIETTrait () : void {
11+
$this->assertIsTrait(dQUIET::class);
12+
$this->assertClassHasProperty(dQUIET::class, 'dQUIET');
13+
$this->assertClassPropertyIsType(dQUIET::class, 'dQUIET', 'bool');
14+
}
15+
16+
public function testdQUIETDefault () : void {
17+
$params = GhostscriptParameters::create();
18+
19+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
20+
21+
$params = $params->getParameters();
22+
$this->assertIsArray($params);
23+
$this->assertContains('-dQUIET', $params);
24+
}
25+
26+
public function testdQUIETTrue () : void {
27+
$params = GhostscriptParameters::create()->quiet(true);
28+
29+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
30+
31+
$params = $params->getParameters();
32+
$this->assertIsArray($params);
33+
$this->assertContains('-dQUIET', $params);
34+
}
35+
36+
public function testdQUIETFalse () : void {
37+
$params = GhostscriptParameters::create()->quiet(false);
38+
39+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
40+
41+
$params = $params->getParameters();
42+
$this->assertIsArray($params);
43+
$this->assertNotContains('-dQUIET', $params);
44+
}
45+
}

tests/Parameters/sDEVICETest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fawno\PDFOptimizer\Tests\Parameters;
5+
6+
use Fawno\Ghostscript\GhostscriptParameters;
7+
use Fawno\Ghostscript\Parameters\Enums\sDEVICEEnum;
8+
use Fawno\Ghostscript\Parameters\sDEVICE;
9+
10+
class sDEVICETest extends TestParameterCase {
11+
public function testsDEVICETrait () : void {
12+
$this->assertIsTrait(sDEVICE::class);
13+
$this->assertClassHasProperty(sDEVICE::class, 'sDEVICE');
14+
$this->assertClassPropertyIsType(sDEVICE::class, 'sDEVICE', [sDEVICEEnum::class, 'null']);
15+
}
16+
17+
public function testsDEVICEDefault () : void {
18+
$params = GhostscriptParameters::create();
19+
20+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
21+
22+
$params = $params->getParameters();
23+
$this->assertIsArray($params);
24+
$this->assertContains('-sDEVICE=' . sDEVICEEnum::PDFWRITE->value, $params);
25+
}
26+
27+
public function testsDEVICENull () : void {
28+
$params = GhostscriptParameters::create()->device(null);
29+
30+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
31+
32+
$params = $params->getParameters();
33+
$this->assertIsArray($params);
34+
$this->assertNotContains('-sDEVICE=' . sDEVICEEnum::PDFWRITE->value, $params);
35+
}
36+
37+
public function testsDEVICEJPEG () : void {
38+
$params = GhostscriptParameters::create()->device(sDEVICEEnum::JPEG);
39+
40+
$this->assertInstanceOf(GhostscriptParameters::class, $params);
41+
42+
$params = $params->getParameters();
43+
$this->assertIsArray($params);
44+
$this->assertContains('-sDEVICE=' . sDEVICEEnum::JPEG->value, $params);
45+
}
46+
}

0 commit comments

Comments
 (0)