@@ -17,25 +17,40 @@ class FileHandlerTest extends TestCase
17
17
protected function setUp (): void
18
18
{
19
19
parent ::setUp ();
20
-
21
20
$ this ->fileHandler = new FileHandler ();
22
- fopen (filename: " file " , mode: " w " );
21
+ }
23
22
23
+ public static function setUpBeforeClass (): void
24
+ {
25
+ parent ::setUpBeforeClass ();
24
26
$ content = "Film,Genre,Lead Studio,Audience score %,Profitability,Rotten Tomatoes %,Worldwide Gross,Year \n"
25
27
. "Zack and Miri Make a Porno,Romance,The Weinstein Company,70,1.747541667,64,$41.94 ,2008 \n"
26
28
. "Youth in Revolt,Comedy,The Weinstein Company,52,1.09,68,$19.62 ,2010 \n"
27
29
. "Twilight,Romance,Independent,68,6.383363636,26,$702.17 ,2011 " ;
28
30
31
+ fopen (filename: "file " , mode: "w " );
32
+ fopen (filename: "file1 " , mode: "w " );
29
33
file_put_contents ('movie.csv ' , $ content );
30
34
}
31
35
36
+ public static function tearDownAfterClass (): void
37
+ {
38
+ parent ::tearDownAfterClass ();
39
+
40
+ $ files = ["file " , "movie.csv " , 'file1 ' ];
41
+
42
+ foreach ($ files as $ file ) {
43
+ if (file_exists ($ file )) {
44
+ unlink (filename: $ file );
45
+ }
46
+ }
47
+ }
48
+
32
49
protected function tearDown (): void
33
50
{
34
51
parent ::tearDown ();
35
52
36
53
$ this ->fileHandler = null ;
37
- unlink (filename: "file " );
38
- unlink (filename: "movie.csv " );
39
54
}
40
55
41
56
@@ -67,34 +82,34 @@ public function shouldThrowExceptionIfFileIsNotWritable()
67
82
$ this ->fileHandler ->write (data: "hello world " );
68
83
}
69
84
85
+
70
86
#[Test]
71
- public function multipleFileCanBeWrittenSimultaneously ()
87
+ public function fileIsClosedProperly ()
72
88
{
73
89
$ this ->fileHandler ->open (filename: 'file ' );
74
-
75
- $ this ->fileHandler ->open (filename: 'file1 ' , mode: 'w ' );
76
-
77
90
$ this ->fileHandler ->write (data: "hello world " );
91
+ $ this ->fileHandler ->close ();
78
92
79
- $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file ' ));
80
-
81
- $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file1 ' ));
82
-
83
- unlink ("file1 " );
93
+ $ this ->expectException (TypeError::class);
94
+ $ this ->fileHandler ->write (data: "fwrite(): supplied resource is not a valid stream resource " );
84
95
}
85
96
86
97
87
98
#[Test]
88
- public function fileIsClosedProperly ()
99
+ public function multipleFileCanBeWrittenSimultaneously ()
89
100
{
90
101
$ this ->fileHandler ->open (filename: 'file ' );
102
+
103
+ $ this ->fileHandler ->open (filename: 'file1 ' );
104
+
91
105
$ this ->fileHandler ->write (data: "hello world " );
92
- $ this ->fileHandler ->close ();
93
106
94
- $ this ->expectException (TypeError::class);
95
- $ this ->fileHandler ->write (data: "fwrite(): supplied resource is not a valid stream resource " );
107
+ $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file ' ));
108
+
109
+ $ this ->assertEquals ("hello world " , file_get_contents (filename: 'file1 ' ));
96
110
}
97
111
112
+
98
113
#[Test]
99
114
#[DataProvider('provideMovieNames ' )]
100
115
#[TestDox('search result with name $keyword exists in file. ' )]
0 commit comments