Skip to content

Commit d8c814f

Browse files
committed
added test for gendiff
1 parent 7b0fe82 commit d8c814f

File tree

3 files changed

+63
-34
lines changed

3 files changed

+63
-34
lines changed

src/Gendiff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Differ;
44

5-
function runGendiff(): void
5+
function runGendiff(CommandFactoryInterface $commandFactory = null): void
66
{
77
$docopt = <<<'DOCOPT'
88
gendiff -h
@@ -21,7 +21,10 @@ function runGendiff(): void
2121

2222
DOCOPT;
2323

24-
$commandFactory = new CommandFactory($docopt);
24+
if (is_null($commandFactory)) {
25+
$commandFactory = new CommandFactory($docopt);
26+
}
27+
2528
$fileReader = new FileReader();
2629

2730
$consoleApp = new ConsoleApp($commandFactory, $fileReader);

tests/DifferTest.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/GendiffTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Differ;
4+
5+
//require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
use PHPUnit\Framework\TestCase;
8+
use PHPUnit\Framework\Attributes\CoversFunction;
9+
use PHPUnit\Framework\Attributes\CoversNothing;
10+
use function Differ\runGendiff;
11+
12+
#[CoversNothing]
13+
class GendiffTest extends TestCase
14+
{
15+
public function testRunGendiff()
16+
{
17+
$outputString = "{\n" .
18+
" hexlet.io\n" .
19+
" - 50\n" .
20+
" + 20\n" .
21+
" - 123.234.53.22\n" .
22+
" - \n" .
23+
"}\n";
24+
25+
$commandLineParserStubToGetContent = $this->createConfiguredStub(
26+
CommandLineParser::class,
27+
[
28+
'getFileNames' => [
29+
'FILE1' => __DIR__ . "/../file1.json",
30+
'FILE2' => __DIR__ . "/../file2.json"
31+
]
32+
]
33+
);
34+
$cmdLineParserStub = $this->createConfiguredStub(
35+
CommandLineParser::class,
36+
[
37+
'execute' => $commandLineParserStubToGetContent
38+
]
39+
);
40+
41+
$filesDiffCommand = new FilesDiffCommand();
42+
$displayCommand = new DisplayCommand();
43+
44+
$commandFactoryMock = $this->createMock(CommandFactory::class);
45+
$commandFactoryMock->expects($this->exactly(3))
46+
->method('getCommand')
47+
->willReturnMap([
48+
['parse', $cmdLineParserStub],
49+
['difference', $filesDiffCommand],
50+
['show', $displayCommand]
51+
]);
52+
53+
$this->expectOutputString(
54+
$outputString);
55+
56+
runGendiff($commandFactoryMock);
57+
}
58+
}

0 commit comments

Comments
 (0)