diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index facac86..1950470 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -8,8 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - # TODO Add 8.1 version as well - php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - uses: actions/checkout@v2 diff --git a/tests/AbstractConfigTest.php b/tests/AbstractConfigTest.php index 8a16b46..69dda1e 100644 --- a/tests/AbstractConfigTest.php +++ b/tests/AbstractConfigTest.php @@ -139,7 +139,7 @@ public function testSetArray() 'host' => 'localhost', 'name' => 'mydatabase' ]); - $this->assertInternalType('array', $this->config->get('database')); + $this->assertIsArray($this->config->get('database')); $this->assertEquals('localhost', $this->config->get('database.host')); } @@ -152,7 +152,7 @@ public function testCacheWithNestedArray() 'host' => 'localhost', 'name' => 'mydatabase' ]); - $this->assertInternalType('array', $this->config->get('database')); + $this->assertIsArray($this->config->get('database')); $this->config->set('database.host', '127.0.0.1'); $expected = [ 'host' => '127.0.0.1', @@ -218,7 +218,7 @@ public function testSetAndUnsetArray() 'host' => 'localhost', 'name' => 'mydatabase' ]); - $this->assertInternalType('array', $this->config->get('database')); + $this->assertIsArray($this->config->get('database')); $this->assertEquals('localhost', $this->config->get('database.host')); $this->config->set('database.host', null); $this->assertNull($this->config->get('database.host')); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 55d6840..bd049fb 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -4,12 +4,14 @@ use Noodlehaus\Parser\Json as JsonParser; use Noodlehaus\Writer\Json as JsonWriter; use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; /** * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-04-21 at 22:37:22. */ class ConfigTest extends TestCase { + use ExpectException; /** * @var Config */ @@ -19,11 +21,11 @@ class ConfigTest extends TestCase * @covers Noodlehaus\Config::load() * @covers Noodlehaus\Config::loadFromFile() * @covers Noodlehaus\Config::getParser() - * @expectedException Noodlehaus\Exception\UnsupportedFormatException - * @expectedExceptionMessage Unsupported configuration format */ public function testLoadWithUnsupportedFormat() { + $this->expectException(\Noodlehaus\Exception\UnsupportedFormatException::class); + $this->expectExceptionMessage('Unsupported configuration format'); $config = Config::load(__DIR__ . '/mocks/fail/error.lib'); // $this->markTestIncomplete('Not yet implemented'); } @@ -32,11 +34,11 @@ public function testLoadWithUnsupportedFormat() * @covers Noodlehaus\Config::__construct() * @covers Noodlehaus\Config::loadFromFile() * @covers Noodlehaus\Config::getParser() - * @expectedException Noodlehaus\Exception\UnsupportedFormatException - * @expectedExceptionMessage Unsupported configuration format */ public function testConstructWithUnsupportedFormat() { + $this->expectException(\Noodlehaus\Exception\UnsupportedFormatException::class); + $this->expectExceptionMessage('Unsupported configuration format'); $config = new Config(__DIR__ . '/mocks/fail/error.lib'); } @@ -46,11 +48,11 @@ public function testConstructWithUnsupportedFormat() * @covers Noodlehaus\Config::getParser() * @covers Noodlehaus\Config::getPathFromArray() * @covers Noodlehaus\Config::getValidPath() - * @expectedException Noodlehaus\Exception\FileNotFoundException - * @expectedExceptionMessage Configuration file: [ladadeedee] cannot be found */ public function testConstructWithInvalidPath() { + $this->expectException(\Noodlehaus\Exception\FileNotFoundException::class); + $this->expectExceptionMessage('Configuration file: [ladadeedee] cannot be found'); $config = new Config('ladadeedee'); } @@ -60,10 +62,10 @@ public function testConstructWithInvalidPath() * @covers Noodlehaus\Config::getParser() * @covers Noodlehaus\Config::getPathFromArray() * @covers Noodlehaus\Config::getValidPath() - * @expectedException Noodlehaus\Exception\EmptyDirectoryException */ public function testConstructWithEmptyDirectory() { + $this->expectException(\Noodlehaus\Exception\EmptyDirectoryException::class); $config = new Config(__DIR__ . '/mocks/empty'); } @@ -91,10 +93,10 @@ public function testConstructWithArray() * @covers Noodlehaus\Config::getParser() * @covers Noodlehaus\Config::getPathFromArray() * @covers Noodlehaus\Config::getValidPath() - * @expectedException Noodlehaus\Exception\FileNotFoundException */ public function testConstructWithArrayWithNonexistentFile() { + $this->expectException(\Noodlehaus\Exception\FileNotFoundException::class); $paths = [__DIR__ . '/mocks/pass/config.xml', __DIR__ . '/mocks/pass/config3.json']; $config = new Config($paths); diff --git a/tests/Parser/IniTest.php b/tests/Parser/IniTest.php index 7d12a0d..35ec8c5 100644 --- a/tests/Parser/IniTest.php +++ b/tests/Parser/IniTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('No parsable content'); $this->ini->parseFile(__DIR__ . '/../mocks/fail/error2.ini'); } @@ -58,14 +60,8 @@ public function testLoadInvalidIni() $exceptionMessage = "syntax error, unexpected end of file, expecting ']' in Unknown on line 1"; } - if (PHP_VERSION_ID < 50600 && PHP_VERSION_ID >= 50500) { - $this->setExpectedException( - '\Noodlehaus\Exception\ParseException', $exceptionMessage - ); - } else { - $this->expectException(\Noodlehaus\Exception\ParseException::class); - $this->expectExceptionMessage($exceptionMessage); - } + $this->expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage($exceptionMessage); $this->ini->parseString(file_get_contents(__DIR__ . '/../mocks/fail/error.ini')); } diff --git a/tests/Parser/JsonTest.php b/tests/Parser/JsonTest.php index 7ae769b..7ce0bf1 100644 --- a/tests/Parser/JsonTest.php +++ b/tests/Parser/JsonTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('Syntax error'); $this->json->parseFile(__DIR__ . '/../mocks/fail/error.json'); } diff --git a/tests/Parser/PhpTest.php b/tests/Parser/PhpTest.php index d334fc8..0d27e0d 100644 --- a/tests/Parser/PhpTest.php +++ b/tests/Parser/PhpTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\UnsupportedFormatException::class); + $this->expectExceptionMessage('PHP data does not return an array'); $this->php->parseFile(__DIR__ . '/../mocks/fail/error.php'); } /** * @covers Noodlehaus\Parser\Php::parseFile() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage PHP file threw an exception */ public function testLoadExceptionalPhpFile() { + $this->expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('PHP file threw an exception'); $this->php->parseFile(__DIR__ . '/../mocks/fail/error-exception.php'); } /** * @covers Noodlehaus\Parser\Php::parseString() * @covers Noodlehaus\Parser\Php::isolate() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage PHP string threw an exception */ public function testLoadExceptionalPhpString() { + $this->expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('PHP string threw an exception'); $this->php->parseString(file_get_contents(__DIR__ . '/../mocks/fail/error-exception.php')); } diff --git a/tests/Parser/SerializeTest.php b/tests/Parser/SerializeTest.php index 922b15e..5a6d4c4 100644 --- a/tests/Parser/SerializeTest.php +++ b/tests/Parser/SerializeTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('unserialize(): Error at offset 57 of 58 bytes'); $this->serialize->parseFile(__DIR__ . '/../mocks/fail/error.txt'); } diff --git a/tests/Parser/XmlTest.php b/tests/Parser/XmlTest.php index c825525..37b1a91 100644 --- a/tests/Parser/XmlTest.php +++ b/tests/Parser/XmlTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('Opening and ending tag mismatch: name line 4'); $this->xml->parseFile(__DIR__ . '/../mocks/fail/error.xml'); } diff --git a/tests/Parser/YamlTest.php b/tests/Parser/YamlTest.php index 9c1b0d6..a4f14f1 100644 --- a/tests/Parser/YamlTest.php +++ b/tests/Parser/YamlTest.php @@ -1,14 +1,16 @@ expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('Error parsing YAML file'); $this->yaml->parseFile(__DIR__ . '/../mocks/fail/error.yaml'); } /** * @covers Noodlehaus\Parser\Yaml::parseString() * @covers Noodlehaus\Parser\Yaml::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage Error parsing YAML string */ public function testLoadInvalidYamlString() { + $this->expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('Error parsing YAML string'); $this->yaml->parseString(file_get_contents(__DIR__ . '/../mocks/fail/error.yaml')); } diff --git a/tests/Writer/IniTest.php b/tests/Writer/IniTest.php index 3483596..dfc7eed 100644 --- a/tests/Writer/IniTest.php +++ b/tests/Writer/IniTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Ini; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class IniTest extends TestCase { + use ExpectException; /** * @var Ini */ @@ -97,11 +99,11 @@ public function testWriteIni() * @covers Noodlehaus\Writer\Ini::toString() * @covers Noodlehaus\Writer\Ini::toFile() * @covers Noodlehaus\Writer\Ini::toINI() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file); diff --git a/tests/Writer/JsonTest.php b/tests/Writer/JsonTest.php index 64970a8..1908990 100644 --- a/tests/Writer/JsonTest.php +++ b/tests/Writer/JsonTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Json; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class JsonTest extends TestCase { + use ExpectException; /** * @var Json */ @@ -90,11 +92,11 @@ public function testWriteJson() /** * @covers Noodlehaus\Writer\Json::toString() * @covers Noodlehaus\Writer\Json::toFile() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file); diff --git a/tests/Writer/PropertiesTest.php b/tests/Writer/PropertiesTest.php index 7645568..c4db878 100644 --- a/tests/Writer/PropertiesTest.php +++ b/tests/Writer/PropertiesTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Properties; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class PropertiesTest extends TestCase { + use ExpectException; /** * @var Properties */ @@ -98,11 +100,11 @@ public function testWriteProperties() * @covers Noodlehaus\Writer\Properties::toString() * @covers Noodlehaus\Writer\Properties::toFile() * @covers Noodlehaus\Writer\Properties::toProperties() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file); diff --git a/tests/Writer/SerializeTest.php b/tests/Writer/SerializeTest.php index 22b7e69..7af530d 100644 --- a/tests/Writer/SerializeTest.php +++ b/tests/Writer/SerializeTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Serialize; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class SerializeTest extends TestCase { + use ExpectException; /** * @var Serialize */ @@ -90,11 +92,11 @@ public function testWriteSerialize() /** * @covers Noodlehaus\Writer\Serialize::toString() * @covers Noodlehaus\Writer\Serialize::toFile() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file); diff --git a/tests/Writer/XmlTest.php b/tests/Writer/XmlTest.php index c3fda63..68fc972 100644 --- a/tests/Writer/XmlTest.php +++ b/tests/Writer/XmlTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Xml; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class XmlTest extends TestCase { + use ExpectException; /** * @var Xml */ @@ -95,11 +97,11 @@ public function testWriteXml() /** * @covers Noodlehaus\Writer\Xml::toFile() * @covers Noodlehaus\Writer\Xml::toXML() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file); diff --git a/tests/Writer/YamlTest.php b/tests/Writer/YamlTest.php index 7ed316d..aa0db55 100644 --- a/tests/Writer/YamlTest.php +++ b/tests/Writer/YamlTest.php @@ -3,10 +3,12 @@ namespace Noodlehaus\Writer\Test; use Noodlehaus\Writer\Yaml; +use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; use Yoast\PHPUnitPolyfills\TestCases\TestCase; class YamlTest extends TestCase { + use ExpectException; /** * @var Yaml */ @@ -99,11 +101,11 @@ public function testWriteYaml() /** * @covers Noodlehaus\Writer\Yaml::toString() * @covers Noodlehaus\Writer\Yaml::toFile() - * @expectedException Noodlehaus\Exception\WriteException - * @expectedExceptionMessage There was an error writing the file */ public function testUnwritableFile() { + $this->expectException(\Noodlehaus\Exception\WriteException::class); + $this->expectExceptionMessage('There was an error writing the file'); chmod($this->temp_file, 0444); $this->writer->toFile($this->data, $this->temp_file);