diff --git a/Tests/Command/LintCommandTest.php b/Tests/Command/LintCommandTest.php index 4b9788c1..5ad032bf 100644 --- a/Tests/Command/LintCommandTest.php +++ b/Tests/Command/LintCommandTest.php @@ -92,7 +92,7 @@ public function testCustomTagsError() public function testLintFileNotReadable() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $tester = $this->createCommandTester(); $filename = $this->createFile(''); unlink($filename); diff --git a/Tests/DumperTest.php b/Tests/DumperTest.php index 41c8b02c..7f3e245f 100644 --- a/Tests/DumperTest.php +++ b/Tests/DumperTest.php @@ -194,7 +194,7 @@ public function testObjectSupportDisabledButNoExceptions() public function testObjectSupportDisabledWithExceptions() { - $this->expectException('Symfony\Component\Yaml\Exception\DumpException'); + $this->expectException(\Symfony\Component\Yaml\Exception\DumpException::class); $this->dumper->dump(['foo' => new A(), 'bar' => 1], 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE); } @@ -619,14 +619,14 @@ public function testDumpTrailingNewlineInMultiLineLiteralBlocks() public function testZeroIndentationThrowsException() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The indentation must be greater than zero'); new Dumper(0); } public function testNegativeIndentationThrowsException() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The indentation must be greater than zero'); new Dumper(-4); } diff --git a/Tests/InlineTest.php b/Tests/InlineTest.php index 261e4304..acbde08a 100644 --- a/Tests/InlineTest.php +++ b/Tests/InlineTest.php @@ -69,14 +69,14 @@ public function getTestsForParsePhpConstants() public function testParsePhpConstantThrowsExceptionWhenUndefined() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('The constant "WRONG_CONSTANT" is not defined'); Inline::parse('!php/const WRONG_CONSTANT', Yaml::PARSE_CONSTANT); } public function testParsePhpConstantThrowsExceptionOnInvalidType() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('#The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#'); Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } @@ -120,60 +120,60 @@ public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedTo public function testParseScalarWithNonEscapedBlackslashShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Found unknown escape character "\V".'); Inline::parse('"Foo\Var"'); } public function testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Inline::parse('"Foo\\"'); } public function testParseScalarWithIncorrectlyQuotedStringShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $value = "'don't do somthin' like that'"; Inline::parse($value); } public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $value = '"don"t do somthin" like that"'; Inline::parse($value); } public function testParseInvalidMappingKeyShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $value = '{ "foo " bar": "bar" }'; Inline::parse($value); } public function testParseMappingKeyWithColonNotFollowedBySpace() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}")'); Inline::parse('{foo:""}'); } public function testParseInvalidMappingShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Inline::parse('[foo] bar'); } public function testParseInvalidSequenceShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Inline::parse('{ foo: bar } bar'); } public function testParseInvalidTaggedSequenceShouldThrowException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS); } @@ -219,14 +219,14 @@ public function testParseMapReferenceInSequence() public function testParseUnquotedAsterisk() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('A reference must contain at least one character at line 1.'); Inline::parse('{ foo: * }'); } public function testParseUnquotedAsteriskFollowedByAComment() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('A reference must contain at least one character at line 1.'); Inline::parse('{ foo: * #foo }'); } @@ -613,7 +613,7 @@ public function getBinaryData() */ public function testParseInvalidBinaryData($data, $expectedMessage) { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches($expectedMessage); Inline::parse($data); @@ -631,7 +631,7 @@ public function getInvalidBinaryData() public function testNotSupportedMissingValue() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Malformed inline YAML string: "{this, is not, supported}" at line 1.'); Inline::parse('{this, is not, supported}'); } @@ -648,7 +648,7 @@ public function testVeryLongQuotedStrings() public function testMappingKeysCannotBeOmitted() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Missing mapping key'); Inline::parse('{: foo}'); } @@ -679,7 +679,7 @@ public function testTheEmptyStringIsAValidMappingKey() */ public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected) { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead'); $this->assertSame($expected, Inline::parse($yaml)); } @@ -732,7 +732,7 @@ public function testTagWithEmptyValueInMapping() public function testUnfinishedInlineMap() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage("Unexpected end of line, expected one of \",}\n\" at line 1 (near \"{abc: 'def'\")."); Inline::parse("{abc: 'def'"); } diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index feec9998..6bf904a0 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -514,7 +514,7 @@ public function getObjectForMapTests() public function testObjectsSupportDisabledWithExceptions() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $yaml = <<<'EOF' foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} bar: 1 @@ -564,14 +564,14 @@ public function testNonUtf8Exception() $this->fail('charsets other than UTF-8 are rejected.'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Yaml\Exception\ParseException', $e, 'charsets other than UTF-8 are rejected.'); + $this->assertInstanceOf(ParseException::class, $e, 'charsets other than UTF-8 are rejected.'); } } } public function testUnindentedCollectionException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $yaml = <<<'EOF' collection: @@ -586,7 +586,7 @@ public function testUnindentedCollectionException() public function testShortcutKeyUnindentedCollectionException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $yaml = <<<'EOF' collection: @@ -600,7 +600,7 @@ public function testShortcutKeyUnindentedCollectionException() public function testMultipleDocumentsNotSupportedException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('/^Multiple documents are not supported.+/'); Yaml::parse(<<<'EOL' # Ranking of 1998 home runs @@ -619,7 +619,7 @@ public function testMultipleDocumentsNotSupportedException() public function testSequenceInAMapping() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Yaml::parse(<<<'EOF' yaml: hash: me @@ -727,7 +727,7 @@ public function getParseExceptionNotAffectedMultiLineStringLastResortParsing() */ public function testParseExceptionNotAffectedByMultiLineStringLastResortParsing($yaml) { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->parser->parse($yaml); } @@ -759,7 +759,7 @@ public function testMultiLineStringLastResortParsing() public function testMappingInASequence() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); Yaml::parse(<<<'EOF' yaml: - array stuff @@ -770,7 +770,7 @@ public function testMappingInASequence() public function testScalarInSequence() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('missing colon'); Yaml::parse(<<<'EOF' foo: @@ -793,7 +793,7 @@ public function testScalarInSequence() */ public function testMappingDuplicateKeyBlock() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Duplicate key "child" detected'); $input = <<<'EOD' parent: @@ -813,7 +813,7 @@ public function testMappingDuplicateKeyBlock() public function testMappingDuplicateKeyFlow() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Duplicate key "child" detected'); $input = <<<'EOD' parent: { child: first, child: duplicate } @@ -832,7 +832,7 @@ public function testMappingDuplicateKeyFlow() */ public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber) { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage(sprintf('Duplicate key "%s" detected at line %d', $duplicateKey, $lineNumber)); Yaml::parse($input); @@ -1058,7 +1058,7 @@ public function testYamlDirective() public function testFloatKeys() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Numeric keys are not supported. Quote your evaluable mapping keys instead'); $yaml = <<<'EOF' foo: @@ -1071,7 +1071,7 @@ public function testFloatKeys() public function testBooleanKeys() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Non-string keys are not supported. Quote your evaluable mapping keys instead'); $yaml = <<<'EOF' true: foo @@ -1108,7 +1108,7 @@ public function testExplicitStringCasting() public function testColonInMappingValueException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('A colon cannot be used in an unquoted mapping value'); $yaml = <<<'EOF' foo: bar: baz @@ -1346,7 +1346,7 @@ public function getBinaryData() */ public function testParseInvalidBinaryData($data, $expectedMessage) { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->parser->parse($data); @@ -2168,35 +2168,35 @@ public function testNonSpecificTagSupport() public function testCustomTagsDisabled() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Tags support is not enabled. Enable the "Yaml::PARSE_CUSTOM_TAGS" flag to use "!iterator" at line 1 (near "!iterator [foo]").'); $this->parser->parse('!iterator [foo]'); } public function testUnsupportedTagWithScalar() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Tags support is not enabled. Enable the "Yaml::PARSE_CUSTOM_TAGS" flag to use "!iterator" at line 1 (near "!iterator foo").'); $this->parser->parse('!iterator foo'); } public function testUnsupportedBuiltInTagWithScalar() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('The string "!!iterator foo" could not be parsed as it uses an unsupported built-in tag at line 1 (near "!!iterator foo").'); $this->parser->parse('!!iterator foo'); } public function testExceptionWhenUsingUnsupportedBuiltInTags() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('The built-in tag "!!foo" is not implemented at line 1 (near "!!foo").'); $this->parser->parse('!!foo'); } public function testComplexMappingThrowsParseException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 1 (near "? "1"").'); $yaml = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 2 (near "? "1"").'); $yaml = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 1 (near "- ? "1"").'); $yaml = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Unable to parse at line 2 (near " foo = bar").'); $ini = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Reference "foo" does not exist at line 2'); $yaml = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('#^File ".+/Fixtures/nonexistent.yml" does not exist\.$#'); $this->parser->parseFile(__DIR__.'/Fixtures/nonexistent.yml'); } public function testParsingNotReadableFilesThrowsException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('#^File ".+/Fixtures/not_readable.yml" cannot be read\.$#'); if ('\\' === \DIRECTORY_SEPARATOR) { $this->markTestSkipped('chmod is not supported on Windows'); @@ -2497,7 +2497,7 @@ public function testParseReferencesOnMergeKeysWithMappingsParsedAsObjects() public function testEvalRefException() { - $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Reference "foo" does not exist'); $yaml = <<expectException('Symfony\Component\Yaml\Exception\ParseException'); + $this->expectException(ParseException::class); $this->expectExceptionMessage('Circular reference [foo, bar, foo] detected'); $this->parser->parse($yaml, Yaml::PARSE_CUSTOM_TAGS); } diff --git a/Tests/YamlTest.php b/Tests/YamlTest.php index 7be12664..151b5b9d 100644 --- a/Tests/YamlTest.php +++ b/Tests/YamlTest.php @@ -26,14 +26,14 @@ public function testParseAndDump() public function testZeroIndentationThrowsException() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The indentation must be greater than zero'); Yaml::dump(['lorem' => 'ipsum', 'dolor' => 'sit'], 2, 0); } public function testNegativeIndentationThrowsException() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The indentation must be greater than zero'); Yaml::dump(['lorem' => 'ipsum', 'dolor' => 'sit'], 2, -4); }