forked from the-crucible/phpunit-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
33JsonStringEqualsJsonFile.php
40 lines (36 loc) · 992 Bytes
/
33JsonStringEqualsJsonFile.php
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
<?php
/**
* assertJsonStringEqualsJsonFile(
* mixed $expectedFile,
* mixed $actualJson[,
* string $message = '']
* )
*
* Reports an error identified by $message if the value of $actualJson does not
* match the value of $expectedFile.
*/
define('DS', DIRECTORY_SEPARATOR);
define('D_DIR' , dirname(__FILE__) . DS . 'data' . DS);
class JsonStringEqualsJsonFileTest extends PHPUnit_Framework_TestCase
{
/**
* This will fail because json is different
*/
public function testFailure()
{
$this->assertJsonStringEqualsJsonFile(
D_DIR . 'file2.json', "{\"a\":\"b\", \"c\":\"e\"} "
);
}
/**
* This will pass irrespective of the fact that content is
* different but json is same (Again there are extra white space)
*/
public function testSuccess()
{
$this->assertJsonStringEqualsJsonFile(
D_DIR . 'file2.json', "{\"a\":\"b\", \"c\":\"d\"} "
);
}
}
?>