Skip to content

Commit

Permalink
Merge pull request #387 from KnpLabs/add-phpstan-level4-ci-check
Browse files Browse the repository at this point in the history
Add phpstan level 4 CI check
  • Loading branch information
alexpozzi authored Jan 31, 2020
2 parents d7ad8d5 + 551ed01 commit 2766ff9
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* text=auto

/test export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ install: composer update --prefer-dist

script:
- vendor/bin/phpunit
- composer phpstan
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "knplabs/knp-snappy",
"type": "library",
"description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.",
"description": "PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.",
"keywords": ["pdf", "thumbnail", "snapshot", "knplabs", "knp", "wkhtmltopdf"],
"homepage": "http://github.com/KnpLabs/snappy",
"license": "MIT",
"authors": [
{
"name": "KnpLabs Team",
"name": "KNP Labs Team",
"homepage": "http://knplabs.com"
},
{
Expand All @@ -21,7 +21,9 @@
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~7.4"
"phpunit/phpunit": "~7.4",
"phpstan/phpstan": "^0.12.7",
"phpstan/phpstan-phpunit": "^0.12.6"
},
"suggest": {
"h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency",
Expand All @@ -35,6 +37,14 @@
"Knp\\Snappy\\": "src/Knp/Snappy"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 4
paths:
- src/
- tests/
inferPrivatePropertyTypeFromConstructor: true
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- "#^Call to an undefined static method #"
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<testsuites>
<testsuite name="Snappy Test Suite">
<directory>./test</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
10 changes: 6 additions & 4 deletions src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function __construct($binary, array $options = [], array $env = null)
$this->setOptions($options);
$this->env = empty($env) ? null : $env;

register_shutdown_function([$this, 'removeTemporaryFiles']);
if (is_callable([$this, 'removeTemporaryFiles'])) {
register_shutdown_function([$this, 'removeTemporaryFiles']);
}
}

public function __destruct()
Expand Down Expand Up @@ -91,7 +93,7 @@ public function setDefaultExtension($defaultExtension)
/**
* Gets the default extension.
*
* @return $string
* @return string
*/
public function getDefaultExtension()
{
Expand Down Expand Up @@ -430,7 +432,7 @@ protected function createTemporaryFile($content = null, $extension = null)
/**
* Removes all temporary files.
*/
public function removeTemporaryFiles()
public function removeTemporaryFiles(): void
{
foreach ($this->temporaryFiles as $file) {
$this->unlink($file);
Expand All @@ -441,7 +443,7 @@ public function removeTemporaryFiles()
* Builds the command string.
*
* @param string $binary The binary path/name
* @param string/array $input Url(s) or file location(s) of the page(s) to process
* @param string|array $input Url(s) or file location(s) of the page(s) to process
* @param string $output File location to the image-to-be
* @param array $options An array of options
*
Expand Down
2 changes: 1 addition & 1 deletion src/Knp/Snappy/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function generate($input, $output, array $options = [], $overwrite = fals
/**
* Convert option content or url to file if it is needed.
*
* @param $option
* @param mixed $option
*
* @return bool
*/
Expand Down
14 changes: 0 additions & 14 deletions test/Knp/Snappy/ImageTest.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

namespace Knp\Snappy;
namespace Tests\Knp\Snappy;

use Knp\Snappy\AbstractGenerator;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class AbstractGeneratorTest extends TestCase
{
public function testAddOption()
{
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

$this->assertEquals([], $media->getOptions());

Expand All @@ -36,13 +37,13 @@ public function testAddOption()
$r->invokeArgs($media, ['baz', 'bat']);
$this->fail($message);
} catch (\InvalidArgumentException $e) {
$this->anything($message);
$this->anything();
}
}

public function testAddOptions()
{
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

$this->assertEquals([], $media->getOptions());

Expand Down Expand Up @@ -78,7 +79,7 @@ public function testAddOptions()
$r->invokeArgs($media, [['bak' => 'bam', 'bah' => 'bap', 'baz' => 'bat']]);
$this->fail($message);
} catch (\InvalidArgumentException $e) {
$this->anything($message);
$this->anything();
}
}

Expand Down Expand Up @@ -117,7 +118,7 @@ public function testSetOption()
$media->setOption('bad', 'def');
$this->fail($message);
} catch (\InvalidArgumentException $e) {
$this->anything($message);
$this->anything();
}
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public function testSetOptions()
$media->setOptions(['foo' => 'abc', 'baz' => 'def', 'bad' => 'ghi']);
$this->fail($message);
} catch (\InvalidArgumentException $e) {
$this->anything($message);
$this->anything();
}
}

Expand Down Expand Up @@ -493,7 +494,7 @@ public function testGetOutputFromHtmlWithHtmlArray()

public function testMergeOptions()
{
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

$originalOptions = ['foo' => 'bar', 'baz' => 'bat'];

Expand Down Expand Up @@ -538,7 +539,7 @@ public function testMergeOptions()
$r->invokeArgs($media, [['foo' => 'ban', 'bad' => 'bah']]);
$this->fail($message);
} catch (\InvalidArgumentException $e) {
$this->anything($message);
$this->anything();
}
}

Expand All @@ -547,7 +548,7 @@ public function testMergeOptions()
*/
public function testBuildCommand($binary, $url, $path, $options, $expected)
{
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

$r = new \ReflectionMethod($media, 'buildCommand');
$r->setAccessible(true);
Expand Down Expand Up @@ -679,7 +680,7 @@ public function testCheckOutput()

try {
$r->invokeArgs($media, ['the_output_file', 'the command']);
$this->anything($message);
$this->anything();
} catch (\RuntimeException $e) {
$this->fail($message);
}
Expand Down Expand Up @@ -712,7 +713,7 @@ public function testCheckOutputWhenTheFileDoesNotExist()
$r->invokeArgs($media, ['the_output_file', 'the command']);
$this->fail($message);
} catch (\RuntimeException $e) {
$this->anything($message);
$this->anything();
}
}

Expand Down Expand Up @@ -750,7 +751,7 @@ public function testCheckOutputWhenTheFileIsEmpty()
$r->invokeArgs($media, ['the_output_file', 'the command']);
$this->fail($message);
} catch (\RuntimeException $e) {
$this->anything($message);
$this->anything();
}
}

Expand All @@ -767,14 +768,14 @@ public function testCheckProcessStatus()

try {
$r->invokeArgs($media, [0, '', '', 'the command']);
$this->anything('0 status means success');
$this->anything();
} catch (\RuntimeException $e) {
$this->fail('0 status means success');
}

try {
$r->invokeArgs($media, [1, '', '', 'the command']);
$this->anything('1 status means failure, but no stderr content');
$this->anything();
} catch (\RuntimeException $e) {
$this->fail('1 status means failure, but no stderr content');
}
Expand All @@ -792,7 +793,7 @@ public function testCheckProcessStatus()
*/
public function testIsAssociativeArray($array, $isAssociativeArray)
{
$generator = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
$generator = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

$r = new \ReflectionMethod($generator, 'isAssociativeArray');
$r->setAccessible(true);
Expand Down
15 changes: 15 additions & 0 deletions tests/Knp/Snappy/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tests\Knp\Snappy;

use Knp\Snappy\Image;
use PHPUnit\Framework\TestCase;

class ImageTest extends TestCase
{
public function testCreateInstance()
{
$testObject = new Image();
$this->assertInstanceOf(Image::class, $testObject);
}
}
7 changes: 4 additions & 3 deletions test/Knp/Snappy/PdfTest.php → tests/Knp/Snappy/PdfTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Knp\Snappy;
namespace Tests\Knp\Snappy;

use Knp\Snappy\Pdf;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -40,8 +41,8 @@ function ($filename) {

public function testCreateInstance()
{
$testObject = new \Knp\Snappy\Pdf();
$this->assertInstanceOf('\Knp\Snappy\Pdf', $testObject);
$testObject = new Pdf();
$this->assertInstanceOf(Pdf::class, $testObject);
}

public function testThatSomethingUsingTmpFolder()
Expand Down

0 comments on commit 2766ff9

Please sign in to comment.