Skip to content

Commit

Permalink
cover cases not covered by v2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Dec 7, 2020
1 parent f2d2c88 commit d147efd
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/GenieCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Dakujem\Wire\Tests;

use Dakujem\Sleeve;
use Dakujem\Wire\Exceptions\Unresolvable;
use Dakujem\Wire\Exceptions\UnresolvableCallArguments;
use Dakujem\Wire\Genie;
use PHPUnit\Framework\TestCase;

Expand All @@ -14,6 +16,7 @@
class GenieCoreTest extends TestCase
{
use WithStuff;
use AssertsErrors;

public function testGenieProvisionsCallArguments()
{
Expand Down Expand Up @@ -70,4 +73,42 @@ public function testEmploy()
$this->with(new Genie($c, $core), $contains);
$this->with(Genie::employ($c, $core), $contains);
}

public function testInvocationTypeSwitch()
{
$g = new Genie($c = new Sleeve([
Constant::class => new Constant(0.0),
Coefficient::class => new Coefficient(1.0),
Offset::class => function ($c) {
return new Offset($c[Constant::class], $c[Coefficient::class]);
},
]));

$o1 = $g(Offset::class);
$o2 = $g(function (Offset $offset) {
return $offset;
});

$this->assertSame($c[Offset::class], $o2);
$this->assertInstanceOf(Offset::class, $o1);
$this->assertNotSame($c[Offset::class], $o1); // must not be the same, one is created, other one is from the container
$self = $this;
$this->with($o1, function () use ($self, $c) {
// assert that the services contained inside the newly created Offset instance come from the container
$self->assertSame($c[Constant::class], $this->absolute);
$self->assertSame($c[Coefficient::class], $this->relative);
});
}

public function testUnresolvable()
{
$g = new Genie(new Sleeve([]), function () {
throw new UnresolvableCallArguments('foo');
});

$this->assertException(function () use ($g) {
$g(function () {
});
}, Unresolvable::class);
}
}

0 comments on commit d147efd

Please sign in to comment.