Passed
Push — master ( 3d4557...4c2a8d )
by Hannes
01:54
created

VoidExpectation::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Expectation;
6
7
use hanneskod\readmetester\Runner\OutcomeInterface;
8
9
/**
10
 * Validate that no error and no output is generated
11
 */
12
final class VoidExpectation implements ExpectationInterface
13
{
14
    public function getDescription(): string
15
    {
16
        return 'expecting that no output and no error is produced';
17
    }
18
19
    public function handles(OutcomeInterface $outcome): bool
20
    {
21
        return true;
22
    }
23
24
    public function handle(OutcomeInterface $outcome): StatusInterface
25
    {
26
        if ($outcome->isOutput()) {
27
            return new Failure($outcome, "Failed asserting nothing, found output: {$outcome->getContent()}");
28
        }
29
30
        if ($outcome->isError()) {
31
            return new Failure($outcome, "Failed asserting nothing, found error: {$outcome->getContent()}");
32
        }
33
34
        return new Success($outcome, 'Asserted that no output and no error is produced');
35
    }
36
}
37