mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 00:35:41 +08:00
Refactor all (except command) modules using new exceptions
This commit is contained in:
@@ -6,8 +6,7 @@ namespace SPC\Tests\globals;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LogLevel;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\exception\ExecutionException;
|
||||
use ZM\Logger\ConsoleLogger;
|
||||
|
||||
/**
|
||||
@@ -64,7 +63,7 @@ class GlobalFunctionsTest extends TestCase
|
||||
$this->markTestSkipped('Windows not support f_passthru');
|
||||
}
|
||||
$this->assertEquals(null, f_passthru('echo ""'));
|
||||
$this->expectException('SPC\exception\RuntimeException');
|
||||
$this->expectException(ExecutionException::class);
|
||||
f_passthru('false');
|
||||
}
|
||||
|
||||
@@ -80,16 +79,16 @@ class GlobalFunctionsTest extends TestCase
|
||||
$this->markTestSkipped('Windows not support shell');
|
||||
}
|
||||
$shell = shell();
|
||||
$this->assertInstanceOf('SPC\util\UnixShell', $shell);
|
||||
$this->assertInstanceOf('SPC\util\UnixShell', $shell->cd('/'));
|
||||
$this->assertInstanceOf('SPC\util\UnixShell', $shell->exec('echo ""'));
|
||||
$this->assertInstanceOf('SPC\util\UnixShell', $shell->setEnv(['SPC_TEST_ENV' => '1']));
|
||||
$this->assertInstanceOf('SPC\util\shell\UnixShell', $shell);
|
||||
$this->assertInstanceOf('SPC\util\shell\UnixShell', $shell->cd('/'));
|
||||
$this->assertInstanceOf('SPC\util\shell\UnixShell', $shell->exec('echo ""'));
|
||||
$this->assertInstanceOf('SPC\util\shell\UnixShell', $shell->setEnv(['SPC_TEST_ENV' => '1']));
|
||||
|
||||
[$code, $out] = $shell->execWithResult('echo "_"');
|
||||
$this->assertEquals(0, $code);
|
||||
$this->assertEquals('_', implode('', $out));
|
||||
|
||||
$this->expectException('SPC\exception\RuntimeException');
|
||||
$this->expectException('SPC\exception\ExecutionException');
|
||||
$shell->exec('false');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace SPC\Tests\store;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\exception\InterruptException;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\LockFile;
|
||||
|
||||
@@ -34,7 +34,7 @@ class DownloaderTest extends TestCase
|
||||
// test keyboard interrupt
|
||||
try {
|
||||
Downloader::downloadGit('setup-static-php', 'https://github.com/static-php/setup-static-php.git', 'SIGINT');
|
||||
} catch (WrongUsageException $e) {
|
||||
} catch (InterruptException $e) {
|
||||
$this->assertStringContainsString('interrupted', $e->getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class DownloaderTest extends TestCase
|
||||
// test keyboard interrupt
|
||||
try {
|
||||
Downloader::downloadFile('fake-file', 'https://fakecmd.com/curlDown', 'SIGINT');
|
||||
} catch (WrongUsageException $e) {
|
||||
} catch (InterruptException $e) {
|
||||
$this->assertStringContainsString('interrupted', $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace SPC\Tests\util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\SPCInternalException;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
/**
|
||||
@@ -105,7 +105,7 @@ final class GlobalEnvManagerTest extends TestCase
|
||||
// Temporarily unset BUILD_ROOT_PATH
|
||||
putenv('BUILD_ROOT_PATH');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectException(SPCInternalException::class);
|
||||
GlobalEnvManager::init();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace SPC\Tests\util;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\ExecutionException;
|
||||
use SPC\util\PkgConfigUtil;
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ final class PkgConfigUtilTest extends TestCase
|
||||
*/
|
||||
public function testGetCflagsWithInvalidPackage(string $package): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectException(ExecutionException::class);
|
||||
PkgConfigUtil::getCflags($package);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ final class PkgConfigUtilTest extends TestCase
|
||||
*/
|
||||
public function testGetLibsArrayWithInvalidPackage(string $package): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectException(ExecutionException::class);
|
||||
PkgConfigUtil::getLibsArray($package);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\store;
|
||||
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\InterruptException;
|
||||
use SPC\exception\SPCInternalException;
|
||||
|
||||
function f_exec(string $command, mixed &$output, mixed &$result_code): bool
|
||||
{
|
||||
@@ -52,13 +53,13 @@ function f_passthru(string $cmd): bool
|
||||
{
|
||||
if (str_starts_with($cmd, 'git')) {
|
||||
if (str_contains($cmd, '--branch "SIGINT"')) {
|
||||
throw new RuntimeException('Interrupt', 2);
|
||||
throw new InterruptException('interrupted', 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (str_contains($cmd, 'https://fakecmd.com/curlDown')) {
|
||||
if (str_contains($cmd, 'SIGINT')) {
|
||||
throw new RuntimeException('Interrupt', 2);
|
||||
throw new InterruptException('interrupted', 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -71,5 +72,5 @@ function f_passthru(string $cmd): bool
|
||||
return true;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('Invalid tests');
|
||||
throw new SPCInternalException('Invalid tests');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user