Repository navigation
Expand file tree
/
Copy pathCept.php
More file actions
101 lines (83 loc) · 2.6 KB
/
Copy pathCept.php
File metadata and controls
101 lines (83 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace Codeception\TestCase;
use Codeception\Events;
use Codeception\Event\TestEvent;
use Codeception\Parser;
use Codeception\Scenario;
use Codeception\Step;
use Codeception\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
class Cept extends TestCase implements ScenarioDriven
{
private $name;
protected $testFile = null;
protected $output;
protected $debug;
protected $features = array();
protected $bootstrap = null;
protected $stopped = false;
protected $parser;
public function __construct(EventDispatcher $dispatcher, array $data = array(), $dataName = '')
{
parent::__construct('testCodecept', $data, $dataName);
$this->dispatcher = $dispatcher;
if (! isset($data['file'])) {
throw new \Exception('File with test scenario not set. Use array(file => filepath) to set a scenario');
}
$this->name = $data['name'];
$this->testFile = $data['file'];
$this->scenario = new Scenario($this);
$this->parser = new Parser($this->scenario);
if (isset($data['bootstrap']) && file_exists($data['bootstrap'])) {
$this->bootstrap = $data['bootstrap'];
}
}
public function getFileName()
{
return $this->name;
}
public function getName($withDataSet = true)
{
return $this->name;
}
public function getScenarioText($format = 'text')
{
$code = $this->getRawBody();
$this->parser->parseFeature($code);
$this->parser->parseSteps($code);
if ($format == 'html') {
return $this->scenario->getHtml();
}
return $this->scenario->getText();
}
public function getFeature()
{
return $this->scenario->getFeature();
}
public function toString()
{
return $this->scenario->getFeature() . ' (' . $this->getFileName() . ')';
}
public function preload()
{
$this->parser->prepareToRun($this->getRawBody());
$this->fire(Events::TEST_PARSED, new TestEvent($this));
}
public function getRawBody()
{
return file_get_contents($this->testFile);
}
public function testCodecept()
{
$this->fire(Events::TEST_BEFORE, new TestEvent($this));
$scenario = $this->scenario;
$scenario->run();
if ($this->bootstrap) {
/** @noinspection PhpIncludeInspection */
require $this->bootstrap;
}
/** @noinspection PhpIncludeInspection */
require $this->testFile;
$this->fire(Events::TEST_AFTER, new TestEvent($this));
}
}