-
-
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.
added support for first-class callable syntax in NEON
- Loading branch information
Showing
4 changed files
with
111 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\DI; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class Service | ||
{ | ||
public $cb; | ||
|
||
|
||
public function __construct($cb) | ||
{ | ||
$this->cb = $cb; | ||
} | ||
|
||
|
||
public function foo() | ||
{ | ||
} | ||
} | ||
|
||
|
||
test('Valid callables', function () { | ||
$config = ' | ||
services: | ||
- Service( Service::foo(...), @a::foo(...), ::trim(...) ) | ||
a: stdClass | ||
'; | ||
$loader = new DI\Config\Loader; | ||
$compiler = new DI\Compiler; | ||
$compiler->addConfig($loader->load(Tester\FileMock::create($config, 'neon'))); | ||
$code = $compiler->compile(); | ||
|
||
Assert::contains('new Service(Service::foo(...), $this->getService(\'a\')->foo(...), trim(...));', $code); | ||
}); | ||
|
||
|
||
// Invalid callable 1 | ||
Assert::exception(function () { | ||
$config = ' | ||
services: | ||
- Service(...) | ||
'; | ||
$loader = new DI\Config\Loader; | ||
$compiler = new DI\Compiler; | ||
$compiler->addConfig($loader->load(Tester\FileMock::create($config, 'neon'))); | ||
$compiler->compile(); | ||
}, Nette\DI\ServiceCreationException::class, 'Service of type Closure: Cannot create closure for Service(...)'); | ||
|
||
|
||
// Invalid callable 2 | ||
Assert::exception(function () { | ||
$config = ' | ||
services: | ||
- Service( Service(...) ) | ||
'; | ||
$loader = new DI\Config\Loader; | ||
$compiler = new DI\Compiler; | ||
$compiler->addConfig($loader->load(Tester\FileMock::create($config, 'neon'))); | ||
$compiler->compile(); | ||
}, Nette\DI\ServiceCreationException::class, 'Service of type Service: Cannot create closure for Service(...) (used in Service::__construct())'); |
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