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

HttpStatusRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 3
c 3
b 2
f 0
lcom 1
cbo 2
dl 0
loc 19
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A validate() 0 6 2
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