Skip to content

Commit a79d7d7

Browse files
committed
added test for filesDiffCommand
1 parent 9fc8279 commit a79d7d7

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/FilesDiffCommandTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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(FilesDiffCommand::class)]
11+
#[CoversClass(FileReader::class)]
12+
#[CoversMethod(FilesDiffCommand::class, 'setFileReader')]
13+
#[CoversMethod(FilesDiffCommand::class, 'execute')]
14+
class FilesDiffCommandTest extends TestCase
15+
{
16+
private $fileNames;
17+
18+
protected function setUp(): void
19+
{
20+
$this->fileNames = [
21+
"FILE1" => __DIR__ . "/../file1.json",
22+
"FILE2" => __DIR__ . "/../file2.json"
23+
];
24+
}
25+
26+
public function testSetFileReader()
27+
{
28+
$diffCommand = new FilesDiffCommand();
29+
30+
$this->assertInstanceOf(
31+
FilesDiffCommand::class,
32+
$diffCommand->setFileReader(new FileReader()));
33+
}
34+
35+
public function testExecute()
36+
{
37+
$cmdLineParser = $this->createConfiguredStub(
38+
CommandLineParser::class,
39+
[
40+
'getFileNames' => $this->fileNames
41+
]
42+
);
43+
44+
$diffCommand = new FilesDiffCommand();
45+
46+
$resultContent = $diffCommand->setFileReader(new FileReader())
47+
->execute($cmdLineParser)
48+
->getFilesContent();
49+
50+
$this->assertStringEqualsFile(
51+
__DIR__ . "/../fixtures/filesContent.txt",
52+
$resultContent
53+
);
54+
55+
$resultDiffs = $diffCommand->setFileReader(new FileReader())
56+
->execute($cmdLineParser)
57+
->getFilesDiffs();
58+
59+
$this->assertStringEqualsFile(
60+
__DIR__ . "/../fixtures/filesDiffs.txt",
61+
$resultDiffs
62+
);
63+
}
64+
}

0 commit comments

Comments
 (0)