/**
  * @test
  */
 public function Getting_an_instance_type_always_returns_same_instance()
 {
     // arrange
     $Container = new TestContainer();
     // act
     $Container->registerInstance('NonInjectableClass', NonInjectableClass::newNonInjectableClass());
     $InstanceOne = $Container->NonInjectableClass;
     $InstanceTwo = $Container->NonInjectableClass;
     // assert
     $this->assertSame($InstanceOne, $InstanceTwo);
 }
 /**
  * @test
  */
 public function Can_register_instance_and_get_instance()
 {
     // arrange
     $Container = new TestContainer();
     $expectedInstanceClass = 'MindTouch\\OpenContainer\\test\\InjectableTestClassWithNoDependencies';
     // act
     $Container->registerSharedType('InjectableTestClassWithNoDependencies', $expectedInstanceClass);
     $Instance = $Container->InjectableTestClassWithNoDependencies;
     // assert
     $this->assertInstanceOf($expectedInstanceClass, $Instance);
 }
 /**
  * @test
  */
 public function Can_get_registered_types()
 {
     // arrange
     $Container = new TestContainer();
     $Container->registerType('InjectableTestClassWithNoDependencies', 'MindTouch\\OpenContainer\\test\\InjectableTestClassWithNoDependencies');
     $Container->registerSharedType('InjectableTestClassWithSimpleDependencies', 'MindTouch\\OpenContainer\\test\\InjectableTestClassWithSimpleDependencies');
     $Container->registerInstance('NonInjectableClass', NonInjectableClass::newNonInjectableClass());
     // act
     $types = $Container->getRegisteredTypes();
     // assert
     $this->assertEquals(array('InjectableTestClassWithNoDependencies', 'InjectableTestClassWithSimpleDependencies', 'NonInjectableClass'), $types);
 }
 /**
  * @test
  */
 public function Can_check_if_instances_are_registered()
 {
     // arrange
     $Container = new TestContainer();
     $type = 'NonInjectableClass';
     // act
     $first = $Container->isRegistered($type);
     $Container->registerInstance($type, NonInjectableClass::newNonInjectableClass());
     $second = $Container->isRegistered($type);
     // assert
     $this->assertFalse($first);
     $this->assertTrue($second);
 }
 /**
  * @test
  */
 public function Registered_instance_is_not_recreated_after_flush()
 {
     // arrange
     $Container = new TestContainer();
     $type = 'NonInjectableClass';
     $expectedInstanceClass = 'MindTouch\\OpenContainer\\test\\NonInjectableClass';
     // act
     $Container->registerInstance($type, NonInjectableClass::newNonInjectableClass());
     $FirstInstance = $Container->NonInjectableClass;
     $Container->flush($type);
     $exceptionThrown = false;
     try {
         $Container->NonInjectableClass;
     } catch (NotRegisteredInOpenContainerException $e) {
         $exceptionThrown = true;
     }
     // assert
     $this->assertInstanceOf($expectedInstanceClass, $FirstInstance);
     $this->assertTrue($exceptionThrown);
 }
 /**
  * @test
  */
 public function Can_register_shared_type_with_instance_dependency()
 {
     // arrange
     $Container = new TestContainer();
     $RegisteredInstance = NonInjectableClass::newNonInjectableClass();
     $Container->registerInstance('NonInjectableClass', $RegisteredInstance);
     $expectedInstanceClass = 'MindTouch\\OpenContainer\\test\\InjectableTestClassWithInstanceDependency';
     // act
     $Container->registerSharedType('InjectableTestClassWithInstanceDependency', $expectedInstanceClass);
     $Instance = $Container->InjectableTestClassWithInstanceDependency;
     // assert
     $this->assertInstanceOf($expectedInstanceClass, $Instance);
 }