Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Sep 8, 2015
1 parent d9f8892 commit ef86b8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The library provides unit tests that covers the core-functionality normally run
[continues integration platform][travis]. Tests can also be executed manually using the
`composer phpunit` command from the root directory.

### Release notes
## Release notes

- 1.0.0 Initial release (2015-09-07)
- Added the `CallbackContainer` and `CallbackLoader` interface
Expand Down
2 changes: 1 addition & 1 deletion src/DeferredCallbackLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function singleton( $handlerName ) {

$instance = $this->getReturnValueFromSingletonFor( $handlerName, $fingerprint );

if ( !isset( $this->expectedReturnTypeByHandler[$handlerName] ) || is_a( $instance, $this->expectedReturnTypeByHandler[$handlerName] ) ) {
if ( $instance !== null && ( !isset( $this->expectedReturnTypeByHandler[$handlerName] ) || is_a( $instance, $this->expectedReturnTypeByHandler[$handlerName] ) ) ) {
return $instance;
}

Expand Down
35 changes: 26 additions & 9 deletions tests/phpunit/Unit/DeferredCallbackLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function testRegisterCallback() {
return new \stdClass;
} );

$instance->registerExpectedReturnType( 'Foo', '\stdClass' );

$this->assertEquals(
new \stdClass,
$instance->load( 'Foo' )
Expand All @@ -57,11 +55,29 @@ public function testRegisterCallback() {
new \stdClass,
$instance->singleton( 'Foo' )
);
}

public function testDeregisterCallback() {

$instance = new DeferredCallbackLoader();

$instance->registerCallback( 'Foo', function() {
return 'abc';
} );

$this->assertEquals(
'abc',
$instance->load( 'Foo' )
);

$instance->deregister( 'Foo' );

$this->assertNull(
$instance->singleton( 'Foo' )
);
}

public function testLoadTypedReturn() {
public function testLoadCallbackHandlerWithExpectedReturnType() {

$instance = new DeferredCallbackLoader();

Expand All @@ -77,7 +93,7 @@ public function testLoadTypedReturn() {
);
}

public function testLoadUntypedHandler() {
public function testLoadCallbackHandlerWithoutExpectedReturnType() {

$instance = new DeferredCallbackLoader();

Expand All @@ -93,7 +109,8 @@ public function testLoadUntypedHandler() {

public function testRegisterCallbackContainer() {

$instance = new DeferredCallbackLoader( new FooCallbackContainer() );
$instance = new DeferredCallbackLoader();
$instance->registerCallbackContainer( new FooCallbackContainer() );

$this->assertEquals(
new \stdClass,
Expand Down Expand Up @@ -146,7 +163,7 @@ public function testInjectInstanceForExistingRegisteredCallbackHandler() {
);
}

public function testLoadParameterizedInstance() {
public function testLoadParameterizedCallbackHandler() {

$instance = new DeferredCallbackLoader();

Expand Down Expand Up @@ -183,7 +200,7 @@ public function testSingleton() {
);
}

public function testFingerprintedParameterizedSingleton() {
public function testFingerprintedParameterizedSingletonCallbackHandler() {

$instance = new DeferredCallbackLoader();

Expand All @@ -208,7 +225,7 @@ public function testFingerprintedParameterizedSingleton() {
);
}

public function testLoadUnregisteredCallbackHandlerToReturnNull() {
public function testUnregisteredCallbackHandlerIsToReturnNull() {

$instance = new DeferredCallbackLoader();

Expand All @@ -217,7 +234,7 @@ public function testLoadUnregisteredCallbackHandlerToReturnNull() {
);
}

public function testLoadUnregisteredCallbackHandlerAsSingletonToReturnNull() {
public function testUnregisteredCallbackHandlerForSingletonIsToReturnNull() {

$instance = new DeferredCallbackLoader();

Expand Down

0 comments on commit ef86b8b

Please sign in to comment.