1+ <?php
2+
3+ namespace Differ ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use PHPUnit \Framework \Attributes \CoversClass ;
7+ use PHPUnit \Framework \Attributes \CoversMethod ;
8+ use Differ \FileReader ;
9+
10+ #[CoversClass(FileReader::class)]
11+ #[CoversMethod(FileReader::class, 'readFile ' )]
12+ class FileReaderTest extends TestCase
13+ {
14+ public function testReadFileAsObject ()
15+ {
16+ $ fileReader = new FileReader ();
17+
18+ $ fileContent = $ fileReader ->readFile (
19+ __DIR__ . "/../fixtures/fileForArray.json " );
20+
21+ $ this ->assertJsonStringEqualsJsonFile (
22+ __DIR__ . "/../fixtures/fileForArray.json " ,
23+ json_encode ($ fileContent ));
24+ }
25+
26+ public function testReadFileAsArray ()
27+ {
28+ $ fileReader = new FileReader ();
29+
30+ $ fileContent = $ fileReader ->readFile (
31+ __DIR__ . "/../fixtures/fileForArray.json " ,
32+ true
33+ );
34+
35+ $ this ->assertJsonStringEqualsJsonFile (
36+ __DIR__ . "/../fixtures/fileForArray.json " ,
37+ json_encode ($ fileContent ));
38+ }
39+
40+ public function testReadFileNotJson ()
41+ {
42+ $ fileReader = new FileReader ();
43+
44+ $ fileContent = $ fileReader ->readFile (
45+ __DIR__ . "/../fixtures/fileNotJson.json "
46+ );
47+
48+ $ this ->assertNull ($ fileContent );
49+ }
50+ }
0 commit comments