Completed
Branch master (1f9106)
by Nils
03:23
created

SizeRule::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Html;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\StandardRule;
7
8
/**
9
 * This rule calculates the size of a html document. If the document is bigger than a given value
10
 * the test will fail.
11
 */
12 View Code Duplication
class SizeRule extends StandardRule
13
{
14
    private $maxSize;
15
16
    protected $contentTypes = array('text/html');
17
18
    /**
19
     * @param int $maxSize The maximum size of a html file in kilobytes.
20
     */
21
    public function init($maxSize = 200)
22
    {
23
        $this->maxSize = $maxSize;
24
    }
25
26
    protected function doValidation(Response $response)
27
    {
28
        $size = strlen($response->getBody()) / 1000;
29
        $this->assert($size <= $this->maxSize, 'The size of this html file is too big (' . $size . ' KB)');
30
    }
31
}
32