@@ -182,6 +182,53 @@ public function testSuccessfulPeclFileOperations(): void
182182 $ this ->assertFileExists ($ this ->baseDirectory . "/pecl/deps/ $ library- $ ref- $ vsVersion- $ arch.zip " );
183183 }
184184
185+ public function testPackagesFileIsGeneratedWithoutSyncFile (): void
186+ {
187+ $ result = $ this ->runPeclWinlibsCommand ('redis ' , 'phpredis ' , '5.3.7 ' , 'vs16 ' , 'x64 ' );
188+
189+ $ this ->assertEquals (0 , $ result , 'Command should return success. ' );
190+
191+ $ packagesFile = $ this ->baseDirectory . '/pecl/deps/packages.txt ' ;
192+ $ syncFile = $ packagesFile . '.sync ' ;
193+
194+ $ this ->assertFileExists ($ packagesFile );
195+ $ this ->assertFileExists ($ syncFile );
196+ $ this ->assertSame (
197+ ['phpredis-5.3.7-vs16-x64.zip ' ],
198+ file ($ packagesFile , FILE_IGNORE_NEW_LINES )
199+ );
200+ }
201+
202+ public function testPackagesFileUpdatesExistingEntriesAndMaintainsSorting (): void
203+ {
204+ $ this ->runPeclWinlibsCommand ('redis ' , 'phpredis ' , '5.3.7 ' , 'vs16 ' , 'x64 ' );
205+
206+ $ packagesFile = $ this ->baseDirectory . '/pecl/deps/packages.txt ' ;
207+ $ this ->assertFileExists ($ packagesFile );
208+ $ this ->assertSame (
209+ ['phpredis-5.3.7-vs16-x64.zip ' ],
210+ file ($ packagesFile , FILE_IGNORE_NEW_LINES )
211+ );
212+
213+ $ this ->runPeclWinlibsCommand ('imagick ' , 'imagick ' , '3.7.0 ' , 'vs16 ' , 'x64 ' );
214+ $ this ->assertSame (
215+ [
216+ 'imagick-3.7.0-vs16-x64.zip ' ,
217+ 'phpredis-5.3.7-vs16-x64.zip ' ,
218+ ],
219+ file ($ packagesFile , FILE_IGNORE_NEW_LINES )
220+ );
221+
222+ $ this ->runPeclWinlibsCommand ('redis ' , 'phpredis ' , '5.3.8 ' , 'vs16 ' , 'x64 ' );
223+ $ this ->assertSame (
224+ [
225+ 'imagick-3.7.0-vs16-x64.zip ' ,
226+ 'phpredis-5.3.8-vs16-x64.zip ' ,
227+ ],
228+ file ($ packagesFile , FILE_IGNORE_NEW_LINES )
229+ );
230+ }
231+
185232 public static function versionProvider (): array
186233 {
187234 return [
@@ -278,4 +325,32 @@ public static function fileProvider(): array
278325 ]],
279326 ];
280327 }
328+
329+ private function runPeclWinlibsCommand (string $ buildName , string $ library , string $ ref , string $ vsVersion , string $ arch ): int
330+ {
331+ $ directory = $ this ->winlibsDirectory . '/ ' . $ buildName ;
332+ mkdir ($ directory , 0755 , true );
333+
334+ file_put_contents ($ directory . '/data.json ' , json_encode ([
335+ 'type ' => 'pecl ' ,
336+ 'library ' => $ library ,
337+ 'ref ' => $ ref ,
338+ 'vs_version_targets ' => $ vsVersion ,
339+ 'php_versions ' => '8.2 ' ,
340+ 'stability ' => 'stable '
341+ ]));
342+
343+ $ zipPath = $ directory . "/ $ buildName- $ ref- $ vsVersion- $ arch.zip " ;
344+ $ zip = new ZipArchive ();
345+ if ($ zip ->open ($ zipPath , ZipArchive::CREATE ) === TRUE ) {
346+ $ zip ->addFromString ('dummy_file.txt ' , 'dummy content ' );
347+ $ zip ->close ();
348+ }
349+
350+ $ command = new WinlibsCommand ();
351+ $ command ->setOption ('base-directory ' , $ this ->baseDirectory );
352+ $ command ->setOption ('builds-directory ' , $ this ->buildsDirectory );
353+
354+ return $ command ->handle ();
355+ }
281356}
0 commit comments