From ef98415df338ceb7748bcbbd64339ceb56179f76 Mon Sep 17 00:00:00 2001 From: Davide Pastore Date: Thu, 30 Dec 2021 16:56:38 +0100 Subject: [PATCH 1/4] Add PHP 8.1 to the build matrix --- .github/workflows/continuous-integration.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 From b917a4b7d8b075ea9874d531f4e93d3d769190cd Mon Sep 17 00:00:00 2001 From: Davide Pastore Date: Thu, 30 Dec 2021 17:00:08 +0100 Subject: [PATCH 2/4] Use assertIsArray instead of assertInternalType --- tests/AbstractConfigTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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')); From 2550582933f997ab7eb57ad026373fe04f0d4372 Mon Sep 17 00:00:00 2001 From: Davide Pastore Date: Thu, 30 Dec 2021 17:09:10 +0100 Subject: [PATCH 3/4] Remove usages of phpunit deprecated methods --- tests/ConfigTest.php | 16 ++++++++-------- tests/Parser/IniTest.php | 14 ++++---------- tests/Parser/JsonTest.php | 4 ++-- tests/Parser/PhpTest.php | 12 ++++++------ tests/Parser/SerializeTest.php | 4 ++-- tests/Parser/XmlTest.php | 4 ++-- tests/Parser/YamlTest.php | 8 ++++---- tests/Writer/IniTest.php | 4 ++-- tests/Writer/JsonTest.php | 4 ++-- tests/Writer/PropertiesTest.php | 4 ++-- tests/Writer/SerializeTest.php | 4 ++-- tests/Writer/XmlTest.php | 4 ++-- tests/Writer/YamlTest.php | 4 ++-- 13 files changed, 40 insertions(+), 46 deletions(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 55d6840..c295125 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -19,11 +19,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 +32,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 +46,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 +60,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 +91,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..3a4b152 100644 --- a/tests/Parser/IniTest.php +++ b/tests/Parser/IniTest.php @@ -36,13 +36,13 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Ini::parseFile() * @covers Noodlehaus\Parser\Ini::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage No parsable content * Tests the case where an INI string contains no parsable data at all, resulting in parse_ini_string * returning NULL, but not setting an error retrievable by error_get_last() */ public function testLoadInvalidIniGBH() { + $this->expectException(\Noodlehaus\Exception\ParseException::class); + $this->expectExceptionMessage('No parsable content'); $this->ini->parseFile(__DIR__ . '/../mocks/fail/error2.ini'); } @@ -58,14 +58,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..3d08da5 100644 --- a/tests/Parser/JsonTest.php +++ b/tests/Parser/JsonTest.php @@ -36,11 +36,11 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Json::parseFile() * @covers Noodlehaus\Parser\Json::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage Syntax error */ public function testLoadInvalidJson() { + $this->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..75b8dce 100644 --- a/tests/Parser/PhpTest.php +++ b/tests/Parser/PhpTest.php @@ -36,32 +36,32 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Php::parseFile() * @covers Noodlehaus\Parser\Php::parse() - * @expectedException Noodlehaus\Exception\UnsupportedFormatException - * @expectedExceptionMessage PHP data does not return an array */ public function testLoadInvalidPhp() { + $this->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..d649591 100644 --- a/tests/Parser/SerializeTest.php +++ b/tests/Parser/SerializeTest.php @@ -36,11 +36,11 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Serialize::parseFile() * @covers Noodlehaus\Parser\Serialize::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage unserialize(): Error at offset 57 of 58 bytes */ public function testLoadInvalidSerialize() { + $this->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..fa9ec71 100644 --- a/tests/Parser/XmlTest.php +++ b/tests/Parser/XmlTest.php @@ -36,11 +36,11 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Xml::parseFile() * @covers Noodlehaus\Parser\Xml::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage Opening and ending tag mismatch: name line 4 */ public function testLoadInvalidXml() { + $this->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..10c339c 100644 --- a/tests/Parser/YamlTest.php +++ b/tests/Parser/YamlTest.php @@ -36,22 +36,22 @@ public function testGetSupportedExtensions() /** * @covers Noodlehaus\Parser\Yaml::parseFile() * @covers Noodlehaus\Parser\Yaml::parse() - * @expectedException Noodlehaus\Exception\ParseException - * @expectedExceptionMessage Error parsing YAML file */ public function testLoadInvalidYamlFile() { + $this->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..e6c1ee8 100644 --- a/tests/Writer/IniTest.php +++ b/tests/Writer/IniTest.php @@ -97,11 +97,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..8a7af7c 100644 --- a/tests/Writer/JsonTest.php +++ b/tests/Writer/JsonTest.php @@ -90,11 +90,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..c00d0b3 100644 --- a/tests/Writer/PropertiesTest.php +++ b/tests/Writer/PropertiesTest.php @@ -98,11 +98,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..f7ead17 100644 --- a/tests/Writer/SerializeTest.php +++ b/tests/Writer/SerializeTest.php @@ -90,11 +90,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..73a8aad 100644 --- a/tests/Writer/XmlTest.php +++ b/tests/Writer/XmlTest.php @@ -95,11 +95,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..0a47e2c 100644 --- a/tests/Writer/YamlTest.php +++ b/tests/Writer/YamlTest.php @@ -99,11 +99,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); From bea67ffa6d5cb7c9b0b0c5502ac25a6299262d51 Mon Sep 17 00:00:00 2001 From: Davide Pastore Date: Thu, 30 Dec 2021 17:24:13 +0100 Subject: [PATCH 4/4] Use ExpectException polyfill --- tests/ConfigTest.php | 2 ++ tests/Parser/IniTest.php | 4 +++- tests/Parser/JsonTest.php | 4 +++- tests/Parser/PhpTest.php | 4 +++- tests/Parser/SerializeTest.php | 4 +++- tests/Parser/XmlTest.php | 4 +++- tests/Parser/YamlTest.php | 4 +++- tests/Writer/IniTest.php | 2 ++ tests/Writer/JsonTest.php | 2 ++ tests/Writer/PropertiesTest.php | 2 ++ tests/Writer/SerializeTest.php | 2 ++ tests/Writer/XmlTest.php | 2 ++ tests/Writer/YamlTest.php | 2 ++ 13 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index c295125..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 */ diff --git a/tests/Parser/IniTest.php b/tests/Parser/IniTest.php index 3a4b152..35ec8c5 100644 --- a/tests/Parser/IniTest.php +++ b/tests/Parser/IniTest.php @@ -1,14 +1,16 @@