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

SizeRule::doValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
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