Skip to content

Commit 3b913f5

Browse files
committed
added tests for user functions
1 parent d8c814f commit 3b913f5

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/Differ.php

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

33
namespace Differ\Differ;
44

5+
use Differ\CommandFactory;
56
use Differ\CommandLineParser;
67
use Differ\FilesDiffCommand;
78
use Differ\FileReader;
89
use Differ\DisplayCommand;
910

1011
function genDiff(string $pathToFile1, string $pathToFile2)
1112
{
12-
$parserCommand = new CommandLineParser();
13+
$commandFactory = new CommandFactory();
14+
$parserCommand = $commandFactory->getCommand('parse');
1315
$fileNames = [
1416
"FILE1" => $pathToFile1,
1517
"FILE2" => $pathToFile2
1618
];
1719
$nextCommand = $parserCommand->setFileNames($fileNames);
1820

19-
$currentCommand = new FilesDiffCommand();
20-
$nextCommand = $currentCommand->setFileNames($nextCommand)
21-
->setFileReader(new FileReader())
22-
->execute();
21+
$currentCommand = $commandFactory->getCommand('difference');
22+
$nextCommand = $currentCommand->setFileReader(new FileReader())
23+
->execute($nextCommand);
2324

24-
$currentCommand = new DisplayCommand();
25-
return $currentCommand->execute($nextCommand)
26-
->getDiffs();
25+
$currentCommand = $commandFactory->getCommand('show');
26+
return $currentCommand->execute($nextCommand);
2727
}

tests/GendiffTest.php

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

33
namespace Differ;
44

5-
//require_once __DIR__ . '/../vendor/autoload.php';
6-
75
use PHPUnit\Framework\TestCase;
8-
use PHPUnit\Framework\Attributes\CoversFunction;
96
use PHPUnit\Framework\Attributes\CoversNothing;
107
use function Differ\runGendiff;
118

tests/genDiffUserTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Differ;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use PHPUnit\Framework\Attributes\CoversNothing;
7+
use function Differ\Differ\genDiff as genDiff;
8+
use Differ\CommandLineParser;
9+
use Differ\FilesDiffCommand;
10+
use Differ\FileReader;
11+
use Differ\DisplayCommand;
12+
13+
#[CoversNothing]
14+
class genDiffUserTest extends TestCase
15+
{
16+
function testFilesDiffer()
17+
{
18+
$outputString = "{\n" .
19+
" hexlet.io\n" .
20+
" - 50\n" .
21+
" + 20\n" .
22+
" - 123.234.53.22\n" .
23+
" - \n" .
24+
"}\n";
25+
26+
$this->expectOutputString($outputString);
27+
28+
genDiff(__DIR__ . "/../file1.json", __DIR__ . "/../file2.json");
29+
}
30+
}

0 commit comments

Comments
 (0)