[PHP-WEBMASTER] [web-downloads] main: Fail on malformed winlibs jobs instead of silently dropping them

Author: Shivam Mathur (shivammathur)
Date: 2026-04-02T06:55:34+05:30

Commit: Fail on malformed winlibs jobs instead of silently dropping them · php/web-downloads@dec6915 · GitHub
Raw diff: https://github.com/php/web-downloads/commit/dec6915337fbb5f057b204412dabbe94b62c0562.diff

Fail on malformed winlibs jobs instead of silently dropping them

Changed paths:
  M src/Console/Command/WinlibsCommand.php
  M tests/Console/Command/WinlibsCommandTest.php

Diff:

diff --git a/src/Console/Command/WinlibsCommand.php b/src/Console/Command/WinlibsCommand.php
index 44dc7ed..e719920 100644
--- a/src/Console/Command/WinlibsCommand.php
+++ b/src/Console/Command/WinlibsCommand.php
@@ -44,6 +44,9 @@ public function handle(): int
                 $data = json_decode(file_get_contents($directoryPath . '/data.json'), true, 512, JSON_THROW_ON_ERROR);
                 $files = glob($directoryPath . '/*.zip');
                 $files = $this->parseFiles($files);
+ if (empty($files)) {
+ throw new Exception('No valid files found in ' . basename($directoryPath));
+ }
                 if ($files) {
                     if($data['type'] === 'php') {
                         $this->copyPhpFiles($files, $data['library'], $data['vs_version_targets']);
diff --git a/tests/Console/Command/WinlibsCommandTest.php b/tests/Console/Command/WinlibsCommandTest.php
index 42fc22d..d5382a1 100644
--- a/tests/Console/Command/WinlibsCommandTest.php
+++ b/tests/Console/Command/WinlibsCommandTest.php
@@ -263,6 +263,29 @@ public function testHandlesCorruptDataFile(): void
         $this->assertEquals(1, $result);
     }

+ public function testHandlesNoValidFilesInJob(): void
+ {
+ mkdir($this->winlibsDirectory . '/lib', 0755, true);
+ file_put_contents($this->winlibsDirectory . '/lib/data.json', json_encode([
+ 'type' => 'php',
+ 'library' => 'lib',
+ 'ref' => '1.0.0',
+ 'vs_version_targets' => 'vs16',
+ 'php_versions' => '8.2',
+ 'stability' => 'stable'
+ ]));
+ file_put_contents($this->winlibsDirectory . '/lib/not-a-valid-file.zip', 'dummy');
+
+ $command = new WinlibsCommand();
+ $command->setOption('base-directory', $this->baseDirectory);
+ $command->setOption('builds-directory', $this->buildsDirectory);
+ ob_start();
+ $result = $command->handle();
+ $output = ob_get_clean();
+ $this->assertStringContainsString('No valid files found', $output);
+ $this->assertEquals(1, $result);
+ }
+

     #[DataProvider('fileProvider')]
     public function testParseFiles($file, $expected): void