Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heiglandreas committed Aug 1, 2024
1 parent 35d22e6 commit 544f779
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"description": "A PHP-Wrapper around the Ghostscript-CLI",
"type": "library",
"license": "MIT",
"require": {
"php": "7.4|^8.0"
},
"authors": [
{
"name": "Andreas Heigl",
Expand Down
36 changes: 12 additions & 24 deletions tests/GhostscriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ public function testForNonEmptyGhostscriptPath()
$this->assertNotEquals(null, $path);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSettingFileWorks()
{
$this->expectException(\InvalidArgumentException::class);
$f = new Ghostscript();
$f->setInputFile(__FILE__);
$comp = new \SplFileInfo(__FILE__);
Expand Down Expand Up @@ -91,7 +89,7 @@ public function testSettingOutfileIsRepresentedInRenderString($outfile, $expecte
$f->setDevice(new Png());
$f->setInputFile(__DIR__ . '/support/test.pdf');
$f->setOutputFile($outfile);
$this->assertContains($expectedResultInRenderString, $f->getRenderString());
$this->assertStringContainsString($expectedResultInRenderString, $f->getRenderString());
}

public function settingOutfileIsRepresentedInRenderStringProvider()
Expand Down Expand Up @@ -247,18 +245,12 @@ public function testRendering()
public function testSettingPages()
{
$f = new Ghostscript();
$this->assertAttributeEquals(null, 'pageStart', $f);
$this->assertAttributeEquals(null, 'pageEnd', $f);
$this->assertEmpty($f->getPageRangeString());

$f->setPages(2);
$this->assertAttributeEquals(2, 'pageStart', $f);
$this->assertAttributeEquals(null, 'pageEnd', $f);
$this->assertEquals(' -dFirstPage=2 -dLastPage=2', $f->getPageRangeString());

$f->setPages(3, 4);
$this->assertAttributeEquals(3, 'pageStart', $f);
$this->assertAttributeEquals(4, 'pageEnd', $f);
$this->assertEquals(' -dFirstPage=3 -dLastPage=4', $f->getPageRangeString());
}

Expand All @@ -274,7 +266,8 @@ public function testSettingDefaultGsPathFails()
$this->markTestSkipped('Can not test due to installed GS');
}

$this->setExpectedExceptionFromAnnotation();
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('No Ghostscript-instance found or running on windows.');

Ghostscript::setGsPath();
}
Expand All @@ -288,34 +281,29 @@ public function testSettingDefaultGsPathWorks()

Ghostscript::setGsPath();

$this->assertAttributeEquals($output[0], 'PATH', Ghostscript::class);
$this->assertEquals($output[0], Ghostscript::getGsPath());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The given file is not executable
*/
public function testThatSettingPathToNonExecutableFails()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The given file is not executable');
Ghostscript::setGsPath(__DIR__ . '/_assets/nonExecutable');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage No valid Ghostscript found
*/
public function testThatSettingPathToNonGsFails()
{
Ghostscript::setGsPath(__DIR__ . '/_assets/executableNonGs');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('No valid Ghostscript found');
Ghostscript::setGsPath(__DIR__ . '/_assets/executableNonGs');
}

public function testThatSettingPathToSomethingGsLikeWorks()
{
Ghostscript::setGsPath(__DIR__ . '/_assets/executableGs');
$this->assertAttributeEquals(
$this->assertEquals(
__DIR__ . '/_assets/executableGs',
'PATH',
Ghostscript::class
Ghostscript::getGsPath()
);
}

Expand Down

0 comments on commit 544f779

Please sign in to comment.