GenerateCestTest.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
  3. class GenerateCestTest extends BaseCommandRunner
  4. {
  5. protected function setUp()
  6. {
  7. $this->makeCommand('\Codeception\Command\GenerateCest');
  8. $this->config = array(
  9. 'actor' => 'HobbitGuy',
  10. 'path' => 'tests/shire',
  11. );
  12. }
  13. /**
  14. * @group command
  15. */
  16. public function testBasic()
  17. {
  18. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
  19. $this->assertEquals('tests/shire/HallUnderTheHillCest.php', $this->filename);
  20. $this->assertContains('class HallUnderTheHillCest', $this->content);
  21. $this->assertContains('public function _before(HobbitGuy $I)', $this->content);
  22. $this->assertContains('public function _after(HobbitGuy $I)', $this->content);
  23. $this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
  24. $this->assertContains('Test was created in tests/shire/HallUnderTheHillCest.php', $this->output);
  25. }
  26. /**
  27. * @group command
  28. */
  29. public function testNamespaced()
  30. {
  31. $this->config['namespace'] = 'Shire';
  32. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
  33. $this->assertContains('namespace Shire;', $this->content);
  34. $this->assertContains('use Shire\HobbitGuy;', $this->content);
  35. $this->assertContains('class HallUnderTheHillCest', $this->content);
  36. }
  37. /**
  38. * @group command
  39. */
  40. public function testGenerateWithFullName()
  41. {
  42. $this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest.php'));
  43. $this->assertEquals('tests/shire/HomeCanInclude12DwarfsCest.php', $this->filename);
  44. }
  45. /**
  46. * @group command
  47. */
  48. public function testGenerateWithSuffix()
  49. {
  50. $this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest'));
  51. $this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCest.php');
  52. $this->assertIsValidPhp($this->content);
  53. }
  54. public function testGenerateWithGuyNamespaced()
  55. {
  56. $this->config['namespace'] = 'MiddleEarth';
  57. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
  58. $this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
  59. $this->assertContains('namespace MiddleEarth;', $this->content);
  60. $this->assertContains('use MiddleEarth\\HobbitGuy;', $this->content);
  61. $this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
  62. $this->assertIsValidPhp($this->content);
  63. }
  64. public function testCreateWithNamespace()
  65. {
  66. $this->execute(array('suite' => 'shire', 'class' => 'MiddleEarth\HallUnderTheHillCest'));
  67. $this->assertEquals('tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->filename);
  68. $this->assertContains('namespace MiddleEarth;', $this->content);
  69. $this->assertContains('class HallUnderTheHillCest', $this->content);
  70. $this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->output);
  71. }
  72. public function testGenerateWithSuiteNamespace()
  73. {
  74. $this->config['suite_namespace'] = 'MiddleEarth\\Bosses\\';
  75. $this->config['namespace'] = 'MiddleEarth';
  76. $this->config['actor'] = 'HobbitGuy';
  77. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
  78. $this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
  79. $this->assertContains('namespace MiddleEarth\\Bosses;', $this->content);
  80. $this->assertContains('use MiddleEarth\\HobbitGuy', $this->content);
  81. $this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
  82. $this->assertIsValidPhp($this->content);
  83. }
  84. }