13
13
14
14
class AssertTraitTest extends \PHPUnit_Framework_TestCase
15
15
{
16
- private static function getSchema ($ filename )
17
- {
18
- return implode (DIRECTORY_SEPARATOR , [__DIR__ , 'schemas ' , $ filename ]);
19
- }
20
-
21
- private static function getJson ($ filename )
22
- {
23
- return implode (DIRECTORY_SEPARATOR , [__DIR__ , 'json ' , $ filename ]);
24
- }
25
-
26
- public function testAssertJsonSchema ()
16
+ public function testAssertJsonMatchesSchema ()
27
17
{
28
18
$ content = json_decode ('{"foo":123} ' );
29
19
30
- AssertTraitImpl::assertJsonMatchesSchema (self :: getSchema ('test.schema.json ' ), $ content );
20
+ AssertTraitImpl::assertJsonMatchesSchema (Utils:: getSchemaPath ('test.schema.json ' ), $ content );
31
21
}
32
22
33
23
/**
34
24
* @expectedException \PHPUnit_Framework_ExpectationFailedException
35
25
*/
36
- public function testAssertJsonSchemaFail ()
26
+ public function testAssertJsonMatchesSchemaFail ()
37
27
{
38
28
$ content = json_decode ('{"foo":"123"} ' );
39
29
40
- AssertTraitImpl::assertJsonMatchesSchema (self :: getSchema ('test.schema.json ' ), $ content );
30
+ AssertTraitImpl::assertJsonMatchesSchema (Utils:: getSchemaPath ('test.schema.json ' ), $ content );
41
31
}
42
32
43
- public function testAssertJsonSchemaFailMessage ()
33
+ public function testAssertJsonMatchesSchemaFailMessage ()
44
34
{
45
35
$ content = json_decode ('{"foo":"123"} ' );
46
36
47
37
$ exception = null ;
48
38
49
39
try {
50
- AssertTraitImpl::assertJsonMatchesSchema (self :: getSchema ('test.schema.json ' ), $ content );
40
+ AssertTraitImpl::assertJsonMatchesSchema (Utils:: getSchemaPath ('test.schema.json ' ), $ content );
51
41
} catch (\PHPUnit_Framework_ExpectationFailedException $ exception ) {
52
42
self ::assertContains ('- Property: foo, Contraint: type, Message: String value found, but an integer is required ' , $ exception ->getMessage ());
53
43
self ::assertContains ('- Response: {"foo":"123"} ' , $ exception ->getMessage ());
@@ -59,27 +49,27 @@ public function testAssertJsonSchemaFailMessage()
59
49
/**
60
50
* Tests if referenced schemas are loaded automatically.
61
51
*/
62
- public function testAssertJsonSchemaWithRefs ()
52
+ public function testAssertJsonMatchesSchemaWithRefs ()
63
53
{
64
54
$ content = json_decode ('{"code":123, "message":"Nothing works."} ' );
65
55
66
- AssertTraitImpl::assertJsonMatchesSchema (self :: getSchema ('error.schema.json ' ), $ content );
56
+ AssertTraitImpl::assertJsonMatchesSchema (Utils:: getSchemaPath ('error.schema.json ' ), $ content );
67
57
}
68
58
69
59
/**
70
60
* @expectedException \PHPUnit_Framework_ExpectationFailedException
71
61
*/
72
- public function testAssertJsonSchemaWithRefsFails ()
62
+ public function testAssertJsonMatchesSchemaWithRefsFails ()
73
63
{
74
64
$ content = json_decode ('{"code":"123", "message":"Nothing works."} ' );
75
65
76
- AssertTraitImpl::assertJsonMatchesSchema (self :: getSchema ('error.schema.json ' ), $ content );
66
+ AssertTraitImpl::assertJsonMatchesSchema (Utils:: getSchemaPath ('error.schema.json ' ), $ content );
77
67
}
78
68
79
69
public function testAssertJsonMatchesSchemaString ()
80
70
{
81
71
$ content = json_decode ('{"foo":123} ' );
82
- $ schema = file_get_contents (self :: getSchema ('test.schema.json ' ));
72
+ $ schema = file_get_contents (Utils:: getSchemaPath ('test.schema.json ' ));
83
73
84
74
AssertTraitImpl::assertJsonMatchesSchemaString ($ schema , $ content );
85
75
}
@@ -94,7 +84,7 @@ public function testAssertJsonMatchesSchemaString()
94
84
*/
95
85
public function testAssertJsonValueEquals ($ expression , $ value )
96
86
{
97
- $ content = json_decode (file_get_contents (self :: getJson ('testAssertJsonValueEquals.json ' )));
87
+ $ content = json_decode (file_get_contents (Utils:: getJsonPath ('testAssertJsonValueEquals.json ' )));
98
88
99
89
AssertTraitImpl::assertJsonValueEquals ($ value , $ expression , $ content );
100
90
}
@@ -112,7 +102,7 @@ public function assertJsonValueEqualsProvider()
112
102
*/
113
103
public function testAssertJsonValueEqualsFailsOnWrongDataType ()
114
104
{
115
- $ content = json_decode (file_get_contents (self :: getJson ('testAssertJsonValueEquals.json ' )));
105
+ $ content = json_decode (file_get_contents (Utils:: getJsonPath ('testAssertJsonValueEquals.json ' )));
116
106
117
107
AssertTraitImpl::assertJsonValueEquals ($ content , 'a.b.c[0].d[1][0] ' , '1 ' );
118
108
}
0 commit comments