-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added ContainerBuilder::findByType tests
- Loading branch information
Showing
3 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\DI\Container::getByType() and findByType() | ||
*/ | ||
|
||
use Nette\DI, | ||
Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class Service extends Nette\Object | ||
{ | ||
} | ||
|
||
class Service2 extends Nette\Object | ||
{ | ||
} | ||
|
||
|
||
$builder = new DI\ContainerBuilder; | ||
$one = $builder->addDefinition('one') | ||
->setClass('Service'); | ||
$two = $builder->addDefinition('two') | ||
->setClass('Service2'); | ||
$three = $builder->addDefinition('three') | ||
->setClass('Service2') | ||
->setAutowired(FALSE); | ||
|
||
$container = createContainer($builder); | ||
|
||
Assert::type( 'Service', $container->getByType('Service') ); | ||
Assert::null( $container->getByType('unknown', FALSE) ); | ||
|
||
Assert::exception(function() use ($container) { | ||
$container->getByType('unknown'); | ||
}, 'Nette\DI\MissingServiceException', 'Service of type unknown not found.'); | ||
|
||
Assert::exception(function() use ($container) { | ||
$container->getByType('Nette\Object'); | ||
}, 'Nette\DI\MissingServiceException', 'Multiple services of type Nette\Object found: one, two, container.'); | ||
|
||
|
||
Assert::same( array('one'), $container->findByType('Service') ); | ||
Assert::same( array('two', 'three'), $container->findByType('Service2') ); | ||
Assert::same( array(), $container->findByType('unknown') ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters