-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minification of metadata: added option 'di › export › types' & Compil…
…er::addExportedType()
- Loading branch information
Showing
5 changed files
with
177 additions
and
3 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
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
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,132 @@ | ||
<?php | ||
|
||
/** | ||
* Test: DIExtension types exporting | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\DI; | ||
use Nette\DI\Extensions\DIExtension; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class Foo | ||
{ | ||
} | ||
|
||
|
||
test(function () { | ||
$compiler = new DI\Compiler; | ||
$compiler->addExtension('di', new DIExtension); | ||
$container = createContainer($compiler, ' | ||
di: | ||
export: | ||
types: true | ||
services: | ||
one: | ||
factory: stdClass | ||
autowired: no | ||
second: stdClass | ||
'); | ||
|
||
Assert::same(['second', 'one'], $container->findByType(stdClass::class)); | ||
Assert::same(['second'], $container->findAutowired(stdClass::class)); | ||
}); | ||
|
||
|
||
test(function () { | ||
$compiler = new DI\Compiler; | ||
$compiler->addExtension('di', new DIExtension); | ||
$container = createContainer($compiler, ' | ||
di: | ||
export: | ||
types: false | ||
services: | ||
one: | ||
factory: stdClass | ||
autowired: no | ||
second: stdClass | ||
'); | ||
|
||
Assert::same([], $container->findByType(stdClass::class)); | ||
Assert::same([], $container->findAutowired(stdClass::class)); | ||
}); | ||
|
||
|
||
test(function () { | ||
$compiler = new DI\Compiler; | ||
$compiler->addExtension('di', new DIExtension); | ||
$compiler->addExportedType(stdClass::class); | ||
$container = createContainer($compiler, ' | ||
di: | ||
export: | ||
types: false | ||
services: | ||
one: | ||
factory: stdClass | ||
autowired: no | ||
second: stdClass | ||
'); | ||
|
||
Assert::same(['second', 'one'], $container->findByType(stdClass::class)); | ||
Assert::same(['second'], $container->findAutowired(stdClass::class)); | ||
}); | ||
|
||
|
||
test(function () { | ||
$compiler = new DI\Compiler; | ||
$compiler->addExtension('di', new DIExtension); | ||
$compiler->addExportedType(stdClass::class); | ||
$container = createContainer($compiler, ' | ||
di: | ||
export: | ||
types: | ||
services: | ||
one: | ||
factory: Foo | ||
autowired: no | ||
second: stdClass | ||
'); | ||
|
||
Assert::same([], $container->findByType(Foo::class)); | ||
Assert::same([], $container->findAutowired(Foo::class)); | ||
Assert::same(['second'], $container->findByType(stdClass::class)); | ||
Assert::same(['second'], $container->findAutowired(stdClass::class)); | ||
}); | ||
|
||
|
||
test(function () { | ||
$compiler = new DI\Compiler; | ||
$compiler->addExtension('di', new DIExtension); | ||
$compiler->addExportedType(stdClass::class); | ||
$container = createContainer($compiler, ' | ||
di: | ||
export: | ||
types: | ||
- Foo | ||
services: | ||
one: | ||
factory: Foo | ||
autowired: no | ||
second: stdClass | ||
'); | ||
|
||
Assert::same(['one'], $container->findByType(Foo::class)); | ||
Assert::same([], $container->findAutowired(Foo::class)); | ||
Assert::same(['second'], $container->findByType(stdClass::class)); | ||
Assert::same(['second'], $container->findAutowired(stdClass::class)); | ||
}); |