pastebin

Paste Search Dynamic
Recent pastes
Container static
  1. <?php
  2.  
  3. /**
  4.  * Test: NetteDIContainer static usage.
  5.  *
  6.  * @author     David Grudl
  7.  * @package    NetteDI
  8.  * @subpackage UnitTests
  9.  */
  10.  
  11. use NetteDIContainer;
  12.  
  13.  
  14.  
  15. require __DIR__ . '/../bootstrap.php';
  16.  
  17.  
  18.  
  19. class MyContainer extends Container
  20. {
  21.  
  22.         protected function createServiceOne()
  23.         {
  24.                 return new stdClass;
  25.         }
  26.  
  27.         protected function createServiceTwo()
  28.         {
  29.         }
  30.  
  31. }
  32.  
  33.  
  34.  
  35. $container = new MyContainer;
  36.  
  37. assert::true( $container->hasService('one') );
  38. assert::false( $container->hasService('undefined') );
  39.  
  40. assert::true( $container->getService('one') instanceof stdClass );
  41. assert::same( $container->getService('one'), $container->getService('one') ); // shared
  42.  
  43.  
  44. // bad method
  45. assert::throws(function() use ($container) {
  46.         $container->getService('two');
  47. }, 'NetteUnexpectedValueException', "Unable to create service 'two', value returned by factory 'createServiceTwo' is not object.");
Parsed in 0.056 seconds