Skip to content

Commit

Permalink
Merge pull request #50 from cmodijk/test-1
Browse files Browse the repository at this point in the history
CouldNotResolveCallable child service
  • Loading branch information
matthiasnoback committed Feb 12, 2016
2 parents bd29bfa + e84ca4a commit 723bf20
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/CallableResolver/Exception/CouldNotResolveCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ public static function createFor($value)

private static function printValue($value)
{
return str_replace(' ', '', str_replace("\n", '', print_r($value, true)));
return str_replace(' ', '', str_replace("\n", '', print_r(self::convertValue($value), true)));
}

private static function convertValue($value)
{
if (is_array($value)) {
return array_map(function($value){
return self::convertObject($value);
}, $value);
}

return self::convertObject($value);
}

private static function convertObject($value)
{
if (is_object($value)) {
return get_class($value);
}

return $value;
}
}
38 changes: 36 additions & 2 deletions tests/CallableResolver/ServiceLocatorAwareCallableResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,24 @@ public function it_fails_if_the_loaded_service_is_not_callable()

$this->setExpectedException(
'SimpleBus\Message\CallableResolver\Exception\CouldNotResolveCallable',
'stdClass Object() could not be resolved to a valid callable'
'stdClass could not be resolved to a valid callable'
);
$this->resolver->resolve('not_a_callable');
}

/**
* @test
*/
public function it_fails_if_the_loaded_service_is_not_callable_does_not_list_child_service()
{
$handler = new \stdClass();
$handler->childService = new \stdClass();

$this->services['not_a_callable'] = $handler;

$this->setExpectedException(
'SimpleBus\Message\CallableResolver\Exception\CouldNotResolveCallable',
'stdClass could not be resolved to a valid callable'
);
$this->resolver->resolve('not_a_callable');
}
Expand All @@ -93,7 +110,24 @@ public function it_fails_if_the_loaded_service_and_method_array_is_not_callable(

$this->setExpectedException(
'SimpleBus\Message\CallableResolver\Exception\CouldNotResolveCallable',
'Array([0] => stdClass Object()[1] => nonExistingMethod) could not be resolved to a valid callable'
'Array([0] => stdClass[1] => nonExistingMethod) could not be resolved to a valid callable'
);
$this->resolver->resolve(['callable_service_id', 'nonExistingMethod']);
}

/**
* @test
*/
public function it_fails_if_the_loaded_service_and_method_array_is_not_callable_does_not_list_child_service()
{
$handler = new \stdClass();
$handler->childService = new \stdClass();

$this->services['callable_service_id'] = $handler;

$this->setExpectedException(
'SimpleBus\Message\CallableResolver\Exception\CouldNotResolveCallable',
'Array([0] => stdClass[1] => nonExistingMethod) could not be resolved to a valid callable'
);
$this->resolver->resolve(['callable_service_id', 'nonExistingMethod']);
}
Expand Down

0 comments on commit 723bf20

Please sign in to comment.