1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
From: Jordi Boggiano <j.boggiano@seld.be>
Date: Wed, 9 Dec 2020 13:13:14 +0100
Subject: Try to re-enable 8.1 build using phpunit 9
Origin: backport, https://github.com/Seldaek/jsonlint/commit/62cb5df89677559cefb10bb9787a73816538060d
---
tests/JsonParserTest.php | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/tests/JsonParserTest.php b/tests/JsonParserTest.php
index 4b17a69..042f2e2 100644
--- a/tests/JsonParserTest.php
+++ b/tests/JsonParserTest.php
@@ -73,7 +73,7 @@ class JsonParserTest extends TestCase
}');
$this->fail('Invalid trailing comma should be detected');
} catch (ParsingException $e) {
- $this->assertContains('It appears you have an extra trailing comma', $e->getMessage());
+ $this->assertStringContainsStringCompat('It appears you have an extra trailing comma', $e->getMessage());
}
}
@@ -86,7 +86,7 @@ class JsonParserTest extends TestCase
}');
$this->fail('Invalid quotes for string should be detected');
} catch (ParsingException $e) {
- $this->assertContains('Invalid string, it appears you used single quotes instead of double quotes', $e->getMessage());
+ $this->assertStringContainsStringCompat('Invalid string, it appears you used single quotes instead of double quotes', $e->getMessage());
}
}
@@ -99,7 +99,7 @@ class JsonParserTest extends TestCase
}');
$this->fail('Invalid unescaped string should be detected');
} catch (ParsingException $e) {
- $this->assertContains('Invalid string, it appears you have an unescaped backslash at: \z', $e->getMessage());
+ $this->assertStringContainsStringCompat('Invalid string, it appears you have an unescaped backslash at: \z', $e->getMessage());
}
}
@@ -148,7 +148,7 @@ EXPECTED;
$parser->parse('{"bar": "foo}');
$this->fail('Invalid unterminated string should be detected');
} catch (ParsingException $e) {
- $this->assertContains('Invalid string, it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid', $e->getMessage());
+ $this->assertStringContainsStringCompat('Invalid string, it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid', $e->getMessage());
}
}
@@ -160,7 +160,7 @@ EXPECTED;
bar"}');
$this->fail('Invalid multi-line string should be detected');
} catch (ParsingException $e) {
- $this->assertContains('Invalid string, it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid', $e->getMessage());
+ $this->assertStringContainsStringCompat('Invalid string, it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid', $e->getMessage());
}
}
@@ -173,7 +173,7 @@ bar"}');
');
$this->fail('Empty string should be invalid');
} catch (ParsingException $e) {
- $this->assertContains("Parse error on line 1:\n\n^", $e->getMessage());
+ $this->assertStringContainsStringCompat("Parse error on line 1:\n\n^", $e->getMessage());
}
}
@@ -193,7 +193,7 @@ bar"}');
$parser->parse('{"a":"b", "a":"c"}', JsonParser::DETECT_KEY_CONFLICTS);
$this->fail('Duplicate keys should not be allowed');
} catch (DuplicateKeyException $e) {
- $this->assertContains('Duplicate key: a', $e->getMessage());
+ $this->assertStringContainsStringCompat('Duplicate key: a', $e->getMessage());
$this->assertSame('a', $e->getKey());
$this->assertSame(array('line' => 1, 'key' => 'a'), $e->getDetails());
}
@@ -210,7 +210,7 @@ bar"}');
$parser->parse('{"":"b", "_empty_":"a"}', JsonParser::DETECT_KEY_CONFLICTS);
$this->fail('Duplicate keys should not be allowed');
} catch (DuplicateKeyException $e) {
- $this->assertContains('Duplicate key: _empty_', $e->getMessage());
+ $this->assertStringContainsStringCompat('Duplicate key: _empty_', $e->getMessage());
$this->assertSame('_empty_', $e->getKey());
$this->assertSame(array('line' => 1, 'key' => '_empty_'), $e->getDetails());
}
@@ -262,7 +262,7 @@ bar"}');
$parser->parse((string) file_get_contents(dirname(__FILE__) .'/bom.json'));
$this->fail('BOM should be detected');
} catch (ParsingException $e) {
- $this->assertContains('BOM detected', $e->getMessage());
+ $this->assertStringContainsStringCompat('BOM detected', $e->getMessage());
}
}
@@ -281,7 +281,16 @@ bar"}');
try {
$this->assertEquals('', $parser->parse('{"'));
} catch (ParsingException $e) {
- $this->assertContains('Invalid string, it appears you forgot to terminate a string', $e->getMessage());
+ $this->assertStringContainsStringCompat('Invalid string, it appears you forgot to terminate a string', $e->getMessage());
+ }
+ }
+
+ public function assertStringContainsStringCompat($needle, $haystack, $message = '')
+ {
+ if (method_exists($this, 'assertStringContainsString')) {
+ $this->assertStringContainsString($needle, $haystack, $message);
+ } else {
+ $this->assertContains($needle, $haystack, $message);
}
}
}
|