Skip to content

Commit fd62a1b

Browse files
committed
adjust the output string for testing
1 parent 6ede915 commit fd62a1b

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

src/Behavioral/Command/Receiver/UnixFileSystem.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66

77
final class UnixFileSystem implements FileSystem
88
{
9-
private string $fileName = 'unix_file';
9+
private string $fileName = 'file.sh';
1010

1111
public function openFile(): void
1212
{
13-
printf('Unix file %s is open\n', $this->fileName);
13+
printf("Unix file %s is open", $this->fileName);
1414
}
1515

1616
public function writeFile(string $content): void
1717
{
18-
printf('Unix file %s is writing\n', $this->fileName);
19-
printf('Content: %s\n', $content);
18+
printf("Unix file %s is writing of the contents: %s", $this->fileName, $content);
2019
}
2120

2221
public function closeFile(): void
2322
{
24-
printf('Unix file %s is closed\n', $this->fileName);
23+
printf("Unix file %s is closed", $this->fileName);
2524
}
2625
}

src/Behavioral/Command/Receiver/WindowsFileSystem.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66

77
final class WindowsFileSystem implements FileSystem
88
{
9-
private string $fileName = 'windows_file';
9+
private string $fileName = 'file.bat';
1010

1111
public function openFile(): void
1212
{
13-
printf('Windows file %s is open\n', $this->fileName);
13+
printf("Windows file %s is open", $this->fileName);
1414
}
1515

1616
public function writeFile(string $content): void
1717
{
18-
printf('Windows file %s is writing\n', $this->fileName);
19-
printf('Content: %s' . PHP_EOL, $content);
18+
printf("Windows file %s is writing of the contents: %s", $this->fileName, $content);
2019
}
2120

2221
public function closeFile(): void
2322
{
24-
printf('Windows file %s is closed\n', $this->fileName);
23+
printf("Windows file %s is closed", $this->fileName);
2524
}
2625
}

tests/Behavioral/Command/CommandTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace Growthdev\DesignPatterns\Tests\Behavioral\Command;
66

7+
use Growthdev\DesignPatterns\Behavioral\Command\CloseFileCommand;
78
use Growthdev\DesignPatterns\Behavioral\Command\FileInvoker;
89
use Growthdev\DesignPatterns\Behavioral\Command\OpenFileCommand;
910
use Growthdev\DesignPatterns\Behavioral\Command\Receiver\FileSystem;
1011
use Growthdev\DesignPatterns\Behavioral\Command\Receiver\UnixFileSystem;
1112
use Growthdev\DesignPatterns\Behavioral\Command\Receiver\WindowsFileSystem;
13+
use Growthdev\DesignPatterns\Behavioral\Command\WriteFileCommand;
1214
use PHPUnit\Framework\TestCase;
1315

1416
final class CommandTest extends TestCase
@@ -20,10 +22,36 @@ private static function getFileSystem(): FileSystem
2022
return $os ? new UnixFileSystem() : new WindowsFileSystem();
2123
}
2224

23-
public function testCanInvokeFile(): void
25+
public function testCanExecuteOpenFileCommand(): void
2426
{
25-
$this->getFileSystem();
27+
$openFile = new OpenFileCommand(self::getFileSystem());
28+
29+
$invoker = new FileInvoker($openFile);
30+
$invoker->execute();
31+
32+
$this->expectOutputString("Unix file file.sh is open");
33+
}
34+
35+
public function testCanExecuteWrittingFileCommand(): void
36+
{
37+
$writeFile = new WriteFileCommand(
38+
self::getFileSystem(),
39+
'sh unix command'
40+
);
41+
42+
$invoker = new FileInvoker($writeFile);
43+
$invoker->execute();
44+
45+
$this->expectOutputString("Unix file file.sh is writing of the contents: sh unix command");
46+
}
2647

48+
public function testCanExecuteCloseFileCommand(): void
49+
{
50+
$closeFile = new CloseFileCommand(self::getFileSystem());
2751

52+
$invoker = new FileInvoker($closeFile);
53+
$invoker->execute();
54+
55+
$this->expectOutputString("Unix file file.sh is closed");
2856
}
2957
}

0 commit comments

Comments
 (0)