@@ -130,4 +130,60 @@ function it_throws_exception_when_file_type_is_not_supported()
130
130
$ this ->expectException (ConfigurationFileNotFoundException::class);
131
131
$ this ->fileReader ->readFile ();
132
132
}
133
+
134
+ /** @test */
135
+ function it_prioritizes_php_files_over_yml ()
136
+ {
137
+ $ phpConfig = "<?php return ['tools' => ['phpunit']]; " ;
138
+ $ ymlConfig = $ this ->configurationFileBuilder ->setTools (['phpcs ' ])->buildYalm ();
139
+
140
+ $ fileSystemStructure = [
141
+ 'githooks.php ' => $ phpConfig ,
142
+ 'githooks.yml ' => $ ymlConfig
143
+ ];
144
+
145
+ $ this ->createFileSystem ($ fileSystemStructure );
146
+
147
+ $ expectedConfig = ['tools ' => ['phpunit ' ]];
148
+ $ fileReaded = $ this ->fileReader ->readFile ();
149
+
150
+ $ this ->assertEquals ($ expectedConfig , $ fileReaded );
151
+ }
152
+
153
+ public function configurationFilesInRootAndQaDataProvider ()
154
+ {
155
+ return [
156
+ 'PHP files ' => [
157
+ "<?php return ['tools' => ['phpunit']]; " ,
158
+ "<?php return ['tools' => ['phpcs']]; " ,
159
+ ['tools ' => ['phpunit ' ]],
160
+ 'php '
161
+ ],
162
+ 'YAML files ' => [
163
+ $ this ->setConfigurationFileBuilder ()->setTools (['phpunit ' ])->buildYalm (),
164
+ $ this ->setConfigurationFileBuilder ()->setTools (['phpcs ' ])->buildYalm (),
165
+ $ this ->setConfigurationFileBuilder ()->setTools (['phpunit ' ])->buildArray (),
166
+ 'yml '
167
+ ]
168
+ ];
169
+ }
170
+
171
+ /**
172
+ * @test
173
+ * @dataProvider configurationFilesInRootAndQaDataProvider
174
+ * When there are valid configuration files in both root and qa directories, it prioritizes files in the root directory
175
+ */
176
+ function it_prioritizes_files_in_root_directory_over_files_in_qa_directory ($ rootFile , $ qaFile , $ expectedConfig , $ fileExtension )
177
+ {
178
+ $ fileSystemStructure = [
179
+ "githooks. $ fileExtension " => $ rootFile ,
180
+ 'qa ' => ["githooks. $ fileExtension " => $ qaFile ]
181
+ ];
182
+
183
+ $ this ->createFileSystem ($ fileSystemStructure );
184
+
185
+ $ fileReaded = $ this ->fileReader ->readFile ();
186
+
187
+ $ this ->assertEquals ($ expectedConfig , $ fileReaded );
188
+ }
133
189
}
0 commit comments