44
55use PHPUnit \Framework \TestCase ;
66use PHPUnit \Framework \Attributes \CoversClass ;
7+ use PHPUnit \Framework \Attributes \CoversMethod ;
78use Differ \DisplayCommand ;
8- use Fixtures \CommandLineParsersStub ;
99
1010#[CoversClass(DisplayCommand::class)]
11+ #[CoversMethod(DisplayCommand::class, 'execute ' )]
1112class DisplayCommandTest extends TestCase
1213{
13- public $ displayCmd ;
14- private $ file1Content ;
15- private $ file2Content ;
14+ private $ filesContent ;
15+ private $ filesDiffs ;
16+ private $ filesDiffCmd ;
1617
1718 protected function setUp (): void
18- {
19- $ this ->displayCmd = new DisplayCommand ();
20-
21- $ this ->file1Content =
22- [
23- "id " => "none " ,
24- "host " => "hexlet.io " ,
25- "timeout " => 50
26- ];
27- $ this ->file2Content =
28- [
29- "timeout " => 20 ,
30- "verbose " => 1 ,
31- "host " => "hexlet.io "
32- ];
19+ {
20+ $ this ->filesContent = "file 1 content: \n" .
21+ "{ \n" .
22+ " 'id': 'none', \n" .
23+ " 'host': 'hexlet.io', \n" .
24+ " 'timeout': 50 \n" .
25+ "} \n" .
26+ "file 2 content: \n" .
27+ "{ \n" .
28+ " 'timeout': 20, \n" .
29+ " 'verbose': 1, \n" .
30+ " 'host': 'hexlet.io' \n" .
31+ "} \n" ;
32+
33+ $ this ->filesDiffs = "{ \n" .
34+ " + 'id': 'none', \n" .
35+ " 'host': 'hexlet.io', \n" .
36+ " - 'timeout': 50, \n" .
37+ " + 'timeout': 20, \n" .
38+ " + 'verbose': 1 \n" .
39+ "} \n" ;
40+
41+ $ this ->filesDiffCmd = $ this ->createConfiguredStub (
42+ FilesDiffCommand::class,
43+ [
44+ 'getFilesContent ' => $ this ->filesContent ,
45+ 'getFilesDiffs ' => $ this ->filesDiffs ,
46+ ]
47+ );
3348 }
3449
3550 public function testInstance ()
3651 {
37- $ this ->assertInstanceOf (DisplayCommand::class, $ this ->displayCmd );
52+ $ displayCmd = new DisplayCommand ();
53+
54+ $ this ->assertInstanceOf (DisplayCommand::class, $ displayCmd );
3855 }
3956
40- public function testExecute ()
57+ public function testFilesDiffs ()
4158 {
42- $ filesDiffCmd = $ this ->createConfiguredStub (
43- FilesDiffCommand::class,
44- [
45- 'getFilesContent ' =>
46- [
47- "FILE1 " => $ this ->file1Content ,
48- "FILE2 " => $ this ->file2Content
49- ]
50- ]
51- );
59+ $ displayCmd = new DisplayCommand ();
60+
61+ $ displayCmd ->execute ($ this ->filesDiffCmd );
62+ $ this ->expectOutputString ($ this ->filesDiffs );
63+ }
64+
65+ public function testFilesContent ()
66+ {
67+ $ displayCmd = new DisplayCommand ();
5268
53- $ this -> assertInstanceOf (DisplayCommand::class, $ this ->displayCmd
54- -> execute ( $ filesDiffCmd ) );
69+ $ displayCmd -> setMode ( " content " )-> execute ( $ this ->filesDiffCmd );
70+ $ this -> expectOutputString ( $ this -> filesContent );
5571 }
5672
57- public function testGetDiffs ()
73+ public function testUnknownDisplayMode ()
5874 {
59- $ this ->assertEquals ("{ \n} \n" , $ this ->displayCmd ->getDiffs ());
75+ $ displayCmd = new DisplayCommand ();
76+
77+ $ displayCmd ->setMode ("extra " )->execute ($ this ->filesDiffCmd );
78+ $ this ->expectOutputString ("error: unknown mode " );
6079 }
6180}
0 commit comments