PageRenderTime 50ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/test/data/providers/phpObject.php

https://github.com/Hywan/atoum
PHP | 76 lines | 69 code | 7 blank | 0 comment | 0 complexity | e0f0d0c767ca0d7f8fd55067e4422026 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\test\data\providers;
  3. use mageekguy\atoum;
  4. require_once __DIR__ . '/../../../runner.php';
  5. class dummy
  6. {
  7. private function __construct()
  8. {
  9. }
  10. }
  11. class phpObject extends atoum\test
  12. {
  13. public function testClass()
  14. {
  15. $this
  16. ->testedClass->implements(atoum\test\data\provider::class);
  17. }
  18. public function testGenerate()
  19. {
  20. $this
  21. ->given($this->newTestedInstance)
  22. ->then
  23. ->exception(function () {
  24. $this->testedInstance->generate();
  25. })
  26. ->isInstanceOf(atoum\exceptions\logic::class)
  27. ->hasMessage('Class is undefined')
  28. ->given($class = 'stdClass')
  29. ->if($this->testedInstance->setClass($class))
  30. ->then
  31. ->object($this->testedInstance->generate())->isInstanceOf($class)
  32. ->assert('Fail to instanciate an object from a class with mandatory arguments')
  33. ->given($class = 'splFileObject')
  34. ->if($this->testedInstance->setClass($class))
  35. ->then
  36. ->exception(function () {
  37. $this->testedInstance->generate();
  38. })
  39. ->isInstanceOf(atoum\exceptions\runtime::class)
  40. ->hasMessage('Could not instanciate an object from ' . $class . ' because ' . $class . '::__construct() has at least one mandatory argument')
  41. ->assert('Fail to instanciate an object from a class with a private constructor')
  42. ->given($class = __NAMESPACE__ . '\\dummy')
  43. ->if($this->testedInstance->setClass($class))
  44. ->then
  45. ->exception(function () {
  46. $this->testedInstance->generate();
  47. })
  48. ->isInstanceOf(atoum\exceptions\runtime::class)
  49. ->hasMessage('Could not instanciate an object from ' . $class . ' because ' . $class . '::__construct() is private')
  50. ;
  51. }
  52. public function testGetSetClass()
  53. {
  54. $this
  55. ->given($this->newTestedInstance)
  56. ->then
  57. ->variable($this->testedInstance->getClass())->isNull
  58. ->exception(function () {
  59. $this->testedInstance->setClass(uniqid());
  60. })
  61. ->isInstanceOf(atoum\exceptions\logic\invalidArgument::class)
  62. ->hasMessage('Argument must be a class name')
  63. ->given($class = 'stdClass')
  64. ->then
  65. ->object($this->testedInstance->setClass($class))->istestedInstance
  66. ->string($this->testedInstance->getClass())->isEqualTo($class)
  67. ;
  68. }
  69. }