Skip to content

Commit 9626f9c

Browse files
authored
Merge pull request #25 from mikehaertl/github-actions
Migrate to github actions
2 parents f162f70 + f1908e1 commit 9626f9c

File tree

8 files changed

+81
-27
lines changed

8 files changed

+81
-27
lines changed

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Tests
2+
on: pull_request
3+
jobs:
4+
phpunit:
5+
name: PHP ${{ matrix.php }}
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
php:
10+
- "5.3"
11+
- "5.4"
12+
- "5.5"
13+
- "5.6"
14+
- "7.0"
15+
- "7.1"
16+
- "7.2"
17+
- "7.3"
18+
- "7.4"
19+
- "8.0"
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Install PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
tools: composer:v2
29+
30+
- name: Update composer
31+
run: composer self-update
32+
33+
- name: Get composer cache directory
34+
id: composer-cache
35+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
36+
37+
- name: Cache dependencies
38+
uses: actions/cache@v2
39+
with:
40+
path: ${{ steps.composer-cache.outputs.dir }}
41+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
42+
restore-keys: ${{ runner.os }}-composer-
43+
44+
- name: Install composer packages
45+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
46+
47+
- name: Run phpunit
48+
run: vendor/bin/phpunit --color=always

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
phpunit.xml
22
composer.lock
33
/vendor/
4+
.phpunit.result.cache
45
*.swp

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
php-tmpfile
22
===========
33

4-
[![Build Status](https://secure.travis-ci.org/mikehaertl/php-tmpfile.png)](http://travis-ci.org/mikehaertl/php-tmpfile)
5-
[![Latest Stable Version](https://poser.pugx.org/mikehaertl/php-tmpfile/v/stable.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile)
6-
[![Total Downloads](https://poser.pugx.org/mikehaertl/php-tmpfile/downloads)](https://packagist.org/packages/mikehaertl/php-tmpfile)
7-
[![Latest Unstable Version](https://poser.pugx.org/mikehaertl/php-tmpfile/v/unstable.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile)
8-
[![License](https://poser.pugx.org/mikehaertl/php-tmpfile/license.svg)](https://packagist.org/packages/mikehaertl/php-tmpfile)
4+
[![GitHub Tests](https://github.com/mikehaertl/php-tmpfile/workflows/Tests/badge.svg)](https://github.com/mikehaertl/php-tmpfile/actions)
5+
[![Packagist Version](https://img.shields.io/packagist/v/mikehaertl/php-tmpfile?label=version)](https://packagist.org/packages/mikehaertl/php-tmpfile)
6+
[![Packagist Downloads](https://img.shields.io/packagist/dt/mikehaertl/php-tmpfile)](https://packagist.org/packages/mikehaertl/php-tmpfile)
7+
[![GitHub license](https://img.shields.io/github/license/mikehaertl/php-tmpfile)](https://github.com/mikehaertl/php-tmpfile/blob/master/LICENSE)
98

109
A convenience class for temporary files.
1110

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
}
1111
],
1212
"require-dev": {
13-
"phpunit/phpunit": ">4.0 <8"
13+
"php": ">=5.3.0",
14+
"phpunit/phpunit": ">4.0 <=9.4"
1415
},
1516
"autoload": {
1617
"psr-4": {

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="./tests/bootstrap.php"
1312
>
1413
<testsuites>

tests/FileTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ public function testCanCreateFile()
1616
$readContent = file_get_contents($fileName);
1717
$this->assertEquals($content, $readContent);
1818
unset($tmp);
19-
$this->assertFileNotExists($fileName);
19+
if (phpUnitVersion('<', '9')) {
20+
$this->assertFileNotExists($fileName);
21+
} else {
22+
$this->assertFileDoesNotExist($fileName);
23+
}
2024
}
2125

2226
public function testCanCreateFileWithSuffix()
@@ -64,7 +68,11 @@ public function testCanSaveFileAs()
6468
$readContent = file_get_contents($out);
6569
$this->assertEquals($content, $readContent);
6670
unset($tmp);
67-
$this->assertFileNotExists($fileName);
71+
if (phpUnitVersion('<', '9')) {
72+
$this->assertFileNotExists($fileName);
73+
} else {
74+
$this->assertFileDoesNotExist($fileName);
75+
}
6876
$this->assertFileExists($out);
6977
unlink($out);
7078
}

tests/bootstrap.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<?php
2-
// Some travis environments use phpunit > 6
3-
$newClass = '\PHPUnit\Framework\TestCase';
4-
$oldClass = '\PHPUnit_Framework_TestCase';
5-
if (!class_exists($newClass) && class_exists($oldClass)) {
6-
class_alias($oldClass, $newClass);
2+
3+
/**
4+
* Utility method to check the version of PHPUnit.
5+
*
6+
* Example: phpUnitVersion('<', '8.3'); // true e.g. for 8.2.1
7+
*
8+
* @param string $operator an operator like '>', '<', etc.
9+
* @param string $version the version to check against
10+
* @return bool whether PHPUnit matches the version to check
11+
*/
12+
function phpUnitVersion($operator, $version)
13+
{
14+
$phpUnitVersion = class_exists('\PHPUnit\Runner\Version') ?
15+
call_user_func(array('\PHPUnit\Runner\Version', 'id')) :
16+
call_user_func(array('\PHPUnit_Runner_Version', 'id'));
17+
return version_compare($phpUnitVersion, $version, $operator);
718
}
819

920
require __DIR__ . '/../vendor/autoload.php';

0 commit comments

Comments
 (0)