1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\hanneskod\readmetester\Expectation; |
6
|
|
|
|
7
|
|
|
use hanneskod\readmetester\Expectation\OutputExpectation; |
8
|
|
|
use hanneskod\readmetester\Expectation\ExpectationInterface; |
9
|
|
|
use hanneskod\readmetester\Expectation\Failure; |
10
|
|
|
use hanneskod\readmetester\Expectation\Success; |
11
|
|
|
use hanneskod\readmetester\Runner\OutcomeInterface; |
12
|
|
|
use hanneskod\readmetester\Utils\Regexp; |
13
|
|
|
use PhpSpec\ObjectBehavior; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
|
16
|
|
|
class OutputExpectationSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
function let(Regexp $regexp) |
19
|
|
|
{ |
20
|
|
|
$this->beConstructedWith($regexp); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_is_initializable() |
24
|
|
|
{ |
25
|
|
|
$this->shouldHaveType(OutputExpectation::class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_an_expectation() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType(ExpectationInterface::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_can_be_converted_to_string($regexp) |
34
|
|
|
{ |
35
|
|
|
$regexp->getRegexp()->willReturn('foobar')->shouldBeCalled(); |
36
|
|
|
$this->getDescription(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_handles_outputs(OutcomeInterface $outcome) |
40
|
|
|
{ |
41
|
|
|
$outcome->isOutput()->willReturn(true); |
42
|
|
|
$this->handles($outcome)->shouldReturn(true); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_does_not_handle_other_outcomes(OutcomeInterface $outcome) |
46
|
|
|
{ |
47
|
|
|
$outcome->isOutput()->willReturn(false); |
48
|
|
|
$this->handles($outcome)->shouldReturn(false); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_returns_failure_on_no_match($regexp, OutcomeInterface $outcome) |
52
|
|
|
{ |
53
|
|
|
$outcome->getContent()->willReturn('foobar'); |
54
|
|
|
$regexp->matches('foobar')->willReturn(false); |
55
|
|
|
$regexp->getRegexp()->willReturn(''); |
56
|
|
|
$this->handle($outcome)->shouldHaveType(Failure::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_returns_success_on_match($regexp, OutcomeInterface $outcome) |
60
|
|
|
{ |
61
|
|
|
$outcome->getContent()->willReturn('foobar'); |
62
|
|
|
$regexp->matches('foobar')->willReturn(true); |
63
|
|
|
$regexp->getRegexp()->willReturn(''); |
64
|
|
|
$this->handle($outcome)->shouldHaveType(Success::class); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|