Actor.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Codeception;
  3. use Codeception\Lib\Actor\Shared\Comment;
  4. use Codeception\Lib\Actor\Shared\Friend;
  5. use Codeception\Step\Executor;
  6. abstract class Actor
  7. {
  8. use Comment;
  9. use Friend;
  10. /**
  11. * @var \Codeception\Scenario
  12. */
  13. protected $scenario;
  14. public function __construct(Scenario $scenario)
  15. {
  16. $this->scenario = $scenario;
  17. }
  18. /**
  19. * @return \Codeception\Scenario
  20. */
  21. protected function getScenario()
  22. {
  23. return $this->scenario;
  24. }
  25. public function wantToTest($text)
  26. {
  27. $this->wantTo('test ' . $text);
  28. }
  29. public function wantTo($text)
  30. {
  31. $this->scenario->setFeature($text);
  32. }
  33. public function __call($method, $arguments)
  34. {
  35. $class = get_class($this);
  36. throw new \RuntimeException("Call to undefined method $class::$method");
  37. }
  38. /**
  39. * Lazy-execution given anonymous function
  40. * @param $callable \Closure
  41. * @return $this
  42. */
  43. public function execute($callable)
  44. {
  45. $this->scenario->addStep(new Executor($callable, []));
  46. $callable();
  47. return $this;
  48. }
  49. }