1313
1414use PHPUnit \Framework \ExpectationFailedException ;
1515use PHPUnit \Framework \TestCase ;
16+ use Symfony \Component \HttpFoundation \File \Exception \FileNotFoundException ;
1617
1718class AssertTraitTest extends TestCase
1819{
@@ -25,24 +26,30 @@ public function testAssertJsonMatchesSchemaSimple()
2526 {
2627 $ content = json_decode (file_get_contents (Utils::getJsonPath ('assertJsonMatchesSchema_simple.json ' )));
2728
28- AssertTraitImpl::assertJsonMatchesSchemaDepr ( Utils::getSchemaPath ('assertJsonMatchesSchema_simple.schema.json ' ), $ content );
29+ AssertTraitImpl::assertJsonMatchesSchema ( $ content , Utils::getSchemaPath ('assertJsonMatchesSchema_simple.schema.json ' ));
2930 }
3031
3132 public function testAssertJsonMatchesSchema ()
3233 {
3334 $ content = json_decode ('{"foo":123} ' );
3435
35- AssertTraitImpl::assertJsonMatchesSchemaDepr ( Utils::getSchemaPath ('test.schema.json ' ), $ content );
36+ AssertTraitImpl::assertJsonMatchesSchema ( $ content , Utils::getSchemaPath ('test.schema.json ' ));
3637 }
3738
38- /**
39- * @expectedException \PHPUnit\Framework\ExpectationFailedException
40- */
4139 public function testAssertJsonMatchesSchemaFail ()
4240 {
41+ $ this ->expectException (ExpectationFailedException::class);
4342 $ content = json_decode ('{"foo":"123"} ' );
4443
45- AssertTraitImpl::assertJsonMatchesSchemaDepr (Utils::getSchemaPath ('test.schema.json ' ), $ content );
44+ AssertTraitImpl::assertJsonMatchesSchema ($ content , Utils::getSchemaPath ('test.schema.json ' ));
45+ }
46+ 47+ public function testAssertThrowsFileNotFoundException ()
48+ {
49+ $ this ->expectException (FileNotFoundException::class);
50+ $ content = json_decode ('{"foo":"123"} ' );
51+ 52+ AssertTraitImpl::assertJsonMatchesSchema ($ content , 'not-found.json ' );
4653 }
4754
4855 public function testAssertJsonMatchesSchemaFailMessage ()
@@ -52,10 +59,10 @@ public function testAssertJsonMatchesSchemaFailMessage()
5259 $ exception = null ;
5360
5461 try {
55- AssertTraitImpl::assertJsonMatchesSchemaDepr ( Utils::getSchemaPath ('test.schema.json ' ), $ content );
62+ AssertTraitImpl::assertJsonMatchesSchema ( $ content , Utils::getSchemaPath ('test.schema.json ' ));
5663 } catch (ExpectationFailedException $ exception ) {
57- self ::assertContains ('- Property: foo, Contraint : type, Message: String value found, but an integer is required ' , $ exception ->getMessage ());
58- self ::assertContains ('- Response: {"foo":"123"} ' , $ exception ->getMessage ());
64+ self ::assertStringContainsString ('- Property: foo, Constraint : type, Message: String value found, but an integer is required ' , $ exception ->getMessage ());
65+ self ::assertStringContainsString ('- Response: {"foo":"123"} ' , $ exception ->getMessage ());
5966 }
6067
6168 self ::assertInstanceOf ('\PHPUnit\Framework\ExpectationFailedException ' , $ exception );
@@ -68,17 +75,15 @@ public function testAssertJsonMatchesSchemaWithRefs()
6875 {
6976 $ content = json_decode ('{"code":123, "message":"Nothing works."} ' );
7077
71- AssertTraitImpl::assertJsonMatchesSchemaDepr ( Utils::getSchemaPath ('error.schema.json ' ), $ content );
78+ AssertTraitImpl::assertJsonMatchesSchema ( $ content , Utils::getSchemaPath ('error.schema.json ' ));
7279 }
7380
74- /**
75- * @expectedException \PHPUnit\Framework\ExpectationFailedException
76- */
7781 public function testAssertJsonMatchesSchemaWithRefsFails ()
7882 {
83+ $ this ->expectException (ExpectationFailedException::class);
7984 $ content = json_decode ('{"code":"123", "message":"Nothing works."} ' );
8085
81- AssertTraitImpl::assertJsonMatchesSchemaDepr ( Utils::getSchemaPath ('error.schema.json ' ), $ content );
86+ AssertTraitImpl::assertJsonMatchesSchema ( $ content , Utils::getSchemaPath ('error.schema.json ' ));
8287 }
8388
8489 public function testAssertJsonMatchesSchemaString ()
@@ -97,7 +102,7 @@ public function testAssertJsonMatchesSchemaString()
97102 * @param string $expression
98103 * @param mixed $value
99104 */
100- public function testAssertJsonValueEquals ($ expression , $ value )
105+ public function testAssertJsonValueEquals (string $ expression , $ value )
101106 {
102107 $ content = json_decode (file_get_contents (Utils::getJsonPath ('testAssertJsonValueEquals.json ' )));
103108
@@ -109,28 +114,26 @@ public function testAssertWithSchemaStore()
109114 $ obj = new AssertTraitImpl ();
110115 $ obj ->setUp ();
111116
112- $ schemastore = $ obj ->testWithSchemaStore ('foobar ' , (object ) ['type ' => 'string ' ]);
117+ $ schemaStore = $ obj ->testWithSchemaStore ('foobar ' , (object ) ['type ' => 'string ' ]);
113118
114- self ::assertInstanceOf ('JsonSchema\SchemaStorage ' , $ schemastore );
115- self ::assertEquals ($ schemastore ->getSchema ('foobar ' ), (object ) ['type ' => 'string ' ]);
119+ self ::assertInstanceOf ('JsonSchema\SchemaStorage ' , $ schemaStore );
120+ self ::assertEquals ($ schemaStore ->getSchema ('foobar ' ), (object ) ['type ' => 'string ' ]);
116121 }
117122
118- public function assertJsonValueEqualsProvider ()
123+ public function assertJsonValueEqualsProvider (): array
119124 {
120125 return [
121126 ['foo ' , '123 ' ],
122127 ['a.b.c[0].d[1][0] ' , 1 ],
123128 ];
124129 }
125130
126- /**
127- * @expectedException \PHPUnit\Framework\ExpectationFailedException
128- */
129131 public function testAssertJsonValueEqualsFailsOnWrongDataType ()
130132 {
133+ $ this ->expectException (ExpectationFailedException::class);
131134 $ content = json_decode (file_get_contents (Utils::getJsonPath ('testAssertJsonValueEquals.json ' )));
132135
133- AssertTraitImpl::assertJsonValueEquals ($ content , 'a.b.c[0].d[1][0] ' , '1 ' );
136+ AssertTraitImpl::assertJsonValueEquals ($ content , 'a.b.c[0].d[1][0] ' , '{} ' );
134137 }
135138
136139 /**
@@ -141,7 +144,7 @@ public function testGetJsonObject($expected, $actual)
141144 self ::assertEquals ($ expected , AssertTraitImpl::getJsonObject ($ actual ));
142145 }
143146
144- public function jsonObjectProvider ()
147+ public function jsonObjectProvider (): array
145148 {
146149 return [
147150 [[], []],
0 commit comments