CliHelper.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Codeception\Module;
  3. // here you can define custom functions for CliGuy
  4. class CliHelper extends \Codeception\Module
  5. {
  6. public function _beforeSuite($settings = [])
  7. {
  8. $this->debug('Building actor classes for claypit');
  9. $this->getModule('Cli')->runShellCommand('php ' . codecept_root_dir() . 'codecept build -c ' . codecept_data_dir() . 'claypit');
  10. }
  11. public function _before(\Codeception\TestInterface $test)
  12. {
  13. codecept_debug('creating dirs');
  14. $this->getModule('Filesystem')->copyDir(codecept_data_dir() . 'claypit', codecept_data_dir() . 'sandbox');
  15. }
  16. public function _after(\Codeception\TestInterface $test)
  17. {
  18. codecept_debug('deleting dirs');
  19. $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox');
  20. chdir(\Codeception\Configuration::projectDir());
  21. }
  22. public function executeCommand($command, $fail = true, $phpOptions = '')
  23. {
  24. $this->getModule('Cli')->runShellCommand('php ' . $phpOptions . ' ' . \Codeception\Configuration::projectDir() . 'codecept ' . $command . ' -n', $fail);
  25. }
  26. public function executeFailCommand($command)
  27. {
  28. $this->getModule('Cli')->runShellCommand('php '.\Codeception\Configuration::projectDir().'codecept '.$command.' -n', false);
  29. }
  30. public function grabFromOutput($regex)
  31. {
  32. $match = [];
  33. $found = preg_match($regex, $this->getModule('Cli')->output, $match);
  34. if (!$found) {
  35. return '';
  36. }
  37. return $match[1];
  38. }
  39. public function seeDirFound($dir)
  40. {
  41. $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist");
  42. }
  43. }