44
55namespace Growthdev \DesignPatterns \Tests \Behavioral \Command ;
66
7+ use Growthdev \DesignPatterns \Behavioral \Command \CloseFileCommand ;
78use Growthdev \DesignPatterns \Behavioral \Command \FileInvoker ;
89use Growthdev \DesignPatterns \Behavioral \Command \OpenFileCommand ;
910use Growthdev \DesignPatterns \Behavioral \Command \Receiver \FileSystem ;
1011use Growthdev \DesignPatterns \Behavioral \Command \Receiver \UnixFileSystem ;
1112use Growthdev \DesignPatterns \Behavioral \Command \Receiver \WindowsFileSystem ;
13+ use Growthdev \DesignPatterns \Behavioral \Command \WriteFileCommand ;
1214use PHPUnit \Framework \TestCase ;
1315
1416final 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