From 50e137ddba12e370fd86f2ff68cd290dca5c27cd Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 8 Feb 2018 17:23:45 +0800 Subject: [PATCH] Harden tests (#22) - Tweak Travis config: improve the composer install step, add support for new PHP versions and fix the config for PHP 5.3 - Adjust the current version for PHPUnit, and PHP. - Use vfsStream to mock the file system. --- .travis.yml | 5 ++++- composer.json | 5 +++-- phpunit.xml.dist | 2 +- tests/Humbug/Test/FunctionTest.php | 15 +++++---------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0bef26c..7c42278 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,18 @@ language: php php: - - '5.3' - '5.4' - '5.5' - '5.6' - '7.0' - '7.1' + - '7.2' - nightly matrix: + include: + - php: 5.3 + dist: precise fast_finish: true allow_failures: - php: nightly diff --git a/composer.json b/composer.json index f5c1eb2..42a8c54 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,14 @@ ], "require": { - "php": "^5.3 || ^7.0", + "php": "^5.3 || ^7.0 || ^7.1 || ^7.2", "ext-openssl": "*", "composer/ca-bundle": "^1.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.1", - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0" + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5", + "mikey179/vfsStream": "^1.6" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 444e9d1..a44449b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,7 +21,7 @@ - ./src/Humbug/ + ./src/ diff --git a/tests/Humbug/Test/FunctionTest.php b/tests/Humbug/Test/FunctionTest.php index 5379c37..58ac26a 100644 --- a/tests/Humbug/Test/FunctionTest.php +++ b/tests/Humbug/Test/FunctionTest.php @@ -12,20 +12,15 @@ namespace Humbug\Test; use PHPUnit\Framework\TestCase; +use org\bovigo\vfs\vfsStream; -if (!class_exists('\PHPUnit\Framework\TestCase', true)) { - class_alias('\PHPUnit_Framework_TestCase', 'TestCase'); -} - -/** - * @coversNothing - */ class FunctionTest extends TestCase { private static $result; public function setup() { + vfsStream::setup('home_root_path'); if (null === self::$result) { $result = humbug_get_contents('https://www.howsmyssl.com/a/check'); self::$result = json_decode($result, true); @@ -34,7 +29,7 @@ public function setup() public function teardown() { - @unlink(sys_get_temp_dir() . '/humbug.tmp'); + self::$result = null; } public function testRating() @@ -69,8 +64,8 @@ public function testUnknownCipherSuites() public function testFileGetContentsWillPassThrough() { - file_put_contents(sys_get_temp_dir() . '/humbug.tmp', ($expected = uniqid()), LOCK_EX); - $this->assertEquals(file_get_contents(sys_get_temp_dir() . '/humbug.tmp'), $expected); + file_put_contents(vfsStream::url('home_root_path/humbug.tmp'), ($expected = uniqid())); + $this->assertEquals(file_get_contents(vfsStream::url('home_root_path/humbug.tmp')), $expected); } public function testCanGetResponseHeaders()