mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-06 16:25:39 +08:00
Add build function check for current OS and update validation logic
This commit is contained in:
@@ -377,6 +377,10 @@ class PackageLoaderTest extends TestCase
|
||||
$this->createTestPackageConfig('test-lib', 'library');
|
||||
PackageLoader::initPackageInstances();
|
||||
|
||||
// Add a build function for current OS so the stage validation is triggered
|
||||
$package = PackageLoader::getPackage('test-lib');
|
||||
$package->addBuildFunction(PHP_OS_FAMILY, fn () => null);
|
||||
|
||||
// Manually add a before_stage for non-existent stage
|
||||
$reflection = new \ReflectionClass(PackageLoader::class);
|
||||
$property = $reflection->getProperty('before_stages');
|
||||
@@ -417,6 +421,33 @@ class PackageLoaderTest extends TestCase
|
||||
PackageLoader::checkLoadedStageEvents();
|
||||
}
|
||||
|
||||
public function testCheckLoadedStageEventsDoesNotThrowForNonCurrentOSPackage(): void
|
||||
{
|
||||
$this->createTestPackageConfig('test-lib', 'library');
|
||||
PackageLoader::initPackageInstances();
|
||||
|
||||
// Add a build function for a different OS (not current OS)
|
||||
$package = PackageLoader::getPackage('test-lib');
|
||||
$otherOS = PHP_OS_FAMILY === 'Windows' ? 'Linux' : 'Windows';
|
||||
$package->addBuildFunction($otherOS, fn () => null);
|
||||
|
||||
// Manually add a before_stage for 'build' stage
|
||||
// This should NOT throw an exception because the package has no build function for current OS
|
||||
$reflection = new \ReflectionClass(PackageLoader::class);
|
||||
$property = $reflection->getProperty('before_stages');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue(null, [
|
||||
'test-lib' => [
|
||||
'build' => [[fn () => null, null]],
|
||||
],
|
||||
]);
|
||||
|
||||
// This should not throw an exception
|
||||
PackageLoader::checkLoadedStageEvents();
|
||||
|
||||
$this->assertTrue(true); // If we get here, the test passed
|
||||
}
|
||||
|
||||
public function testGetBeforeStageCallbacksReturnsCallbacks(): void
|
||||
{
|
||||
PackageLoader::initPackageInstances();
|
||||
@@ -502,13 +533,13 @@ class PackageLoaderTest extends TestCase
|
||||
mkdir($psr4Dir, 0755, true);
|
||||
|
||||
// Create test class file
|
||||
$classContent = '<?php
|
||||
namespace Test\Package;
|
||||
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
|
||||
#[Library("test-lib")]
|
||||
class TestPackage1 {
|
||||
$classContent = '<?php
|
||||
namespace Test\Package;
|
||||
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
|
||||
#[Library("test-lib")]
|
||||
class TestPackage1 {
|
||||
}';
|
||||
file_put_contents($psr4Dir . '/TestPackage1.php', $classContent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user