StringExistsRule::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Html;
4
5
use Psr\Http\Message\ResponseInterface;
6
use whm\Smoke\Rules\StandardRule;
7
8
/**
9
 * This rule will analyze any html document and checks if a given string is contained.
10
 */
11 View Code Duplication
class StringExistsRule extends StandardRule
12
{
13
    private $string;
14
15
    protected $contentTypes = array('text/html');
16
17
    /**
18
     * @param int $string The string that the document must contain
19
     */
20
    public function init($string)
21
    {
22
        $this->string = $string;
23
    }
24
25
    protected function doValidation(ResponseInterface $response)
26
    {
27
        $this->assert(strpos((string)$response->getBody(), $this->string) !== false,
28
            'The given string (' . $this->string . ') was not found in this document.');
29
    }
30
}
31