Test Failed
Pull Request — master (#2)
by Laurynas
43:45
created

EntryTest::testSubmitDuplicateEmail()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
3
use Qualia\Client;
4
use Qualia\Exceptions\ConnectionErrorException;
5
use Qualia\Exceptions\EmailExistsException;
6
use Qualia\Exceptions\RequestException;
7
use Qualia\Submission\Entry;
8
9
class EntryTest extends TestCase
10
{
11
12
    public function testInvalidCredentials()
13
    {
14
        self::setExpectedException("\\Qualia\\Exceptions\\RequestException");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
15
16
        Entry::build(new Client('597768e728d8f1508f6d9f62', 'invalid-credentials'))
17
                        ->email('q_tVabQ3cUlwZTgQ10', '[email protected]')
18
                        ->send();
19
20
    }
21
22
    public function testInvalidSurvey()
23
    {
24
        self::setExpectedException("\\Qualia\\Exceptions\\RequestException");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
25
26
        Entry::build(new Client('aaa', 'cT6hCqyxD8MQ0k6gfYwWBt3lIMexpsLQ'))
27
                        ->email('q_tVabQ3cUlwZTgQ10', '[email protected]')
28
                        ->send();
29
30
    }
31
32
    public function testServerError()
33
    {
34
        try {
35
            Entry::build(new Client('aaa', 'cT6hCqyxD8MQ0k6gfYwWBt3lIMexpsLQ', 'api.qualiaanalytics.test'))
36
                 ->email('q_tVabQ3cUlwZTgQ10', '[email protected]')
37
                 ->send();
38
        } catch (ConnectionErrorException $e) {
39
            self::assertTrue(true);
40
        } catch (RequestException $e) {
41
            self::assertFalse(true);
42
        }
43
    }
44
45
    public function testValidationException()
46
    {
47
        try {
48
            Entry::build($this->client)
49
                 ->email('dadad', '[email protected]')
50
                 ->send();
51
        } catch (ConnectionErrorException $e) {
52
            self::assertTrue(false);
53
        } catch (EmailExistsException $e) {
54
            self::assertTrue(false);
55
        } catch (RequestException $e) {
56
            self::assertTrue(true);
57
            self::assertEquals(400, $e->getCode());
58
            self::assertEquals("Invalid Question: dadad", $e->getMessage());
59
        }
60
    }
61
62
    public function testFailsWithoutData()
63
    {
64
        self::setExpectedException("InvalidArgumentException");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
65
66
        Entry::build($this->client)
67
                ->send();
68
    }
69
70
    public function allowsOnlyCorrectDateNotUnixTime()
71
    {
72
        self::setExpectedException("InvalidArgumentException");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
74
        $id = uniqid('', true);
75
76
        Entry::build($this->client)
77
                ->uniqueId($id)
78
                ->date('q_1J75WdyBwVpwlJUM', time())
79
                ->send();
80
    }
81
82
    public function testAllowsOnlyCorrectDate()
83
    {
84
        self::setExpectedException("InvalidArgumentException");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
85
86
        Entry::build($this->client)
87
                ->date('q_1J75WdyBwVpwlJUM', 'invalid')
88
                ->send();
89
    }
90
91
    public function testCreatesEntryWithEmail()
92
    {
93
        $id = uniqid('', true);
94
95
        $response = Entry::build($this->client)
96
                ->uniqueId($id)
97
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
98
                ->send();
99
100
        self::assertEquals('success', $response['message']);
101
        self::assertArrayHasKey('id', $response);
102
    }
103
104
    public function testSingleCheckbox()
105
    {
106
        $id = uniqid('', true);
107
108
        $response = Entry::build($this->client)
109
                            ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
110
                            ->response('q_tVabQ3cUlwZTgQ10', 'o_ACvo61cUuKXxD5C1')
111
                            ->send();
112
113
        self::assertEquals('success', $response['message']);
114
        self::assertArrayHasKey('id', $response);
115
    }
116
117
    public function testSubmitWithLanguage()
118
    {
119
        $response = Entry::build($this->client)
120
                            ->language('en')
121
                            ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
122
                            ->send();
123
124
        self::assertEquals('success', $response['message']);
125
        self::assertArrayHasKey('id', $response);
126
    }
127
128
    public function testSubmitWithInvalidLanguage()
129
    {
130
        $response = Entry::build($this->client)
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
131
                            ->language('xy')
132
                            ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
133
                            ->send();
134
135
        // will allow to submit and sets language as default one
136
    }
137
138
    public function testSubmitDuplicateEmail()
139
    {
140
        $id = uniqid('', true);
141
142
        $response = Entry::build($this->client)
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
143
                            ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
144
                            ->send();
145
146
        // allowDuplicates will allow to submit
147
        $response = Entry::build($this->client)
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
148
                         ->allowDuplicates()
149
                         ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
150
                         ->send();
151
152
        try {
153
            // will throw an exception
154
            $response = Entry::build($this->client)
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
155
                             ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
156
                             ->send();
157
        } catch (EmailExistsException $e) {
158
            self::assertTrue(strlen($e->getEntryId()) > 0);
159
            return;
160
        }
161
162
        self::assertFalse(true, "Exception was not thrown");
163
    }
164
165
    public function testWithAllFields()
166
    {
167
        $id = uniqid('', true);
168
169
        $response = Entry::build($this->client)
170
                ->uniqueId($id)
171
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
172
                ->name('q_KCyzOs7VqevWbEO0', "Unit", "Tester")
173
                ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
174
                ->response('q_KCyzOs7VqevWbEO0', ['o_wCcuY5a54YBeXLC1', 'o_ACvo61cUuKXxD5C1'])
175
                ->send();
176
177
        self::assertEquals('success', $response['message']);
178
        self::assertArrayHasKey('id', $response);
179
    }
180
181
    public function testCreatesEntryWithEmailAndMarksCompleted()
182
    {
183
        $id = uniqid('', true);
184
185
        $response = Entry::build($this->client)
186
                ->uniqueId($id)
187
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
188
                ->send(true);
189
190
        self::assertEquals('success', $response['message']);
191
        self::assertArrayHasKey('id', $response);
192
    }
193
}