[PHP-WEBMASTER] [web-downloads] main: Fix tests for series directory condition change

[email protected] (Shivam Mathur)
Newsgroups php.webmaster
Message-ID <[email protected]>
Author: Shivam Mathur (shivammathur)
Date: 2025-11-19T16:07:18+05:30

Commit: https://github.com/php/web-downloads/commit/97ec76963b9a29a95618e85f1b53df2d0e794cbf
Raw diff: https://github.com/php/web-downloads/commit/97ec76963b9a29a95618e85f1b53df2d0e794cbf.diff

Fix tests for series directory condition change

Changed paths:
  M  tests/Console/Command/SeriesDeleteCommandTest.php
  M  tests/Console/Command/SeriesInitCommandTest.php
  M  tests/Console/Command/SeriesStabilityCommandTest.php
  M  tests/Console/Command/SeriesUpdateCommandTest.php
  M  tests/Http/Controllers/SeriesUpdateControllerTest.php


Diff:

diff --git a/tests/Console/Command/SeriesDeleteCommandTest.php b/tests/Console/Command/SeriesDeleteCommandTest.php
index 9929b8b..b3dbd2b 100644
--- a/tests/Console/Command/SeriesDeleteCommandTest.php
+++ b/tests/Console/Command/SeriesDeleteCommandTest.php
@@ -38,15 +38,18 @@ public static function versionProvider(): array
         ];
     }
 
-    public function testReturnsSuccessWhenNoSeriesDir(): void
+    public function testFailsWhenNoSeriesDir(): void
     {
         $command = new SeriesDeleteCommand();
         $command->setOption('base-directory', $this->baseDirectory);
         $command->setOption('builds-directory', $this->buildsDirectory);
 
+        ob_start();
         $result = $command->handle();
+        $output = trim(ob_get_clean());
 
-        $this->assertSame(0, $result, 'Should return success when there is no builds/series directory.');
+        $this->assertSame(1, $result, 'Should fail when there is no builds/series directory.');
+        $this->assertSame('Series directory does not exist', $output);
     }
 
     public function testMissingBaseDirectory(): void
diff --git a/tests/Console/Command/SeriesInitCommandTest.php b/tests/Console/Command/SeriesInitCommandTest.php
index ba16752..24b7d59 100644
--- a/tests/Console/Command/SeriesInitCommandTest.php
+++ b/tests/Console/Command/SeriesInitCommandTest.php
@@ -38,15 +38,18 @@ public static function caseProvider(): array
         ];
     }
 
-    public function testReturnsSuccessWhenNoSeriesDir(): void
+    public function testFailsWhenNoSeriesDir(): void
     {
         $command = new SeriesInitCommand();
         $command->setOption('base-directory', $this->baseDirectory);
         $command->setOption('builds-directory', $this->buildsDirectory);
 
+        ob_start();
         $result = $command->handle();
+        $output = trim(ob_get_clean());
 
-        $this->assertSame(0, $result, 'Should return success when there is no builds/series directory.');
+        $this->assertSame(1, $result, 'Should fail when there is no builds/series directory.');
+        $this->assertSame('Series directory does not exist', $output);
     }
 
     public function testMissingBaseDirectory(): void
diff --git a/tests/Console/Command/SeriesStabilityCommandTest.php b/tests/Console/Command/SeriesStabilityCommandTest.php
index b3364a0..0203f29 100644
--- a/tests/Console/Command/SeriesStabilityCommandTest.php
+++ b/tests/Console/Command/SeriesStabilityCommandTest.php
@@ -38,15 +38,18 @@ public static function versionProvider(): array
         ];
     }
 
-    public function testReturnsSuccessWhenNoSeriesDir(): void
+    public function testFailsWhenNoSeriesDir(): void
     {
         $command = new SeriesStabilityCommand();
         $command->setOption('base-directory', $this->baseDirectory);
         $command->setOption('builds-directory', $this->buildsDirectory);
 
+        ob_start();
         $result = $command->handle();
+        $output = trim(ob_get_clean());
 
-        $this->assertSame(0, $result);
+        $this->assertSame(1, $result);
+        $this->assertSame('Series directory does not exist', $output);
     }
 
     public function testMissingBaseDirectory(): void
diff --git a/tests/Console/Command/SeriesUpdateCommandTest.php b/tests/Console/Command/SeriesUpdateCommandTest.php
index 30bafca..c419fde 100644
--- a/tests/Console/Command/SeriesUpdateCommandTest.php
+++ b/tests/Console/Command/SeriesUpdateCommandTest.php
@@ -55,15 +55,18 @@ public function testMissingBuildsDirectory(): void
         $this->assertSame('Build directory is required', $output);
     }
 
-    public function testReturnsSuccessWhenNoSeriesDirectory(): void
+    public function testFailsWhenNoSeriesDirectory(): void
     {
         $command = new SeriesUpdateCommand();
         $command->setOption('base-directory', $this->baseDirectory);
         $command->setOption('builds-directory', $this->buildsDirectory);
 
+        ob_start();
         $result = $command->handle();
+        $output = trim(ob_get_clean());
 
-        $this->assertSame(0, $result);
+        $this->assertSame(1, $result);
+        $this->assertSame('Series directory does not exist', $output);
     }
 
     public function testUpdatesExistingLibraryEntry(): void
diff --git a/tests/Http/Controllers/SeriesUpdateControllerTest.php b/tests/Http/Controllers/SeriesUpdateControllerTest.php
index 56e6672..ff252b7 100644
--- a/tests/Http/Controllers/SeriesUpdateControllerTest.php
+++ b/tests/Http/Controllers/SeriesUpdateControllerTest.php
@@ -75,14 +75,36 @@ public function testEnqueuesDeleteTaskWithoutPackage(): void
         $this->assertSame($payload, $taskData);
     }
 
-    public function testRejectsInvalidPackageName(): void
+    public function testRejectsInvalidLibraryName(): void
+    {
+        $payload = [
+            'php_version' => '8.0',
+            'vs_version' => 'vs16',
+            'stability' => 'stable',
+            'library' => 'open ssl',
+            'ref' => '1.2.3',
+        ];
+
+        $inputPath = $this->createInputFile($payload);
+        $controller = new SeriesUpdateController($inputPath);
+
+        ob_start();
+        $controller->handle();
+        $output = ob_get_clean();
+        unlink($inputPath);
+
+        $this->assertStringContainsString('The library field must match the pattern /^[a-zA-Z0-9_-]+$/.', $output);
+        $this->assertEmpty(glob($this->buildsDirectory . '/series/series-update-*.json'));
+    }
+
+    public function testRejectsInvalidRefFormat(): void
     {
         $payload = [
             'php_version' => '8.0',
             'vs_version' => 'vs16',
             'stability' => 'stable',
             'library' => 'openssl',
-            // ref missing entirely
+            'ref' => 'v1/2',
         ];
 
         $inputPath = $this->createInputFile($payload);
@@ -93,7 +115,7 @@ public function testRejectsInvalidPackageName(): void
         $output = ob_get_clean();
         unlink($inputPath);
 
-        $this->assertStringContainsString('The ref field must be a string.', $output);
+        $this->assertStringContainsString('The ref field must match the pattern /^([a-zA-Z0-9\.-]+)?$/.', $output);
         $this->assertEmpty(glob($this->buildsDirectory . '/series/series-update-*.json'));
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.