mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 08:14:06 +02:00
Fix and merge branch 'isJson'
This commit is contained in:
@@ -766,6 +766,28 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsJson()
|
||||
{
|
||||
$testData = array(
|
||||
array(false, ''),
|
||||
array(false, '123'),
|
||||
array(true, '{"foo": "bar"}'),
|
||||
array(false, '{"foo":"bar",}'),
|
||||
array(false, '{"foo"}'),
|
||||
array(true, '["foo"]'),
|
||||
array(false, '{"foo": "bar"]'),
|
||||
array(false, '123', 'UTF-8'),
|
||||
array(true, '{"fòô": "bàř"}', 'UTF-8'),
|
||||
array(false, '{"fòô":"bàř",}', 'UTF-8'),
|
||||
array(false, '{"fòô"}', 'UTF-8'),
|
||||
array(false, '["fòô": "bàř"]', 'UTF-8'),
|
||||
array(true, '["fòô"]', 'UTF-8'),
|
||||
array(false, '{"fòô": "bàř"]', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsLowerCase()
|
||||
{
|
||||
$testData = array(
|
||||
|
@@ -471,6 +471,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsJson
|
||||
*/
|
||||
public function testIsJson($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isJson($str, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
|
@@ -556,6 +556,18 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsJson
|
||||
*/
|
||||
public function testIsJson($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isJson();
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
*/
|
||||
|
Reference in New Issue
Block a user