Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependencyIndex to the message of the Unbound exception #113

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CompileInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function getInstanceFile(string $dependencyIndex): string

$checkFile = sprintf(self::COMPILE_CHECK, $this->scriptDir);
if (file_exists($checkFile)) {
throw new Unbound(sprintf('See compile log %s', $this->scriptDir . '/_compile.log'));
throw new Unbound(sprintf('[%s] See compile log %s', $dependencyIndex, $this->scriptDir . '/_compile.log'));
}

touch($checkFile);
Expand Down
1 change: 1 addition & 0 deletions src/DependencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private function getProviderCode(DependencyProvider $provider): Code
$isSingleton = $prop($provider, 'isSingleton');
$node[] = $this->getIsSingletonCode($isSingleton);
$node[] = new Stmt\Return_(new MethodCall(new Expr\Variable('instance'), 'get'));
/** @psalm-suppress InvalidArgument */
$node = $this->factory->namespace('Ray\Di\Compiler')->addStmts($node)->getNode();
$qualifer = $this->qualifier;
$this->qualifier = null;
Expand Down
19 changes: 16 additions & 3 deletions tests/DependencyCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public function testInstanceCompileArray(): void

return array(1, 2, 3);
EOT;
$this->assertSame($expected, (string) $code);
$this->assertContains((string) $code, [
str_replace('array(1, 2, 3)', '[1, 2, 3]', $expected),
$expected,
]);
}

public function testDependencyCompile(): void
Expand All @@ -77,7 +80,14 @@ public function testDependencyCompile(): void
return $instance;
EOT;
$expected = str_replace('{ANY}', Name::ANY, $expectedTemplate);
$this->assertSame($expected, (string) $code);
$this->assertContains((string) $code, [
str_replace(
'array(\'Ray\\Compiler\\FakeCar\', \'setHandle\', \'handle\')',
'[\'Ray\\Compiler\\FakeCar\', \'setHandle\', \'handle\']',
str_replace('\\\\', '\\', $expected)
),
$expected,
]);
}

public function testDependencyProviderCompile(): void
Expand Down Expand Up @@ -120,7 +130,10 @@ public function testDependencyObjectInstanceCompile(): void

return unserialize('O:23:"Ray\\Compiler\\FakeEngine":0:{}');
EOT;
$this->assertSame($expected, (string) $code);
$this->assertContains((string) $code, [
str_replace('\\\\', '\\', $expected),
$expected,
]);
}

public function testDomainException(): void
Expand Down
Loading
Loading