Failed Conditions
Push — master ( 1a6d63...dcbc0d )
by Adrien
05:26
created

assertContentContains()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
4
{
5
    /**
6
     * @var \mQueue\Model\User
7
     */
8
    protected $testUser;
9
    protected $userData = [
10
        'nickname' => 'test user',
11
        'email' => '[email protected]',
12
        'password' => 'superpassword',
13
    ];
14
    protected $movieData = [
15
        'id' => '0096446',
16
        'title' => 'Willow (1988)',
17
    ];
18
19
    public function setUp(): void
20
    {
21
        $this->bootstrap = new Zend_Application(
22
                APPLICATION_ENV, [
23
            'config' => [
24
                APPLICATION_PATH . '/configs/application.ini',
25
            ], ]
26
        );
27
28
        $this->testUser = \mQueue\Model\UserMapper::findEmailPassword($this->userData['email'], $this->userData['password']);
29
        if (!$this->testUser) {
30
            $this->testUser = \mQueue\Model\UserMapper::insertUser($this->userData);
31
        }
32
33
        $movie = \mQueue\Model\MovieMapper::find($this->movieData['id']);
34
        if (!$movie) {
35
            \mQueue\Model\MovieMapper::getDbTable()->createRow($this->movieData)->save();
36
        }
37
38
        parent::setUp();
39
    }
40
41
    public function loginUser($login, $password): void
42
    {
43
        $this->request->setMethod('POST')
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist on AbstractControllerTestCase. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
                ->setPost([
45
                    'login' => $login,
46
                    'password' => $password,
47
        ]);
48
        $this->dispatch('/user/login');
49
50
        $this->resetRequest()
51
                ->resetResponse();
52
53
        $this->request->setPost([]);
54
    }
55
56
    /**
57
     * Assert against plain text search; content should contain needle
58
     *
59
     * @param  string $needle needle that should be contained in content
60
     * @param  string $message
61
     */
62
    public function assertContentContains($needle, $message = ''): void
63
    {
64
        $this->_incrementAssertionCount();
65
        $content = $this->response->outputBody();
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist on AbstractControllerTestCase. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
        if (mb_strpos($content, $needle) === false) {
67
            $failure = sprintf('Failed asserting needle DENOTED BY %s DOES NOT EXIST', $needle);
68
            if (!empty($message)) {
69
                $failure = $message . "\n" . $failure;
70
            }
71
72
            throw new Zend_Test_PHPUnit_Constraint_Exception($failure);
73
        }
74
    }
75
}
76