Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Nov 15, 2020
1 parent 61b4de9 commit 6e9cd67
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Container/ResolvingCallbackTest.php
Expand Up @@ -441,6 +441,45 @@ public function testAfterResolvingCallbacksAreCalledOnceForImplementation()
$container->make(ResolvingContractStub::class);
$this->assertEquals(2, $callCounter);
}

public function testBeforeResolvingCallbacksAreCalled()
{
// Given a call counter initialized to zero.
$container = new Container;
$callCounter = 0;

// And a contract/implementation stub binding.
$container->bind(ResolvingContractStub::class, ResolvingImplementationStub::class);

// When we add a before resolving callback that increment the counter by one.
$container->beforeResolving(ResolvingContractStub::class, function () use (&$callCounter) {
$callCounter++;
});

// Then resolving the implementation stub increases the counter by one.
$container->make(ResolvingImplementationStub::class);
$this->assertEquals(1, $callCounter);

// And resolving the contract stub increases the counter by one.
$container->make(ResolvingContractStub::class);
$this->assertEquals(2, $callCounter);
}

public function testGlobalBeforeResolvingCallbacksAreCalled()
{
// Given a call counter initialized to zero.
$container = new Container;
$callCounter = 0;

// When we add a global before resolving callback that increment that counter by one.
$container->beforeResolving(function () use (&$callCounter) {
$callCounter++;
});

// Then resolving anything increases the counter by one.
$container->make(ResolvingImplementationStub::class);
$this->assertEquals(1, $callCounter);
}
}

interface ResolvingContractStub
Expand Down

0 comments on commit 6e9cd67

Please sign in to comment.