Skip to content

Commit

Permalink
Genie::provision()
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Dec 6, 2020
1 parent 7dc2b03 commit f2d2c88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Genie.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public function construct(string $target, ...$pool)
return new $target(...$this->resolveArguments($target, ...$pool));
}

/**
* Inspect the given target and return an iterable list of arguments
* usable for invoking/constructing the target (using argument unpacking, the splat operator).
* Does not invoke/construct the target.
*
* @param callable|string $target
* @param mixed ...$pool
* @return iterable
*/
public function provision($target, ...$pool): iterable
{
return $this->resolveArguments($target, ...$pool);
}

/**
* Provide services without directly exposing them.
* Returns a fellow invoker with the requested services provisioned.
Expand Down
13 changes: 13 additions & 0 deletions tests/GenieCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class GenieCoreTest extends TestCase
{
use WithStuff;

public function testGenieProvisionsCallArguments()
{
$g = new Genie($c = new Sleeve([
Frog::class => new Frog(),
]));
$f1 = function (Frog $frog, int $answer) {
};
$args = $g->provision($f1, 42);
$this->assertSame($c[Frog::class], $args[0]);
$this->assertSame(42, $args[1]);
$this->assertCount(2, $args);
}

public function testGenieUsesACoreProperlyPassingArguments()
{
$passed = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/GenieProvisioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testProvideReturnsASimpleton()
$this->assertTrue($wg->provide() instanceof Simpleton);
}

public function testProvisioning()
public function testGenieProvidesServices()
{
$sleeve = ContainerProvider::createContainer();
$wg = new Genie($sleeve);
Expand Down

0 comments on commit f2d2c88

Please sign in to comment.