pastebin

Paste Search Dynamic
Recent pastes
Container cloning
  1. <?php
  2.  
  3. /**
  4.  * Test: NetteDIContainer cloning.
  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 Service
  20. {
  21. }
  22.  
  23. $service = new Service;
  24.  
  25.  
  26. $container = new Container;
  27. $container->addService('one', $service);
  28. $container->addService('two', 'Service');
  29. $container->addService('three', function($container){
  30.         return new Service;
  31. });
  32.  
  33. $dolly = clone $container;
  34.  
  35. assert::same( $dolly->getService('one'), $container->getService('one') );
  36. assert::same( $dolly->getService('two'), $container->getService('two') );
  37. assert::same( $dolly->getService('three'), $container->getService('three') );
  38.  
  39.  
  40. $container->addService('oneX', $service);
  41. $container->addService('twoX', 'Service');
  42. $container->addService('threeX', function($container){
  43.         return new Service;
  44. });
  45.  
  46. assert::false( $dolly->hasService('oneX') );
  47. assert::false( $dolly->hasService('twoX') );
  48. assert::false( $dolly->hasService('threeX') );
Parsed in 0.065 seconds