1
1
<?php
2
2
3
+ namespace unit ;
4
+
3
5
use PHPUnit \Framework \Attributes \DataProvider ;
4
6
use PHPUnit \Framework \Attributes \Test ;
5
7
use PHPUnit \Framework \Attributes \TestDox ;
6
8
use PHPUnit \Framework \TestCase ;
7
9
use rcsofttech85 \FileHandler \Exception \CouldNotWriteFileException ;
8
10
use rcsofttech85 \FileHandler \Exception \FileNotFoundException ;
9
11
use rcsofttech85 \FileHandler \FileHandler ;
12
+ use TypeError ;
10
13
11
14
class FileHandlerTest extends TestCase
12
15
{
13
-
14
16
private FileHandler |null $ fileHandler ;
15
17
16
18
protected function setUp (): void
@@ -31,7 +33,7 @@ protected function tearDown(): void
31
33
32
34
33
35
#[Test]
34
- public function file_successfully_written ()
36
+ public function fileSuccessfullyWritten ()
35
37
{
36
38
$ this ->fileHandler ->open (filename: 'file ' );
37
39
@@ -41,15 +43,15 @@ public function file_successfully_written()
41
43
}
42
44
43
45
#[Test]
44
- public function should_throw_exception_if_file_is_not_Found ()
46
+ public function shouldThrowExceptionIfFileIsNotFound ()
45
47
{
46
48
$ this ->expectException (FileNotFoundException::class);
47
49
$ this ->expectExceptionMessage ('File not found ' );
48
50
$ this ->fileHandler ->open (filename: 'unknown ' );
49
51
}
50
52
51
53
#[Test]
52
- public function should_throw_exception_if_file_is_not_writable ()
54
+ public function shouldThrowExceptionIfFileIsNotWritable ()
53
55
{
54
56
$ this ->fileHandler ->open (filename: 'file ' , mode: 'r ' );
55
57
@@ -59,7 +61,7 @@ public function should_throw_exception_if_file_is_not_writable()
59
61
}
60
62
61
63
#[Test]
62
- public function multiple_file_can_be_written_simultaneously ()
64
+ public function multipleFileCanBeWrittenSimultaneously ()
63
65
{
64
66
$ this ->fileHandler ->open (filename: 'file ' );
65
67
@@ -76,7 +78,7 @@ public function multiple_file_can_be_written_simultaneously()
76
78
77
79
78
80
#[Test]
79
- public function file_is_closed_properly ()
81
+ public function fileIsClosedProperly ()
80
82
{
81
83
$ this ->fileHandler ->open (filename: 'file ' );
82
84
$ this ->fileHandler ->write (data: "hello world " );
@@ -87,9 +89,9 @@ public function file_is_closed_properly()
87
89
}
88
90
89
91
#[Test]
90
- #[DataProvider('provide_movie_names ' )]
92
+ #[DataProvider('provideMovieNames ' )]
91
93
#[TestDox('search result with name $keyword exists in file. ' )]
92
- public function result_found_for_exact_name_match (string $ keyword )
94
+ public function resultFoundForExactNameMatch (string $ keyword )
93
95
{
94
96
$ isMovieAvailable = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (
95
97
keyword: $ keyword ,
@@ -99,9 +101,9 @@ public function result_found_for_exact_name_match(string $keyword)
99
101
}
100
102
101
103
#[Test]
102
- #[DataProvider('provide_studio_names ' )]
104
+ #[DataProvider('provideStudioNames ' )]
103
105
#[TestDox('search result with name $keyword exists in file. ' )]
104
- public function studio_is_found_for_exact_name_match (string $ keyword )
106
+ public function studioIsFoundForExactNameMatch (string $ keyword )
105
107
{
106
108
$ isStudioFound = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (
107
109
keyword: $ keyword ,
@@ -111,7 +113,7 @@ public function studio_is_found_for_exact_name_match(string $keyword)
111
113
}
112
114
113
115
#[Test]
114
- public function to_array_method_returns_valid_array ()
116
+ public function toArrayMethodReturnsValidArray ()
115
117
{
116
118
$ data = $ this ->fileHandler ->open (filename: 'movie.csv ' )->toArray ();
117
119
$ expected = [
@@ -130,7 +132,7 @@ public function to_array_method_returns_valid_array()
130
132
}
131
133
132
134
#[Test]
133
- public function search_by_keyword_and_return_array ()
135
+ public function searchByKeywordAndReturnArray ()
134
136
{
135
137
$ expected = [
136
138
'Film ' => 'Zack and Miri Make a Porno ' ,
@@ -153,19 +155,18 @@ public function search_by_keyword_and_return_array()
153
155
$ this ->assertEquals ($ expected , $ data );
154
156
}
155
157
156
- public static function provide_studio_names (): iterable
158
+ public static function provideStudioNames (): iterable
157
159
{
158
160
yield ["Fox " ];
159
161
yield ["Universal " ];
160
162
yield ["Warner Bros. " ];
161
163
}
162
164
163
165
164
- public static function provide_movie_names (): iterable
166
+ public static function provideMovieNames (): iterable
165
167
{
166
168
yield ["The Ugly Truth " ];
167
169
yield ["Leap Year " ];
168
170
yield ["Twilight " ];
169
171
}
170
-
171
- }
172
+ }
0 commit comments