DiTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Codeception\Lib;
  3. class DiTest extends \Codeception\Test\Unit
  4. {
  5. /**
  6. * @var Di
  7. */
  8. protected $di;
  9. protected function setUp()
  10. {
  11. $this->di = new Di();
  12. }
  13. protected function injectionShouldFail($msg = '')
  14. {
  15. $this->setExpectedException('Codeception\Exception\InjectionException', $msg);
  16. }
  17. public function testFailDependenciesCyclic()
  18. {
  19. require_once codecept_data_dir().'FailDependenciesCyclic.php';
  20. $this->injectionShouldFail(
  21. 'Failed to resolve cyclic dependencies for class \'FailDependenciesCyclic\IncorrectDependenciesClass\''
  22. );
  23. $this->di->instantiate('FailDependenciesCyclic\IncorrectDependenciesClass');
  24. }
  25. public function testFailDependenciesInChain()
  26. {
  27. require_once codecept_data_dir().'FailDependenciesInChain.php';
  28. $this->injectionShouldFail('Failed to resolve dependency \'FailDependenciesInChain\AnotherClass\'');
  29. $this->di->instantiate('FailDependenciesInChain\IncorrectDependenciesClass');
  30. }
  31. public function testFailDependenciesNonExistent()
  32. {
  33. require_once codecept_data_dir().'FailDependenciesNonExistent.php';
  34. $this->injectionShouldFail('Class FailDependenciesNonExistent\NonExistentClass does not exist');
  35. $this->di->instantiate('FailDependenciesNonExistent\IncorrectDependenciesClass');
  36. }
  37. public function testFailDependenciesPrimitiveParam()
  38. {
  39. require_once codecept_data_dir().'FailDependenciesPrimitiveParam.php';
  40. $this->injectionShouldFail('Parameter \'required\' must have default value');
  41. $this->di->instantiate('FailDependenciesPrimitiveParam\IncorrectDependenciesClass');
  42. }
  43. }