Skip to content

Commit a005c4d

Browse files
committed
add test for CommandFactory
1 parent 140f6a1 commit a005c4d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/CommandFactoryTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Differ\tests;
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\CommandLineParser;
10+
use Differ\FilesDiffCommand;
11+
use Differ\DisplayCommand;
12+
13+
#[CoversClass(CommandFactory::class)]
14+
#[CoversClass(CommandLineParser::class)]
15+
#[CoversClass(FilesDiffCommand::class)]
16+
#[CoversClass(DisplayCommand::class)]
17+
class CommandFactoryTest extends TestCase
18+
{
19+
#[CoversFunction(CommandFactory::class, 'getCommand')]
20+
public function testGetCommand()
21+
{
22+
$fileHandler = fopen(__DIR__ . "/../fixtures/docopt.txt", 'r');
23+
$fileData = [];
24+
while (($docopt[] = fgets($fileHandler, 4096)) !== false);
25+
fclose($fileHandler);
26+
$docopt = implode("\n", $fileData);
27+
28+
$commandFactory = new CommandFactory($docopt);
29+
30+
// Test for CommandLineParse
31+
$this->assertInstanceOf(CommandLineParser::class, $commandFactory->getCommand('parse'));
32+
33+
// Test for FileDiffCommand
34+
$this->assertInstanceOf(FilesDiffCommand::class, $commandFactory->getCommand('difference'));
35+
36+
// Test for DisplayCommand
37+
$this->assertInstanceOf(DisplayCommand::class, $commandFactory->getCommand('show'));
38+
39+
// Test for undefined command
40+
$this->assertNull($commandFactory->getCommand('undefined'));
41+
}
42+
}

0 commit comments

Comments
 (0)