Skip to content

Commit

Permalink
PHPUnit 10 Migration (#14)
Browse files Browse the repository at this point in the history
* Bump PHPUnit dependencies

* Ignore PHPUnit cache folder

* Add return types to test methods

* Define test classes as `final`

* Move to phpunit.xml.dist

* Restructure file paths of tests

* Remove phpunit flag in local test env

---------

Co-authored-by: Shift <shift@laravelshift.com>
  • Loading branch information
olivervogel and laravel-shift committed Feb 28, 2024
1 parent c2b07d1 commit df43a2d
Show file tree
Hide file tree
Showing 29 changed files with 232 additions and 211 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.phpunit.result.cache
/.phpunit.cache
composer.lock
vendor/
phpunit.xml
vendor/
77 changes: 41 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
{
"name": "intervention/gif",
"description": "Native PHP GIF Encoder/Decoder",
"homepage": "https://github.com/intervention/gif",
"keywords": ["image", "gd", "gif", "animation"],
"license": "MIT",
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@intervention.io",
"homepage": "https://intervention.io/"
"name": "intervention/gif",
"description": "Native PHP GIF Encoder/Decoder",
"homepage": "https://github.com/intervention/gif",
"keywords": [
"image",
"gd",
"gif",
"animation"
],
"license": "MIT",
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@intervention.io",
"homepage": "https://intervention.io/"
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1",
"squizlabs/php_codesniffer": "^3.8",
"slevomat/coding-standard": "~8.0"
},
"autoload": {
"psr-4": {
"Intervention\\Gif\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Intervention\\Gif\\Tests\\": "tests"
}
},
"minimum-stability": "stable",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpstan/phpstan": "^1",
"squizlabs/php_codesniffer": "^3.8",
"slevomat/coding-standard": "~8.0"
},
"autoload": {
"psr-4": {
"Intervention\\Gif\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Intervention\\Gif\\Tests\\": "tests"
}
},
"minimum-stability": "stable",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
services:
services:
tests:
build: ./
working_dir: /project
command: bash -c "composer install && ./vendor/bin/phpunit -vvv"
command: bash -c "composer install && ./vendor/bin/phpunit"
volumes:
- ./:/project
coverage:
Expand Down
24 changes: 0 additions & 24 deletions phpunit.xml

This file was deleted.

13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Unit Tests">
<directory suffix=".php">./tests/Unit/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
5 changes: 5 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

abstract class BaseTestCase extends TestCase
{
public function getTestImagePath($filename = 'animation1.gif'): string
{
return sprintf('%s/images/%s', __DIR__, $filename);
}

public function getTestHandle($data)
{
$handle = fopen('php://memory', 'r+');
Expand Down
23 changes: 0 additions & 23 deletions tests/DecoderTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

declare(strict_types=1);

namespace Intervention\Gif\Tests;
namespace Intervention\Gif\Tests\Unit;

use Intervention\Gif\Decoders\AbstractDecoder;
use Intervention\Gif\Tests\BaseTestCase;

class AbstractDecoderTest extends BaseTestCase
final class AbstractDecoderTest extends BaseTestCase
{
public function testConstructor()
public function testConstructor(): void
{
$handle = $this->getTestHandle('foobarbaz');
$decoder = $this->getMockForAbstractClass(AbstractDecoder::class, [$handle, 12]);
$this->assertEquals(12, $decoder->getLength());
}

public function testSetHandle()
public function testSetHandle(): void
{
$handle = $this->getTestHandle('foobarbaz');
$decoder = $this->getMockForAbstractClass(AbstractDecoder::class, [$handle]);
$result = $decoder->setHandle($handle);
$this->assertInstanceOf(AbstractDecoder::class, $result);
}

public function testSetGetLength()
public function testSetGetLength(): void
{
$handle = $this->getTestHandle('foobarbaz');
$decoder = $this->getMockForAbstractClass(AbstractDecoder::class, [$handle]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

declare(strict_types=1);

namespace Intervention\Gif\Tests;
namespace Intervention\Gif\Tests\Unit;

use Intervention\Gif\Blocks\ColorTable;
use Intervention\Gif\Blocks\NetscapeApplicationExtension;
use Intervention\Gif\Decoder;
use Intervention\Gif\DisposalMethod;
use Intervention\Gif\GifDataStream;
use Intervention\Gif\Tests\BaseTestCase;

class AnimationDecodingTest extends BaseTestCase
final class AnimationDecodingTest extends BaseTestCase
{
public function testDecodeAnimation()
public function testDecodeAnimation(): void
{
$gif = Decoder::decode(__DIR__ . '/images/animation2.gif');
$gif = Decoder::decode($this->getTestImagePath('animation2.gif'));
$this->assertInstanceOf(GifDataStream::class, $gif);

// header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

declare(strict_types=1);

namespace Intervention\Gif\Tests;
namespace Intervention\Gif\Tests\Unit;

use Intervention\Gif\Blocks\ApplicationExtension;
use Intervention\Gif\Blocks\DataSubBlock;
use Intervention\Gif\Tests\BaseTestCase;

class ApplicationExtensionTest extends BaseTestCase
final class ApplicationExtensionTest extends BaseTestCase
{
public function testSetGetApplication()
public function testSetGetApplication(): void
{
$ext = new ApplicationExtension();
$this->assertEquals('', $ext->getApplication());
Expand All @@ -27,7 +28,7 @@ public function testAddBlock(): void
$this->assertCount(2, $extension->getBlocks());
}

public function testEncode()
public function testEncode(): void
{
$extension = new ApplicationExtension();
$extension->setApplication('foobar');
Expand All @@ -42,7 +43,7 @@ public function testEncode()
$this->assertEquals("\x21\xff\x0b\x4e\x45\x54\x53\x43\x41\x50\x45\x32\x2e\x30\x03\x01\x0c\x00\x00", $result);
}

public function testDecode()
public function testDecode(): void
{
$source = "\x21\xff\x06\x66\x6F\x6F\x62\x61\x72\x03\x62\x61\x7A\x00";
$extension = ApplicationExtension::decode($this->getTestHandle($source));
Expand Down
19 changes: 10 additions & 9 deletions tests/BuilderTest.php → tests/Unit/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@

declare(strict_types=1);

namespace Intervention\Gif\Tests;
namespace Intervention\Gif\Tests\Unit;

use Intervention\Gif\Builder;
use Intervention\Gif\GifDataStream;
use Intervention\Gif\Tests\BaseTestCase;

class BuilderTest extends BaseTestCase
final class BuilderTest extends BaseTestCase
{
public function testGetGifDataStream()
public function testGetGifDataStream(): void
{
$builder = Builder::canvas(320, 240);
$this->assertInstanceOf(GifDataStream::class, $builder->getGifDataStream());
}

public function testEncode()
public function testEncode(): void
{
$builder = Builder::canvas(320, 240);
$this->assertMatchesRegularExpression('/^\x47\x49\x46\x38(\x37|\x39)\x61/', $builder->encode());
}

public function testCanvas()
public function testCanvas(): void
{
$builder = Builder::canvas(320, 240);
$this->assertInstanceOf(Builder::class, $builder);
Expand All @@ -30,19 +31,19 @@ public function testCanvas()
$this->assertEquals(240, $gif->getLogicalScreenDescriptor()->getHeight());
}

public function testCanvasMultipleLoops()
public function testCanvasMultipleLoops(): void
{
$builder = Builder::canvas(320, 240);
$builder->addFrame(__DIR__ . '/images/red.gif', 0.25, 1, 2);
$builder->addFrame($this->getTestImagePath('red.gif'), 0.25, 1, 2);
$builder->setLoops(10);
$gif = $builder->getGifDataStream();
$this->assertEquals(10, $gif->getMainApplicationExtension()->getLoops());
}

public function testAddFrame()
public function testAddFrame(): void
{
$builder = Builder::canvas(320, 240);
$result = $builder->addFrame(__DIR__ . '/images/red.gif', 0.25, 1, 2);
$result = $builder->addFrame($this->getTestImagePath('red.gif'), 0.25, 1, 2);
$this->assertInstanceOf(Builder::class, $result);
$gif = $builder->getGifDataStream();
$this->assertEquals(25, $gif->getFirstFrame()->getGraphicControlExtension()->getDelay());
Expand Down

0 comments on commit df43a2d

Please sign in to comment.