1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace spec\hanneskod\readmetester\Runner; |
6
|
|
|
|
7
|
|
|
use hanneskod\readmetester\Runner\RunnerInterface; |
8
|
|
|
use hanneskod\readmetester\Runner\ErrorOutcome; |
9
|
|
|
use hanneskod\readmetester\Runner\OutputOutcome; |
10
|
|
|
use hanneskod\readmetester\Runner\VoidOutcome; |
11
|
|
|
use hanneskod\readmetester\Utils\CodeBlock; |
12
|
|
|
|
13
|
|
|
trait RunnerSpecTrait |
14
|
|
|
{ |
15
|
|
|
function it_is_a_runner() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->shouldHaveType(RunnerInterface::CLASS); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function it_returns_void_on_no_outcome() |
21
|
|
|
{ |
22
|
|
|
$this->run(new CodeBlock('$a = 1 + 2;'))->shouldHaveType(VoidOutcome::CLASS); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function it_returns_output() |
26
|
|
|
{ |
27
|
|
|
$this->run(new CodeBlock('echo "foo";'))->shouldBeLike(new OutputOutcome('foo')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_returns_error_on_exception() |
31
|
|
|
{ |
32
|
|
|
$this->run(new CodeBlock('throw new Exception;'))->shouldHaveType(ErrorOutcome::CLASS); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_returns_error_on_trigger_error() |
36
|
|
|
{ |
37
|
|
|
$this->run(new CodeBlock('trigger_error("ERROR");'))->shouldHaveType(ErrorOutcome::CLASS); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_returns_error_on_fatal_error() |
41
|
|
|
{ |
42
|
|
|
$this->run(new CodeBlock('this_function_does_not_exist();'))->shouldHaveType(ErrorOutcome::CLASS); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_can_be_namespaced() |
46
|
|
|
{ |
47
|
|
|
$this->run(new CodeBlock('namespace test;'))->shouldHaveType(VoidOutcome::CLASS); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function it_throws_on_invalid_bootstrap() |
51
|
|
|
{ |
52
|
|
|
$this->beConstructedWith('this-filename-does-not-exist'); |
|
|
|
|
53
|
|
|
$this->shouldThrow(\RuntimeException::CLASS)->duringInstantiation(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_can_be_bootstraped() |
57
|
|
|
{ |
58
|
|
|
$this->beConstructedWith(__DIR__ . '/Bootstrap.php'); |
59
|
|
|
$this->run(new CodeBlock('new Bootstrap;'))->shouldHaveType(VoidOutcome::CLASS); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.