1111use PHPUnit \Framework \TestCase ;
1212use RuntimeException ;
1313
14- abstract class BaseIntegrationTest extends TestCase {
14+ abstract class BaseIntegrationTest extends TestCase
15+ {
1516 protected string $ hostname ;
1617 protected string $ folderPrefix ;
1718 protected string $ testUser ;
@@ -24,7 +25,8 @@ abstract class BaseIntegrationTest extends TestCase {
2425
2526 protected static bool $ setupCompleted = false ;
2627
27- protected function setUp (): void {
28+ protected function setUp (): void
29+ {
2830 parent ::setUp ();
2931
3032 // Load environment variables
@@ -44,7 +46,8 @@ protected function setUp(): void {
4446 }
4547 }
4648
47- protected function setupEnvironment (): void {
49+ protected function setupEnvironment (): void
50+ {
4851 // Create temporary folder
4952 if (!is_dir ($ this ->folderPrefix )) {
5053 mkdir ($ this ->folderPrefix , 0755 , true );
@@ -79,7 +82,8 @@ protected function setupEnvironment(): void {
7982 $ this ->executeDockerCommand ('php occ app:enable gdatavaas ' );
8083 }
8184
82- protected function executeDockerCommand (string $ command , array $ env = []): array {
85+ protected function executeDockerCommand (string $ command , array $ env = []): array
86+ {
8387 $ envString = '' ;
8488 foreach ($ env as $ key => $ value ) {
8589 $ envString .= " --env {$ key }= \"{$ value }\"" ;
@@ -96,7 +100,8 @@ protected function executeDockerCommand(string $command, array $env = []): array
96100 ];
97101 }
98102
99- protected function makeHttpRequest (string $ method , string $ url , array $ options = []): array {
103+ protected function makeHttpRequest (string $ method , string $ url , array $ options = []): array
104+ {
100105 $ client = HttpClientBuilder::buildDefault ();
101106 $ request = new Request ($ url , $ method );
102107
@@ -129,8 +134,6 @@ protected function makeHttpRequest(string $method, string $url, array $options =
129134 $ request ->setBody ($ options ['file_handle ' ]);
130135 }
131136
132- var_dump ($ request );
133-
134137 try {
135138 $ response = $ client ->request ($ request );
136139
@@ -148,7 +151,8 @@ protected function makeHttpRequest(string $method, string $url, array $options =
148151 }
149152 }
150153
151- protected function uploadFileViaWebDAV (string $ username , string $ password , string $ filename , string $ content ): array {
154+ protected function uploadFileViaWebDAV (string $ username , string $ password , string $ filename , string $ content ): array
155+ {
152156 $ url = "http:// {$ this ->hostname }/remote.php/dav/files/ {$ username }/ {$ filename }" ;
153157
154158 return $ this ->makeHttpRequest ('PUT ' , $ url , [
@@ -158,15 +162,17 @@ protected function uploadFileViaWebDAV(string $username, string $password, strin
158162 ]);
159163 }
160164
161- protected function deleteFileViaWebDAV (string $ username , string $ password , string $ filename ): array {
165+ protected function deleteFileViaWebDAV (string $ username , string $ password , string $ filename ): array
166+ {
162167 $ url = "http:// {$ this ->hostname }/remote.php/dav/files/ {$ username }/ {$ filename }" ;
163168
164169 return $ this ->makeHttpRequest ('DELETE ' , $ url , [
165170 'auth ' => ['username ' => $ username , 'password ' => $ password ]
166171 ]);
167172 }
168173
169- protected function uploadFileFromDisk (string $ username , string $ password , string $ filename , string $ localPath ): array {
174+ protected function uploadFileFromDisk (string $ username , string $ password , string $ filename , string $ localPath ): array
175+ {
170176 if (!file_exists ($ localPath )) {
171177 throw new RuntimeException ("File not found: {$ localPath }" );
172178 }
@@ -184,18 +190,19 @@ protected function uploadFileFromDisk(string $username, string $password, string
184190 ]);
185191 }
186192
187- protected function testGetEndpoint (string $ endpoint , string $ description , int $ expectedHttpStatus = 200 , string $ username = 'admin ' , string $ password = 'admin ' ): void {
193+ protected function testGetEndpoint (string $ endpoint , string $ description , int $ expectedHttpStatus = 200 , string $ username = 'admin ' , string $ password = 'admin ' ): void
194+ {
188195 $ url = "http:// {$ this ->hostname }/apps/gdatavaas/ {$ endpoint }" ;
189196
190197 $ result = $ this ->makeHttpRequest ('GET ' , $ url , [
191198 'auth ' => ['username ' => $ username , 'password ' => $ password ]
192199 ]);
193200
194- echo "{$ description } result: {$ result ['http_code ' ]}\n" ;
195201 $ this ->assertEquals ($ expectedHttpStatus , $ result ['http_code ' ], "Failed: {$ description }" );
196202 }
197203
198- protected function testPostEndpoint (string $ endpoint , array $ data , string $ description , int $ expectedHttpStatus = 200 , string $ username = 'admin ' , string $ password = 'admin ' ): void {
204+ protected function testPostEndpoint (string $ endpoint , array $ data , string $ description , int $ expectedHttpStatus = 200 , string $ username = 'admin ' , string $ password = 'admin ' ): void
205+ {
199206 $ url = "http:// {$ this ->hostname }/apps/gdatavaas/ {$ endpoint }" ;
200207
201208 $ result = $ this ->makeHttpRequest ('POST ' , $ url , [
@@ -204,31 +211,35 @@ protected function testPostEndpoint(string $endpoint, array $data, string $descr
204211 'headers ' => ['Content-Type: application/json ' ]
205212 ]);
206213
207- echo "{$ description } result: {$ result ['http_code ' ]}\n" ;
208214 $ this ->assertEquals ($ expectedHttpStatus , $ result ['http_code ' ], "Failed: {$ description }" );
209215 }
210216
211- protected function assertContainsVirusFound (array $ response ): void {
217+ protected function assertContainsVirusFound (array $ response ): void
218+ {
212219 $ this ->assertStringContainsString ('Virus found ' , $ response ['body ' ], 'Expected "Virus found" in response body ' );
213220 }
214221
215- protected function assertHttpCodeInRange (int $ httpCode , int $ min = 200 , int $ max = 299 ): void {
222+ protected function assertHttpCodeInRange (int $ httpCode , int $ min = 200 , int $ max = 299 ): void
223+ {
216224 $ this ->assertGreaterThanOrEqual ($ min , $ httpCode , "HTTP code {$ httpCode } is below expected range {$ min }- {$ max }" );
217225 $ this ->assertLessThan ($ max + 1 , $ httpCode , "HTTP code {$ httpCode } is above expected range {$ min }- {$ max }" );
218226 }
219227
220- protected function getTagsForFile (string $ filePath ): array {
228+ protected function getTagsForFile (string $ filePath ): array
229+ {
221230 $ result = $ this ->executeDockerCommand ("php occ gdatavaas:get-tags-for-file {$ filePath }" );
222231 return $ result ['output ' ];
223232 }
224233
225- protected function assertHasTag (string $ filePath , string $ expectedTag ): void {
234+ protected function assertHasTag (string $ filePath , string $ expectedTag ): void
235+ {
226236 $ tags = $ this ->getTagsForFile ($ filePath );
227237 $ tagString = implode ("\n" , $ tags );
228238 $ this ->assertStringContainsString ($ expectedTag , $ tagString , "Expected tag ' {$ expectedTag }' not found in file tags " );
229239 }
230240
231- protected function assertTagCount (string $ filePath , int $ expectedCount ): void {
241+ protected function assertTagCount (string $ filePath , int $ expectedCount ): void
242+ {
232243 $ tags = $ this ->getTagsForFile ($ filePath );
233244 // Filter out empty lines
234245 $ nonEmptyTags = array_filter ($ tags , function ($ line ) {
@@ -237,7 +248,8 @@ protected function assertTagCount(string $filePath, int $expectedCount): void {
237248 $ this ->assertCount ($ expectedCount , $ nonEmptyTags , "Expected {$ expectedCount } tags, got " . count ($ nonEmptyTags ));
238249 }
239250
240- public static function tearDownAfterClass (): void {
251+ public static function tearDownAfterClass (): void
252+ {
241253 parent ::tearDownAfterClass ();
242254
243255 // Clean up temporary files
@@ -247,7 +259,8 @@ public static function tearDownAfterClass(): void {
247259 }
248260 }
249261
250- private static function removeDirectory (string $ dir ): void {
262+ private static function removeDirectory (string $ dir ): void
263+ {
251264 if (!is_dir ($ dir )) {
252265 return ;
253266 }
0 commit comments