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 \CommandFactory ;
9+ use Differ \DisplayCommand ;
10+ use Differ \FilesDiffCommand ;
11+ use Differ \FileReader ;
12+
13+ #[CoversClass(ConsoleApp::class)]
14+ #[CoversClass(CommandFactory::class)]
15+ #[CoversClass(DisplayCommand::class)]
16+ #[CoversClass(FilesDiffCommand::class)]
17+ #[CoversClass(FileReader::class)]
18+ #[CoversMethod(ConsoleApp::class, 'run ' )]
19+ class ConsoleAppTest extends TestCase
20+ {
21+ public function testConsoleAppRunning ()
22+ {
23+ $ outputString = "{ \n" .
24+ " hexlet.io \n" .
25+ " - 50 \n" .
26+ " + 20 \n" .
27+ " - 123.234.53.22 \n" .
28+ " - \n" .
29+ "} \n" ;
30+
31+ $ commandLineParserStubToGetContent = $ this ->createConfiguredStub (
32+ CommandLineParser::class,
33+ [
34+ 'getFileNames ' => [
35+ 'FILE1 ' => __DIR__ . "/../file1.json " ,
36+ 'FILE2 ' => __DIR__ . "/../file2.json "
37+ ]
38+ ]
39+ );
40+ $ cmdLineParserStub = $ this ->createConfiguredStub (
41+ CommandLineParser::class,
42+ [
43+ 'execute ' => $ commandLineParserStubToGetContent
44+ ]
45+ );
46+
47+ $ filesDiffCommand = new FilesDiffCommand ();
48+ $ displayCommand = new DisplayCommand ();
49+
50+ $ commandFactoryMock = $ this ->createMock (CommandFactory::class);
51+ $ commandFactoryMock ->expects ($ this ->exactly (3 ))
52+ ->method ('getCommand ' )
53+ ->willReturnMap ([
54+ ['parse ' , $ cmdLineParserStub ],
55+ ['difference ' , $ filesDiffCommand ],
56+ ['show ' , $ displayCommand ]
57+ ]);
58+ $ fileReader = new FileReader ();
59+
60+ $ consoleApp = new ConsoleApp ($ commandFactoryMock , $ fileReader );
61+ $ consoleApp ->run ();
62+
63+ $ this ->expectOutputString ($ outputString );
64+ }
65+ }
0 commit comments