From d5604317831ce515bd0140e2478aaee0f0e4a8a7 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 6 Feb 2026 16:56:41 +0800 Subject: [PATCH] Fix phpunit --- src/StaticPHP/Registry/Registry.php | 178 +++++++++--------- tests/StaticPHP/Config/ArtifactConfigTest.php | 30 +-- .../StaticPHP/Config/ConfigValidatorTest.php | 2 +- tests/StaticPHP/Config/PackageConfigTest.php | 47 ++--- tests/StaticPHP/DI/CallbackInvokerTest.php | 9 +- 5 files changed, 137 insertions(+), 129 deletions(-) diff --git a/src/StaticPHP/Registry/Registry.php b/src/StaticPHP/Registry/Registry.php index a753c122c..4075b70b4 100644 --- a/src/StaticPHP/Registry/Registry.php +++ b/src/StaticPHP/Registry/Registry.php @@ -7,6 +7,7 @@ use StaticPHP\Config\ArtifactConfig; use StaticPHP\Config\PackageConfig; use StaticPHP\ConsoleApplication; +use StaticPHP\Exception\FileSystemException; use StaticPHP\Exception\RegistryException; use StaticPHP\Util\FileSystem; use Symfony\Component\Yaml\Yaml; @@ -87,116 +88,121 @@ public static function loadRegistry(string $registry_file, bool $auto_require = self::$current_registry_name = $registry_name; - // Load composer autoload if specified (for external registries with their own dependencies) - if (isset($data['autoload']) && is_string($data['autoload'])) { - $autoload_path = FileSystem::fullpath($data['autoload'], dirname($registry_file)); - if (file_exists($autoload_path)) { - logger()->debug("Loading external autoload from: {$autoload_path}"); - require_once $autoload_path; - } else { - logger()->warning("Autoload file not found: {$autoload_path}"); + try { + // Load composer autoload if specified (for external registries with their own dependencies) + if (isset($data['autoload']) && is_string($data['autoload'])) { + $autoload_path = FileSystem::fullpath($data['autoload'], dirname($registry_file)); + if (file_exists($autoload_path)) { + logger()->debug("Loading external autoload from: {$autoload_path}"); + require_once $autoload_path; + } else { + logger()->warning("Autoload file not found: {$autoload_path}"); + } } - } - // load package configs - if (isset($data['package']['config']) && is_array($data['package']['config'])) { - foreach ($data['package']['config'] as $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - if (is_file($path)) { - self::$loaded_package_configs[] = PackageConfig::loadFromFile($path, $registry_name); - } elseif (is_dir($path)) { - self::$loaded_package_configs = array_merge(self::$loaded_package_configs, PackageConfig::loadFromDir($path, $registry_name)); + // load package configs + if (isset($data['package']['config']) && is_array($data['package']['config'])) { + foreach ($data['package']['config'] as $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + if (is_file($path)) { + self::$loaded_package_configs[] = PackageConfig::loadFromFile($path, $registry_name); + } elseif (is_dir($path)) { + self::$loaded_package_configs = array_merge(self::$loaded_package_configs, PackageConfig::loadFromDir($path, $registry_name)); + } } } - } - // load artifact configs - if (isset($data['artifact']['config']) && is_array($data['artifact']['config'])) { - foreach ($data['artifact']['config'] as $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - if (is_file($path)) { - self::$loaded_artifact_configs[] = ArtifactConfig::loadFromFile($path, $registry_name); - } elseif (is_dir($path)) { - self::$loaded_package_configs = array_merge(self::$loaded_package_configs, ArtifactConfig::loadFromDir($path, $registry_name)); + // load artifact configs + if (isset($data['artifact']['config']) && is_array($data['artifact']['config'])) { + foreach ($data['artifact']['config'] as $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + if (is_file($path)) { + self::$loaded_artifact_configs[] = ArtifactConfig::loadFromFile($path, $registry_name); + } elseif (is_dir($path)) { + self::$loaded_package_configs = array_merge(self::$loaded_package_configs, ArtifactConfig::loadFromDir($path, $registry_name)); + } } } - } - // load doctor items from PSR-4 directories - if (isset($data['doctor']['psr-4']) && is_assoc_array($data['doctor']['psr-4'])) { - foreach ($data['doctor']['psr-4'] as $namespace => $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - DoctorLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + // load doctor items from PSR-4 directories + if (isset($data['doctor']['psr-4']) && is_assoc_array($data['doctor']['psr-4'])) { + foreach ($data['doctor']['psr-4'] as $namespace => $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + DoctorLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + } } - } - // load doctor items from specific classes - // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} - if (isset($data['doctor']['classes']) && is_array($data['doctor']['classes'])) { - foreach ($data['doctor']['classes'] as $key => $value) { - [$class, $file] = self::parseClassEntry($key, $value); - self::requireClassFile($class, $file, dirname($registry_file), $auto_require); - DoctorLoader::loadFromClass($class); + // load doctor items from specific classes + // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} + if (isset($data['doctor']['classes']) && is_array($data['doctor']['classes'])) { + foreach ($data['doctor']['classes'] as $key => $value) { + [$class, $file] = self::parseClassEntry($key, $value); + self::requireClassFile($class, $file, dirname($registry_file), $auto_require); + DoctorLoader::loadFromClass($class); + } } - } - // load packages from PSR-4 directories - if (isset($data['package']['psr-4']) && is_assoc_array($data['package']['psr-4'])) { - foreach ($data['package']['psr-4'] as $namespace => $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - PackageLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + // load packages from PSR-4 directories + if (isset($data['package']['psr-4']) && is_assoc_array($data['package']['psr-4'])) { + foreach ($data['package']['psr-4'] as $namespace => $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + PackageLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + } + } + + // load packages from specific classes + // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} + if (isset($data['package']['classes']) && is_array($data['package']['classes'])) { + foreach ($data['package']['classes'] as $key => $value) { + [$class, $file] = self::parseClassEntry($key, $value); + self::requireClassFile($class, $file, dirname($registry_file), $auto_require); + PackageLoader::loadFromClass($class); + } } - } - // load packages from specific classes - // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} - if (isset($data['package']['classes']) && is_array($data['package']['classes'])) { - foreach ($data['package']['classes'] as $key => $value) { - [$class, $file] = self::parseClassEntry($key, $value); - self::requireClassFile($class, $file, dirname($registry_file), $auto_require); - PackageLoader::loadFromClass($class); + // load artifacts from PSR-4 directories + if (isset($data['artifact']['psr-4']) && is_assoc_array($data['artifact']['psr-4'])) { + foreach ($data['artifact']['psr-4'] as $namespace => $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + ArtifactLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + } } - } - // load artifacts from PSR-4 directories - if (isset($data['artifact']['psr-4']) && is_assoc_array($data['artifact']['psr-4'])) { - foreach ($data['artifact']['psr-4'] as $namespace => $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - ArtifactLoader::loadFromPsr4Dir($path, $namespace, $auto_require); + // load artifacts from specific classes + // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} + if (isset($data['artifact']['classes']) && is_array($data['artifact']['classes'])) { + foreach ($data['artifact']['classes'] as $key => $value) { + [$class, $file] = self::parseClassEntry($key, $value); + self::requireClassFile($class, $file, dirname($registry_file), $auto_require); + ArtifactLoader::loadFromClass($class); + } } - } - // load artifacts from specific classes - // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} - if (isset($data['artifact']['classes']) && is_array($data['artifact']['classes'])) { - foreach ($data['artifact']['classes'] as $key => $value) { - [$class, $file] = self::parseClassEntry($key, $value); - self::requireClassFile($class, $file, dirname($registry_file), $auto_require); - ArtifactLoader::loadFromClass($class); + // load additional commands from PSR-4 directories + if (isset($data['command']['psr-4']) && is_assoc_array($data['command']['psr-4'])) { + foreach ($data['command']['psr-4'] as $namespace => $path) { + $path = FileSystem::fullpath($path, dirname($registry_file)); + $classes = FileSystem::getClassesPsr4($path, $namespace, auto_require: $auto_require); + $instances = array_map(fn ($x) => new $x(), $classes); + ConsoleApplication::_addAdditionalCommands($instances); + } } - } - // load additional commands from PSR-4 directories - if (isset($data['command']['psr-4']) && is_assoc_array($data['command']['psr-4'])) { - foreach ($data['command']['psr-4'] as $namespace => $path) { - $path = FileSystem::fullpath($path, dirname($registry_file)); - $classes = FileSystem::getClassesPsr4($path, $namespace, auto_require: $auto_require); - $instances = array_map(fn ($x) => new $x(), $classes); + // load additional commands from specific classes + // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} + if (isset($data['command']['classes']) && is_array($data['command']['classes'])) { + $instances = []; + foreach ($data['command']['classes'] as $key => $value) { + [$class, $file] = self::parseClassEntry($key, $value); + self::requireClassFile($class, $file, dirname($registry_file), $auto_require); + $instances[] = new $class(); + } ConsoleApplication::_addAdditionalCommands($instances); } + } catch (FileSystemException $e) { + throw new RegistryException($e->getMessage(), 0, $e); } - // load additional commands from specific classes - // Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"} - if (isset($data['command']['classes']) && is_array($data['command']['classes'])) { - $instances = []; - foreach ($data['command']['classes'] as $key => $value) { - [$class, $file] = self::parseClassEntry($key, $value); - self::requireClassFile($class, $file, dirname($registry_file), $auto_require); - $instances[] = new $class(); - } - ConsoleApplication::_addAdditionalCommands($instances); - } self::$current_registry_name = null; } diff --git a/tests/StaticPHP/Config/ArtifactConfigTest.php b/tests/StaticPHP/Config/ArtifactConfigTest.php index dc3964881..f99903652 100644 --- a/tests/StaticPHP/Config/ArtifactConfigTest.php +++ b/tests/StaticPHP/Config/ArtifactConfigTest.php @@ -50,7 +50,7 @@ public function testLoadFromDirThrowsExceptionWhenDirectoryDoesNotExist(): void $this->expectException(WrongUsageException::class); $this->expectExceptionMessage('Directory /nonexistent/path does not exist, cannot load artifact config.'); - ArtifactConfig::loadFromDir('/nonexistent/path'); + ArtifactConfig::loadFromDir('/nonexistent/path', 'test'); } public function testLoadFromDirWithValidArtifactJson(): void @@ -63,7 +63,7 @@ public function testLoadFromDirWithValidArtifactJson(): void file_put_contents($this->tempDir . '/artifact.json', $artifactContent); - ArtifactConfig::loadFromDir($this->tempDir); + ArtifactConfig::loadFromDir($this->tempDir, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config); @@ -88,7 +88,7 @@ public function testLoadFromDirWithMultipleArtifactFiles(): void file_put_contents($this->tempDir . '/artifact.lib.json', $artifact2Content); file_put_contents($this->tempDir . '/artifact.json', json_encode(['artifact-3' => ['source' => 'custom']])); - ArtifactConfig::loadFromDir($this->tempDir); + ArtifactConfig::loadFromDir($this->tempDir, 'test'); $this->assertNotNull(ArtifactConfig::get('artifact-1')); $this->assertNotNull(ArtifactConfig::get('artifact-2')); @@ -100,7 +100,7 @@ public function testLoadFromFileThrowsExceptionWhenFileCannotBeRead(): void $this->expectException(WrongUsageException::class); $this->expectExceptionMessage('Failed to read artifact config file:'); - ArtifactConfig::loadFromFile('/nonexistent/file.json'); + ArtifactConfig::loadFromFile('/nonexistent/file.json', 'test'); } public function testLoadFromFileThrowsExceptionWhenJsonIsInvalid(): void @@ -111,7 +111,7 @@ public function testLoadFromFileThrowsExceptionWhenJsonIsInvalid(): void $this->expectException(WrongUsageException::class); $this->expectExceptionMessage('Invalid JSON format in artifact config file:'); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); } public function testLoadFromFileWithValidJson(): void @@ -127,7 +127,7 @@ public function testLoadFromFileWithValidJson(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('my-artifact'); $this->assertIsArray($config); @@ -144,7 +144,7 @@ public function testGetAllReturnsAllLoadedArtifacts(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $all = ArtifactConfig::getAll(); $this->assertIsArray($all); @@ -170,7 +170,7 @@ public function testGetReturnsConfigWhenArtifactExists(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config); @@ -188,7 +188,7 @@ public function testLoadFromFileWithExpandedUrlInSource(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config); @@ -208,7 +208,7 @@ public function testLoadFromFileWithBinaryCustom(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config['binary']); @@ -228,7 +228,7 @@ public function testLoadFromFileWithBinaryHosted(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config['binary']); @@ -253,7 +253,7 @@ public function testLoadFromFileWithBinaryPlatformSpecific(): void ]); file_put_contents($file, $content); - ArtifactConfig::loadFromFile($file); + ArtifactConfig::loadFromFile($file, 'test'); $config = ArtifactConfig::get('test-artifact'); $this->assertIsArray($config['binary']); @@ -266,7 +266,7 @@ public function testLoadFromFileWithBinaryPlatformSpecific(): void public function testLoadFromDirWithEmptyDirectory(): void { // Empty directory should not throw exception - ArtifactConfig::loadFromDir($this->tempDir); + ArtifactConfig::loadFromDir($this->tempDir, 'test'); $this->assertEquals([], ArtifactConfig::getAll()); } @@ -279,8 +279,8 @@ public function testMultipleLoadsAppendConfigs(): void file_put_contents($file1, json_encode(['art1' => ['source' => 'custom']])); file_put_contents($file2, json_encode(['art2' => ['source' => 'custom']])); - ArtifactConfig::loadFromFile($file1); - ArtifactConfig::loadFromFile($file2); + ArtifactConfig::loadFromFile($file1, 'test'); + ArtifactConfig::loadFromFile($file2, 'test'); $all = ArtifactConfig::getAll(); $this->assertCount(2, $all); diff --git a/tests/StaticPHP/Config/ConfigValidatorTest.php b/tests/StaticPHP/Config/ConfigValidatorTest.php index ae5544ae1..56f61ea63 100644 --- a/tests/StaticPHP/Config/ConfigValidatorTest.php +++ b/tests/StaticPHP/Config/ConfigValidatorTest.php @@ -582,7 +582,7 @@ public function testValidateAndLintPackagesWithAllFieldTypes(): void public function testValidateAndLintPackagesThrowsExceptionForWrongTypeString(): void { $this->expectException(ValidationException::class); - $this->expectExceptionMessage('Package test-pkg [artifact] must be string'); + $this->expectExceptionMessage('Package test-pkg [artifact] has invalid type specification'); $data = [ 'test-pkg' => [ diff --git a/tests/StaticPHP/Config/PackageConfigTest.php b/tests/StaticPHP/Config/PackageConfigTest.php index 4072e39e9..ce28aebc0 100644 --- a/tests/StaticPHP/Config/PackageConfigTest.php +++ b/tests/StaticPHP/Config/PackageConfigTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use StaticPHP\Config\PackageConfig; +use StaticPHP\Exception\ValidationException; use StaticPHP\Exception\WrongUsageException; use StaticPHP\Runtime\SystemTarget; @@ -49,7 +50,7 @@ public function testLoadFromDirThrowsExceptionWhenDirectoryDoesNotExist(): void $this->expectException(WrongUsageException::class); $this->expectExceptionMessage('Directory /nonexistent/path does not exist, cannot load pkg.json config.'); - PackageConfig::loadFromDir('/nonexistent/path'); + PackageConfig::loadFromDir('/nonexistent/path', 'test'); } public function testLoadFromDirWithValidPkgJson(): void @@ -63,7 +64,7 @@ public function testLoadFromDirWithValidPkgJson(): void file_put_contents($this->tempDir . '/pkg.json', $packageContent); - PackageConfig::loadFromDir($this->tempDir); + PackageConfig::loadFromDir($this->tempDir, 'test'); $this->assertTrue(PackageConfig::isPackageExists('test-pkg')); } @@ -87,7 +88,7 @@ public function testLoadFromDirWithMultiplePackageFiles(): void file_put_contents($this->tempDir . '/pkg.lib.json', $pkg2Content); file_put_contents($this->tempDir . '/pkg.json', json_encode(['pkg-3' => ['type' => 'virtual-target']])); - PackageConfig::loadFromDir($this->tempDir); + PackageConfig::loadFromDir($this->tempDir, 'test'); $this->assertTrue(PackageConfig::isPackageExists('pkg-1')); $this->assertTrue(PackageConfig::isPackageExists('pkg-2')); @@ -99,7 +100,7 @@ public function testLoadFromFileThrowsExceptionWhenFileCannotBeRead(): void $this->expectException(WrongUsageException::class); $this->expectExceptionMessage('Failed to read package config file:'); - PackageConfig::loadFromFile('/nonexistent/file.json'); + PackageConfig::loadFromFile('/nonexistent/file.json', 'test'); } public function testLoadFromFileThrowsExceptionWhenJsonIsInvalid(): void @@ -107,10 +108,10 @@ public function testLoadFromFileThrowsExceptionWhenJsonIsInvalid(): void $file = $this->tempDir . '/invalid.json'; file_put_contents($file, 'not valid json{'); - $this->expectException(WrongUsageException::class); - $this->expectExceptionMessage('Invalid JSON format in package config file:'); + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('invalid.json is broken'); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); } public function testLoadFromFileWithValidJson(): void @@ -124,7 +125,7 @@ public function testLoadFromFileWithValidJson(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $this->assertTrue(PackageConfig::isPackageExists('my-pkg')); } @@ -145,7 +146,7 @@ public function testIsPackageExistsReturnsTrueWhenPackageLoaded(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $this->assertTrue(PackageConfig::isPackageExists('test-pkg')); } @@ -160,7 +161,7 @@ public function testGetAllReturnsAllLoadedPackages(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $all = PackageConfig::getAll(); $this->assertIsArray($all); @@ -189,7 +190,7 @@ public function testGetReturnsWholePackageWhenFieldNameIsNull(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $result = PackageConfig::get('test-pkg'); $this->assertIsArray($result); @@ -208,7 +209,7 @@ public function testGetReturnsFieldValueWhenFieldExists(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $result = PackageConfig::get('test-pkg', 'artifact'); $this->assertEquals('test-artifact', $result); @@ -225,7 +226,7 @@ public function testGetReturnsDefaultWhenFieldNotExists(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $result = PackageConfig::get('test-pkg', 'non-existent-field', 'default'); $this->assertEquals('default', $result); @@ -251,7 +252,7 @@ public function testGetWithSuffixFieldsOnLinux(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); // The get method will check SystemTarget::getTargetOS() // On real Linux systems, it should return 'depends@linux' first @@ -273,7 +274,7 @@ public function testGetWithSuffixFieldsReturnsBasicFieldWhenNoSuffixMatch(): voi ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $result = PackageConfig::get('test-pkg', 'depends'); $this->assertEquals(['base-dep'], $result); @@ -291,7 +292,7 @@ public function testGetWithNonSuffixedFieldIgnoresSuffixes(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); // 'artifact' is not in SUFFIX_ALLOWED_FIELDS, so it won't check suffixes $result = PackageConfig::get('test-pkg', 'artifact'); @@ -314,7 +315,7 @@ public function testGetAllSuffixAllowedFields(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); // These are all suffix-allowed fields $pkg = PackageConfig::get('test-pkg'); @@ -328,7 +329,7 @@ public function testGetAllSuffixAllowedFields(): void public function testLoadFromDirWithEmptyDirectory(): void { // Empty directory should not throw exception - PackageConfig::loadFromDir($this->tempDir); + PackageConfig::loadFromDir($this->tempDir, 'test'); $this->assertEquals([], PackageConfig::getAll()); } @@ -341,8 +342,8 @@ public function testMultipleLoadsAppendConfigs(): void file_put_contents($file1, json_encode(['pkg1' => ['type' => 'virtual-target']])); file_put_contents($file2, json_encode(['pkg2' => ['type' => 'virtual-target']])); - PackageConfig::loadFromFile($file1); - PackageConfig::loadFromFile($file2); + PackageConfig::loadFromFile($file1, 'test'); + PackageConfig::loadFromFile($file2, 'test'); $all = PackageConfig::getAll(); $this->assertCount(2, $all); @@ -366,7 +367,7 @@ public function testGetWithComplexPhpExtensionPackage(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $phpExt = PackageConfig::get('test-ext', 'php-extension'); $this->assertIsArray($phpExt); @@ -384,7 +385,7 @@ public function testGetReturnsNullAsDefaultWhenNotSpecified(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $result = PackageConfig::get('test-pkg', 'non-existent'); $this->assertNull($result); @@ -411,7 +412,7 @@ public function testLoadFromFileWithAllPackageTypes(): void ]); file_put_contents($file, $content); - PackageConfig::loadFromFile($file); + PackageConfig::loadFromFile($file, 'test'); $this->assertTrue(PackageConfig::isPackageExists('library-pkg')); $this->assertTrue(PackageConfig::isPackageExists('extension-pkg')); diff --git a/tests/StaticPHP/DI/CallbackInvokerTest.php b/tests/StaticPHP/DI/CallbackInvokerTest.php index 751a70eb9..01cacd392 100644 --- a/tests/StaticPHP/DI/CallbackInvokerTest.php +++ b/tests/StaticPHP/DI/CallbackInvokerTest.php @@ -7,6 +7,7 @@ use DI\Container; use PHPUnit\Framework\TestCase; use StaticPHP\DI\CallbackInvoker; +use StaticPHP\Exception\SPCInternalException; /** * Helper class that requires constructor parameters for testing @@ -92,7 +93,7 @@ public function testInvokeCallbackWithContainerResolution(): void // Should not resolve from container as 'test.service' is not a type // Will try default value or null - $this->expectException(\RuntimeException::class); + $this->expectException(SPCInternalException::class); $this->invoker->invoke($callback); } @@ -139,7 +140,7 @@ public function testInvokeCallbackThrowsExceptionForUnresolvableParameter(): voi return $required; }; - $this->expectException(\RuntimeException::class); + $this->expectException(SPCInternalException::class); $this->expectExceptionMessage("Cannot resolve parameter 'required' of type 'string'"); $this->invoker->invoke($callback); } @@ -527,7 +528,7 @@ public function testInvokeWithUnionTypeThrowsException(): void $callback = eval('return function (string|int $param) { return $param; };'); // Union types are not ReflectionNamedType, should not be resolved from container - $this->expectException(\RuntimeException::class); + $this->expectException(SPCInternalException::class); $this->invoker->invoke($callback); } @@ -594,7 +595,7 @@ public function testInvokeWithContainerExceptionAndNoFallback(): void return $obj; }; - $this->expectException(\RuntimeException::class); + $this->expectException(SPCInternalException::class); $this->expectExceptionMessage("Cannot resolve parameter 'obj'"); $this->invoker->invoke($callback);