GenerateCestTest.php 3.7 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 tryToTest(HobbitGuy $I)', $this->content);
  23. $this->assertContains('Test was created in tests/shire/HallUnderTheHillCest.php', $this->output);
  24. }
  25. /**
  26. * @group command
  27. */
  28. public function testNamespaced()
  29. {
  30. $this->config['namespace'] = 'Shire';
  31. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
  32. $this->assertContains('namespace Shire;', $this->content);
  33. $this->assertContains('use Shire\HobbitGuy;', $this->content);
  34. $this->assertContains('class HallUnderTheHillCest', $this->content);
  35. }
  36. /**
  37. * @group command
  38. */
  39. public function testGenerateWithFullName()
  40. {
  41. $this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest.php'));
  42. $this->assertEquals('tests/shire/HomeCanInclude12DwarfsCest.php', $this->filename);
  43. }
  44. /**
  45. * @group command
  46. */
  47. public function testGenerateWithSuffix()
  48. {
  49. $this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest'));
  50. $this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCest.php');
  51. $this->assertIsValidPhp($this->content);
  52. }
  53. public function testGenerateWithGuyNamespaced()
  54. {
  55. $this->config['namespace'] = 'MiddleEarth';
  56. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
  57. $this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
  58. $this->assertContains('namespace MiddleEarth;', $this->content);
  59. $this->assertContains('use MiddleEarth\\HobbitGuy;', $this->content);
  60. $this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
  61. $this->assertIsValidPhp($this->content);
  62. }
  63. public function testCreateWithNamespace()
  64. {
  65. $this->execute(array('suite' => 'shire', 'class' => 'MiddleEarth\HallUnderTheHillCest'));
  66. $this->assertEquals('tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->filename);
  67. $this->assertContains('namespace MiddleEarth;', $this->content);
  68. $this->assertContains('class HallUnderTheHillCest', $this->content);
  69. $this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->output);
  70. }
  71. public function testGenerateWithSuiteNamespace()
  72. {
  73. $this->config['suite_namespace'] = 'MiddleEarth\\Bosses\\';
  74. $this->config['namespace'] = 'MiddleEarth';
  75. $this->config['actor'] = 'HobbitGuy';
  76. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
  77. $this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
  78. $this->assertContains('namespace MiddleEarth\\Bosses;', $this->content);
  79. $this->assertContains('use MiddleEarth\\HobbitGuy', $this->content);
  80. $this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
  81. $this->assertIsValidPhp($this->content);
  82. }
  83. }