6
6
use PHPUnit \Framework \TestCase ;
7
7
use rcsofttech85 \FileHandler \Exception \CouldNotWriteFileException ;
8
8
use rcsofttech85 \FileHandler \Exception \FileNotFoundException ;
9
- use rcsofttech85 \FileHandler \Exception \InvalidFileException ;
10
9
use rcsofttech85 \FileHandler \FileHandler ;
11
10
12
11
class FileHandlerTest extends TestCase
@@ -32,7 +31,6 @@ protected function tearDown(): void
32
31
33
32
34
33
#[Test]
35
- #[TestDox("file was written successfully! " )]
36
34
public function file_successfully_written ()
37
35
{
38
36
$ this ->fileHandler ->open (filename: 'file ' );
@@ -43,7 +41,6 @@ public function file_successfully_written()
43
41
}
44
42
45
43
#[Test]
46
- #[TestDox("should throw an exception if file is not found " )]
47
44
public function should_throw_exception_if_file_is_not_Found ()
48
45
{
49
46
$ this ->expectException (FileNotFoundException::class);
@@ -52,7 +49,6 @@ public function should_throw_exception_if_file_is_not_Found()
52
49
}
53
50
54
51
#[Test]
55
- #[TestDox("should throw an exception if file is not writable " )]
56
52
public function should_throw_exception_if_file_is_not_writable ()
57
53
{
58
54
$ this ->fileHandler ->open (filename: 'file ' , mode: 'r ' );
@@ -63,7 +59,6 @@ public function should_throw_exception_if_file_is_not_writable()
63
59
}
64
60
65
61
#[Test]
66
- #[TestDox("multiple files can be written simultaneously " )]
67
62
public function multiple_file_can_be_written_simultaneously ()
68
63
{
69
64
$ this ->fileHandler ->open (filename: 'file ' );
@@ -81,7 +76,6 @@ public function multiple_file_can_be_written_simultaneously()
81
76
82
77
83
78
#[Test]
84
- #[TestDox("checks if a movie exists in a collection by a name " )]
85
79
public function file_is_closed_properly ()
86
80
{
87
81
$ this ->fileHandler ->open (filename: 'file ' );
@@ -94,28 +88,69 @@ public function file_is_closed_properly()
94
88
95
89
#[Test]
96
90
#[DataProvider('provide_movie_names ' )]
97
- #[TestDox('Movie with name $keyword exists in collection . ' )]
98
- public function movie_is_found_for_exact_name_match (string $ keyword )
91
+ #[TestDox('search result with name $keyword exists in file . ' )]
92
+ public function result_found_for_exact_name_match (string $ keyword )
99
93
{
100
- $ isMovieAvailable = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (keyword: $ keyword );
94
+ $ isMovieAvailable = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (
95
+ keyword: $ keyword ,
96
+ column: 'Film '
97
+ );
101
98
$ this ->assertTrue ($ isMovieAvailable );
102
99
}
103
100
104
101
#[Test]
105
102
#[DataProvider('provide_studio_names ' )]
106
- #[TestDox('Studio with name $keyword exists in collection . ' )]
103
+ #[TestDox('search result with name $keyword exists in file . ' )]
107
104
public function studio_is_found_for_exact_name_match (string $ keyword )
108
105
{
109
- $ isStudioFound = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (keyword: $ keyword , offset: 2 );
106
+ $ isStudioFound = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (
107
+ keyword: $ keyword ,
108
+ column: 'Lead Studio '
109
+ );
110
110
$ this ->assertTrue ($ isStudioFound );
111
111
}
112
112
113
113
#[Test]
114
- public function should_throw_exception_if_not_valid_csv ()
114
+ public function to_array_method_returns_valid_array ()
115
115
{
116
- $ this ->expectException (InvalidFileException::class);
117
- $ this ->expectExceptionMessage ("invalid file format " );
118
- $ this ->fileHandler ->open (filename: 'invalid.csv ' )->searchInCsvFile (keyword: 'hello ' );
116
+ $ data = $ this ->fileHandler ->open (filename: 'movie.csv ' )->toArray ();
117
+
118
+ $ expected = [
119
+ 'Film ' => 'Zack and Miri Make a Porno ' ,
120
+ 'Genre ' => 'Romance ' ,
121
+ 'Lead Studio ' => 'The Weinstein Company ' ,
122
+ 'Audience score % ' => '70 ' ,
123
+ 'Profitability ' => '1.747541667 ' ,
124
+ 'Rotten Tomatoes % ' => '64 ' ,
125
+ 'Worldwide Gross ' => '$41.94 ' ,
126
+ 'Year ' => '2008 '
127
+
128
+ ];
129
+
130
+ $ this ->assertEquals ($ expected , $ data [0 ]);
131
+ }
132
+
133
+ public function search_by_keyword_and_return_array ()
134
+ {
135
+ $ expected = [
136
+ 'Film ' => 'Zack and Miri Make a Porno ' ,
137
+ 'Genre ' => 'Romance ' ,
138
+ 'Lead Studio ' => 'The Weinstein Company ' ,
139
+ 'Audience score % ' => '70 ' ,
140
+ 'Profitability ' => '1.747541667 ' ,
141
+ 'Rotten Tomatoes % ' => '64 ' ,
142
+ 'Worldwide Gross ' => '$41.94 ' ,
143
+ 'Year ' => '2008 '
144
+
145
+ ];
146
+
147
+ $ data = $ this ->fileHandler ->open (filename: 'movie.csv ' )->searchInCsvFile (
148
+ keyword: 'Zack and Miri Make a Porno ' ,
149
+ column: 'Film ' ,
150
+ format: FileHandler::ARRAY_FORMAT
151
+ );
152
+
153
+ $ this ->assertEquals ($ expected , $ data );
119
154
}
120
155
121
156
public static function provide_studio_names (): iterable
0 commit comments