GenerateTestTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
  3. class GenerateTestTest extends BaseCommandRunner
  4. {
  5. protected function setUp()
  6. {
  7. $this->makeCommand('\Codeception\Command\GenerateTest');
  8. $this->config = array(
  9. 'actor' => 'HobbitGuy',
  10. 'path' => 'tests/shire',
  11. );
  12. }
  13. public function testBasic()
  14. {
  15. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
  16. $this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
  17. $this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
  18. $this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
  19. $this->assertContains('protected function _before()', $this->content);
  20. $this->assertContains('protected function _after()', $this->content);
  21. }
  22. public function testCreateWithSuffix()
  23. {
  24. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillTest'));
  25. $this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
  26. $this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
  27. }
  28. public function testCreateWithNamespace()
  29. {
  30. $this->execute(array('suite' => 'shire', 'class' => 'MiddleEarth\HallUnderTheHillTest'));
  31. $this->assertEquals('tests/shire/MiddleEarth/HallUnderTheHillTest.php', $this->filename);
  32. $this->assertContains('namespace MiddleEarth;', $this->content);
  33. $this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
  34. $this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillTest.php', $this->output);
  35. }
  36. public function testCreateWithExtension()
  37. {
  38. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillTest.php'));
  39. $this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
  40. $this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
  41. $this->assertContains('protected $tester;', $this->content);
  42. $this->assertContains('@var \HobbitGuy', $this->content);
  43. $this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
  44. }
  45. public function testValidPHP()
  46. {
  47. $this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
  48. $this->assertIsValidPhp($this->content);
  49. }
  50. }