diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..94c02ab --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,48 @@ +name: Tests +on: pull_request +jobs: + phpunit: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-latest + strategy: + matrix: + php: + - "5.3" + - "5.4" + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - name: Update composer + run: composer self-update + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install composer packages + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run phpunit + run: vendor/bin/phpunit --color=always diff --git a/.gitignore b/.gitignore index d7eee2f..ee1c10a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ phpunit.xml composer.lock /vendor/ +.phpunit.result.cache *.swp diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5decf5c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: php -dist: trusty -php: - - "7.4" - - "7.3" - - "7.2" - - "7.1" - - "7.0" - - "5.6" - - "5.5" - - "5.4" -install: - - composer install diff --git a/README.md b/README.md index 2435d90..a3fc05e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ php-tmpfile =========== -[![Build Status](https://secure.travis-ci.org/mikehaertl/php-tmpfile.png)](http://travis-ci.org/mikehaertl/php-tmpfile) -[![Latest Stable Version](https://poser.pugx.org/mikehaertl/php-tmpfile/v/stable.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile) -[![Total Downloads](https://poser.pugx.org/mikehaertl/php-tmpfile/downloads)](https://packagist.org/packages/mikehaertl/php-tmpfile) -[![Latest Unstable Version](https://poser.pugx.org/mikehaertl/php-tmpfile/v/unstable.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile) -[![License](https://poser.pugx.org/mikehaertl/php-tmpfile/license.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile) +[![GitHub Tests](https://github.com/mikehaertl/php-tmpfile/workflows/Tests/badge.svg)](https://github.com/mikehaertl/php-tmpfile/actions) +[![Packagist Version](https://img.shields.io/packagist/v/mikehaertl/php-tmpfile?label=version)](https://packagist.org/packages/mikehaertl/php-tmpfile) +[![Packagist Downloads](https://img.shields.io/packagist/dt/mikehaertl/php-tmpfile)](https://packagist.org/packages/mikehaertl/php-tmpfile) +[![GitHub license](https://img.shields.io/github/license/mikehaertl/php-tmpfile)](https://github.com/mikehaertl/php-tmpfile/blob/master/LICENSE) A convenience class for temporary files. diff --git a/composer.json b/composer.json index 9e8e0d6..c28c46a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ } ], "require-dev": { - "phpunit/phpunit": ">4.0 <8" + "php": ">=5.3.0", + "phpunit/phpunit": ">4.0 <=9.4" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 81123cc..41c86c0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > diff --git a/tests/FileTest.php b/tests/FileTest.php index de5dc83..d3d0616 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -16,7 +16,11 @@ public function testCanCreateFile() $readContent = file_get_contents($fileName); $this->assertEquals($content, $readContent); unset($tmp); - $this->assertFileNotExists($fileName); + if (phpUnitVersion('<', '9')) { + $this->assertFileNotExists($fileName); + } else { + $this->assertFileDoesNotExist($fileName); + } } public function testCanCreateFileWithSuffix() @@ -64,7 +68,11 @@ public function testCanSaveFileAs() $readContent = file_get_contents($out); $this->assertEquals($content, $readContent); unset($tmp); - $this->assertFileNotExists($fileName); + if (phpUnitVersion('<', '9')) { + $this->assertFileNotExists($fileName); + } else { + $this->assertFileDoesNotExist($fileName); + } $this->assertFileExists($out); unlink($out); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 245a634..a35e967 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,9 +1,20 @@ 6 -$newClass = '\PHPUnit\Framework\TestCase'; -$oldClass = '\PHPUnit_Framework_TestCase'; -if (!class_exists($newClass) && class_exists($oldClass)) { - class_alias($oldClass, $newClass); + +/** + * Utility method to check the version of PHPUnit. + * + * Example: phpUnitVersion('<', '8.3'); // true e.g. for 8.2.1 + * + * @param string $operator an operator like '>', '<', etc. + * @param string $version the version to check against + * @return bool whether PHPUnit matches the version to check + */ +function phpUnitVersion($operator, $version) +{ + $phpUnitVersion = class_exists('\PHPUnit\Runner\Version') ? + call_user_func(array('\PHPUnit\Runner\Version', 'id')) : + call_user_func(array('\PHPUnit_Runner_Version', 'id')); + return version_compare($phpUnitVersion, $version, $operator); } require __DIR__ . '/../vendor/autoload.php';