@@ -17,25 +17,28 @@ protected function setUp(): void
1717 parent ::setUp ();
1818
1919 $ this ->fileHandler = new FileHandler ();
20+ fopen (filename: "file " , mode: "w " );
21+
2022 }
2123
2224 protected function tearDown (): void
2325 {
2426 parent ::tearDown ();
2527
2628 $ this ->fileHandler = null ;
29+ unlink (filename: "file " );
2730 }
2831
2932
3033 #[Test]
3134 #[TestDox("file was written successfully! " )]
3235 public function file_successfully_written ()
3336 {
34- $ this ->fileHandler ->open (filename: 'file.txt ' );
37+ $ this ->fileHandler ->open (filename: 'file ' );
3538
3639 $ this ->fileHandler ->write (data: "hello world " );
3740
38- $ this ->assertEquals (expected: "hello world " , actual: file_get_contents (filename: 'file.txt ' ));
41+ $ this ->assertEquals (expected: "hello world " , actual: file_get_contents (filename: 'file ' ));
3942 }
4043
4144 #[Test]
@@ -44,15 +47,14 @@ public function should_throw_exception_if_file_is_not_Found()
4447 {
4548 $ this ->expectException (FileNotFoundException::class);
4649 $ this ->expectExceptionMessage ('File not found ' );
47- $ this ->fileHandler ->open (filename: 'unknown ' , mode: ' r ' );
50+ $ this ->fileHandler ->open (filename: 'unknown ' );
4851 }
4952
5053 #[Test]
5154 #[TestDox("should throw an exception if file is not writable " )]
5255 public function should_throw_exception_if_file_is_not_writable ()
5356 {
54-
55- $ this ->fileHandler ->open (filename: 'file ' , mode: 'r ' );
57+ $ this ->fileHandler ->open (filename: 'file ' ,mode: 'r ' );
5658
5759 $ this ->expectException (CouldNotWriteFileException::class);
5860 $ this ->expectExceptionMessage ('Error writing to file ' );
@@ -65,13 +67,15 @@ public function multiple_file_can_be_written_simultaneously()
6567 {
6668 $ this ->fileHandler ->open (filename: 'file ' );
6769
68- $ this ->fileHandler ->open (filename: 'file1 ' );
70+ $ this ->fileHandler ->open (filename: 'file1 ' ,mode: ' w ' );
6971
7072 $ this ->fileHandler ->write (data: "hello world " );
7173
7274 $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file ' ));
7375
7476 $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file1 ' ));
77+
78+ unlink ("file1 " );
7579 }
7680
7781
@@ -85,11 +89,6 @@ public function file_is_closed_properly()
8589
8690 $ this ->expectException (TypeError::class);
8791 $ this ->fileHandler ->write (data: "fwrite(): supplied resource is not a valid stream resource " );
88-
89-
90-
91-
9292 }
9393
94-
9594}
0 commit comments