Completed
Push — master ( 1b1986...a19125 )
by Nils
03:49
created

HttpStatusRule::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Http\Header;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\Rule;
7
use whm\Smoke\Rules\ValidationFailedException;
8
9
/**
10
 * This class validates, whether the response has a specific status.
11
 * Can be used to test, if your homepage has a 200 status or your error page sends a 404.
12
 */
13
class HttpStatusRule implements Rule
14
{
15
    protected $expectedStatus = 200;
16
17
    /**
18
     * @param int $expectedStatus The expected HTTP-status
19
     */
20
    public function init($expectedStatus = 200)
21
    {
22
        $this->expectedStatus = $expectedStatus;
23
    }
24
25
    public function validate(Response $response)
26
    {
27
        if ($response->getStatus() !== $this->expectedStatus) {
28
            throw new ValidationFailedException('Status code ' . $response->getStatus() . ' found, ' . $this->expectedStatus . ' expected.');
29
        }
30
    }
31
}
32