Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds github workflow to run automated tests #22

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
root = true

[*]
charset = utf-8
tab_width = 4
trim_trailing_whitespace = true
indent_size = tab
indent_style = tab
insert_final_newline = true
end_of_line = lf

[{*.yml,*.yml.dist}]
indent_style = space
indent_size = 2
tab_width = 2

[*.xml]
tab_width = 2

[*.json]
tab_width = 2

[COMMIT_EDITMSG]
max_line_length = 72

[*.md]
max_line_length = 80

24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
name: Test on ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v4
- name: install Ghostscript
run: sudo apt-get install -y ghostscript
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: install dependencies
run: composer install
- name: install tools
run: composer require --dev phpunit/phpunit
- name: Run Unit-Tests
run: ./vendor/bin/phpunit --testdox --coverage-text

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/vendor/
composer.lock
.phpunit.result.cache
6 changes: 4 additions & 2 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 All @@ -20,8 +23,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^5.5||^6.0||^7.0",
"phpdocumentor/phpdocumentor": "^2.9",
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.0"

},
Expand Down
48 changes: 24 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php">
<testsuite name="Org_Heigl\Ghostscript Test-Suite">
<directory>./tests</directory>
</testsuite>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<!--
Adapt these paths to your special needs
-->
<log type="coverage-html" target="build/phpunit/coverage" charset="UTF-8"
yui="true" highlight="false"
lowUpperBound="35" highLowerBound="70"/>
</logging>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
38 changes: 13 additions & 25 deletions tests/GhostscriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
class GhostscriptTest extends TestCase
{
public function setup()
public function setup(): void
{
Ghostscript::setGsPath();
}
Expand All @@ -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
Loading