|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Nette\ComponentModel\Container suggestions. |
| 5 | + */ |
| 6 | + |
| 7 | +use Nette\ComponentModel\Container; |
| 8 | +use Tester\Assert; |
| 9 | + |
| 10 | + |
| 11 | +require __DIR__ . '/../bootstrap.php'; |
| 12 | + |
| 13 | + |
| 14 | +class TestContainer extends Container |
| 15 | +{ |
| 16 | + |
| 17 | + public function createComponentPublic() |
| 18 | + { |
| 19 | + } |
| 20 | + |
| 21 | + public static function createComponentPublicStatic() |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + protected function createComponentProtected() |
| 26 | + { |
| 27 | + } |
| 28 | + |
| 29 | + private function createComponentPrivate() |
| 30 | + { |
| 31 | + } |
| 32 | + |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +$cont = new TestContainer; |
| 37 | +$cont->addComponent(new TestContainer, 'form'); |
| 38 | + |
| 39 | +Assert::exception(function () use ($cont) { |
| 40 | + $comp = $cont->getComponent('from'); |
| 41 | +}, 'Nette\InvalidArgumentException', "Component with name 'from' does not exist, did you mean 'form'?"); |
| 42 | + |
| 43 | +Assert::exception(function () use ($cont) { |
| 44 | + $comp = $cont->getComponent('Public'); |
| 45 | +}, 'Nette\InvalidArgumentException', "Component with name 'Public' does not exist, did you mean 'public'?"); |
| 46 | + |
| 47 | +Assert::exception(function () use ($cont) { |
| 48 | + $comp = $cont->getComponent('PublicStatic'); |
| 49 | +}, 'Nette\InvalidArgumentException', "Component with name 'PublicStatic' does not exist, did you mean 'publicStatic'?"); |
| 50 | + |
| 51 | +Assert::exception(function () use ($cont) { |
| 52 | + $comp = $cont->getComponent('Protected'); |
| 53 | +}, 'Nette\InvalidArgumentException', "Component with name 'Protected' does not exist, did you mean 'protected'?"); |
| 54 | + |
| 55 | +Assert::exception(function () use ($cont) { // suggest only non-private methods |
| 56 | + $comp = $cont->getComponent('Private'); |
| 57 | +}, 'Nette\InvalidArgumentException', "Component with name 'Private' does not exist."); |
0 commit comments