Completed
Push — master ( cd6ca3...800f7e )
by Florin
02:35
created

main_test::updateMessages_data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace florinp\messenger\tests\controller;
4
5
use Symfony\Component\HttpFoundation\JsonResponse;
6
7
class main_test extends \phpbb_test_case {
8
9
    /**
10
     * @var \florinp\messenger\controller\main
11
     */
12
    protected $controller;
13
14
    public function setUp() {
15
        parent::setUp();
16
        /**
17
         * @var \phpbb\user $user Mock the user class
18
         */
19
        $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
20
21
        /**
22
         * @var \phpbb\request\request $request
23
         */
24
        $request = $this->getMockBuilder('\phpbb\request\request')
25
            ->disableOriginalConstructor()
26
            ->getMock();
27
28
        /**
29
         * @var \florinp\messenger\models\main_model $model
30
         */
31
        $model = $this->getMockBuilder('\florinp\messenger\models\main_model')
32
            ->disableOriginalConstructor()
33
            ->getMock();
34
35
        /**
36
         * @var \phpbb\notification\manager $notification_manager
37
         */
38
        $notification_manager = $this->getMockBuilder('\phpbb\notification\manager')
39
            ->disableOriginalConstructor()
40
            ->getMock();
41
42
        /**
43
         * @var \florinp\messenger\libs\emojione $emojione
44
         */
45
        $emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione')
46
            ->disableOriginalConstructor()
47
            ->getMock();
48
49
        /**
50
         * @var \florinp\messenger\libs\upload $upload
51
         */
52
        $upload = $this->getMockBuilder('\florinp\messenger\libs\upload')
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
56
        /**
57
         * @var \florinp\messenger\libs\download $download
58
         */
59
        $download = $this->getMockBuilder('\florinp\messenger\libs\download')
60
            ->disableOriginalConstructor()
61
            ->getMock();
62
63
        $this->controller = new \florinp\messenger\controller\main(
64
            $request,
65
            $user,
66
            $model,
67
            $notification_manager,
68
            $emojione,
69
            $upload,
0 ignored issues
show
Documentation introduced by
$upload is of type object<florinp\messenger\libs\upload>, but the function expects a object<florinp\messenger\libs\download>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
            $download
0 ignored issues
show
Unused Code introduced by
The call to main::__construct() has too many arguments starting with $download.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
71
        );
72
    }
73
74
    public function tearDown() {
75
        $this->controller = null;
76
        parent::tearDown();
77
    }
78
79
    public function publish_data() {
80
        return array(
81
            array(200, json_encode(array()))
82
        );
83
    }
84
    /**
85
     * @dataProvider publish_data
86
     */
87 View Code Duplication
    public function test_publish($status_code, $page_content) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
        $response = $this->controller->publish();
89
        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
90
        $this->assertEquals($status_code, $response->getStatusCode());
91
        $this->assertEquals($page_content, $response->getContent());
92
    }
93
94
95
    public function load_data() {
96
        return array(
97
            array(200, json_encode(array(
98
                'success' => false,
99
                'error' => 'The request is invalid'
100
            )))
101
        );
102
    }
103
    /**
104
     * @dataProvider load_data
105
     */
106 View Code Duplication
    public function test_load($status_code, $page_content) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
        $response = $this->controller->load();
108
        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
109
        $this->assertEquals($status_code, $response->getStatusCode());
110
        $this->assertEquals($page_content, $response->getContent());
111
    }
112
113
114
    public function updateMessages_data() {
115
        return array(
116
            array(200, json_encode(array('success' => false)))
117
        );
118
    }
119
}