11<?php
22
3- namespace Tests \TestSuite ;
3+ namespace Tests \TestSuite \ Fixtures \ Downloader ;
44
55use GuzzleHttp \Client ;
66use GuzzleHttp \Exception \ClientException ;
1010use GuzzleHttp \Psr7 \Request ;
1111use PHPUnit \Framework \TestCase ;
1212use Tests \Fixtures \Downloader \CachedHttpDownloader ;
13+ use RecursiveDirectoryIterator ;
14+ use RecursiveIteratorIterator ;
15+ use ReflectionClass ;
1316
1417class CachedHttpDownloaderTest extends TestCase
1518{
@@ -18,7 +21,7 @@ class CachedHttpDownloaderTest extends TestCase
1821 protected function setUp (): void
1922 {
2023 $ this ->tempCacheDir = sys_get_temp_dir () . '/test_cache_ ' . uniqid ();
21- mkdir ($ this ->tempCacheDir , 0777 , true );
24+ mkdir ($ this ->tempCacheDir , 0o777 , true );
2225 }
2326
2427 protected function tearDown (): void
@@ -39,15 +42,15 @@ public function testRetryOn429Error(): void
3942 $ client = new Client (['handler ' => $ handlerStack ]);
4043
4144 $ downloader = new CachedHttpDownloader ('test ' , $ this ->tempCacheDir , 10 , 3 ); // 10ms delay, 3 max retries
42-
45+
4346 // Use reflection to replace the client
44- $ reflection = new \ ReflectionClass ($ downloader );
47+ $ reflection = new ReflectionClass ($ downloader );
4548 $ clientProperty = $ reflection ->getProperty ('client ' );
4649 $ clientProperty ->setAccessible (true );
4750 $ clientProperty ->setValue ($ downloader , $ client );
4851
4952 $ result = $ downloader ->fetch ('http://test.com ' , true );
50-
53+
5154 $ this ->assertEquals ('success content ' , $ result );
5255 }
5356
@@ -65,9 +68,9 @@ public function testRetryFailsAfterMaxAttempts(): void
6568 $ client = new Client (['handler ' => $ handlerStack ]);
6669
6770 $ downloader = new CachedHttpDownloader ('test ' , $ this ->tempCacheDir , 10 , 3 ); // 10ms delay, 3 max retries
68-
71+
6972 // Use reflection to replace the client
70- $ reflection = new \ ReflectionClass ($ downloader );
73+ $ reflection = new ReflectionClass ($ downloader );
7174 $ clientProperty = $ reflection ->getProperty ('client ' );
7275 $ clientProperty ->setAccessible (true );
7376 $ clientProperty ->setValue ($ downloader , $ client );
@@ -87,15 +90,15 @@ public function testSuccessfulRequest(): void
8790 $ client = new Client (['handler ' => $ handlerStack ]);
8891
8992 $ downloader = new CachedHttpDownloader ('test ' , $ this ->tempCacheDir , 10 , 3 );
90-
93+
9194 // Use reflection to replace the client
92- $ reflection = new \ ReflectionClass ($ downloader );
95+ $ reflection = new ReflectionClass ($ downloader );
9396 $ clientProperty = $ reflection ->getProperty ('client ' );
9497 $ clientProperty ->setAccessible (true );
9598 $ clientProperty ->setValue ($ downloader , $ client );
9699
97100 $ result = $ downloader ->fetch ('http://test.com ' , true );
98-
101+
99102 $ this ->assertEquals ('success content ' , $ result );
100103 }
101104
@@ -109,8 +112,8 @@ public function testCachedResponse(): void
109112 $ client1 = new Client (['handler ' => $ handlerStack1 ]);
110113
111114 $ downloader = new CachedHttpDownloader ('test ' , $ this ->tempCacheDir , 10 , 3 );
112-
113- $ reflection = new \ ReflectionClass ($ downloader );
115+
116+ $ reflection = new ReflectionClass ($ downloader );
114117 $ clientProperty = $ reflection ->getProperty ('client ' );
115118 $ clientProperty ->setAccessible (true );
116119 $ clientProperty ->setValue ($ downloader , $ client1 );
@@ -135,10 +138,10 @@ private function removeDirectory(string $dir): void
135138 if (!is_dir ($ dir )) {
136139 return ;
137140 }
138-
139- $ files = new \ RecursiveIteratorIterator (
140- new \ RecursiveDirectoryIterator ($ dir , \ RecursiveDirectoryIterator::SKIP_DOTS ),
141- \ RecursiveIteratorIterator::CHILD_FIRST
141+
142+ $ files = new RecursiveIteratorIterator (
143+ new RecursiveDirectoryIterator ($ dir , RecursiveDirectoryIterator::SKIP_DOTS ),
144+ RecursiveIteratorIterator::CHILD_FIRST
142145 );
143146
144147 foreach ($ files as $ fileinfo ) {
@@ -148,4 +151,4 @@ private function removeDirectory(string $dir): void
148151
149152 rmdir ($ dir );
150153 }
151- }
154+ }
0 commit comments