Passed
Push — master ( 89c3b6...d17ebf )
by Laurynas
44:39
created

EntryTest::testFailsWithoutData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
use Qualia\Client;
4
use Qualia\Exceptions\RequestException;
5
use Qualia\Submission\Entry;
6
7
class EntryTest extends TestCase
8
{
9
10
    public function testInvalidCredentials()
11
    {
12
        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...
13
14
        Entry::build(new Client('597768e728d8f1508f6d9f62', 'invalid-credentials'))
15
                        ->email('q_tVabQ3cUlwZTgQ10', '[email protected]')
16
                        ->send();
17
18
    }
19
20
    public function testFailsWithoutData()
21
    {
22
        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...
23
24
        Entry::build($this->client)
25
                ->send();
26
    }
27
28
    public function allowsOnlyCorrectDateNotUnixTime()
29
    {
30
        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...
31
32
        $id = uniqid('', true);
33
34
        Entry::build($this->client)
35
                ->uniqueId($id)
36
                ->date('q_1J75WdyBwVpwlJUM', time())
37
                ->send();
38
    }
39
40
    public function testAllowsOnlyCorrectDate()
41
    {
42
        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...
43
44
        Entry::build($this->client)
45
                ->date('q_1J75WdyBwVpwlJUM', 'invalid')
46
                ->send();
47
    }
48
49
    public function testCreatesEntryWithEmail()
50
    {
51
        $id = uniqid('', true);
52
53
        $response = Entry::build($this->client)
54
                ->uniqueId($id)
55
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
56
                ->send();
57
58
        self::assertEquals('success', $response['message']);
59
        self::assertArrayHasKey('id', $response);
60
    }
61
62
    public function testSingleCheckbox()
63
    {
64
        $id = uniqid('', true);
65
66
        $response = Entry::build($this->client)
67
                            ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
68
                            ->response('q_tVabQ3cUlwZTgQ10', 'o_ACvo61cUuKXxD5C1')
69
                            ->send();
70
71
        self::assertEquals('success', $response['message']);
72
        self::assertArrayHasKey('id', $response);
73
    }
74
75
    public function testSubmitWithLanguage()
76
    {
77
        $response = Entry::build($this->client)
78
                            ->language('en')
79
                            ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
80
                            ->send();
81
82
        self::assertEquals('success', $response['message']);
83
        self::assertArrayHasKey('id', $response);
84
    }
85
86
    public function testSubmitWithInvalidLanguage()
87
    {
88
        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...
89
90
        $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...
91
                            ->language('xy')
92
                            ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
93
                            ->send();
94
    }
95
96
    public function testWithAllFields()
97
    {
98
        $id = uniqid('', true);
99
100
        $response = Entry::build($this->client)
101
                ->uniqueId($id)
102
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
103
                ->name('q_KCyzOs7VqevWbEO0', "Unit", "Tester")
104
                ->date('q_1J75WdyBwVpwlJUM', date('Y-m-d'))
105
                ->response('q_KCyzOs7VqevWbEO0', ['o_wCcuY5a54YBeXLC1', 'o_ACvo61cUuKXxD5C1'])
106
                ->send();
107
108
        self::assertEquals('success', $response['message']);
109
        self::assertArrayHasKey('id', $response);
110
    }
111
112
    public function testCreatesEntryWithEmailAndMarksCompleted()
113
    {
114
        $id = uniqid('', true);
115
116
        $response = Entry::build($this->client)
117
                ->uniqueId($id)
118
                ->email('q_3RYJ4MpggyMFuU50', $id."[email protected]")
119
                ->send(true);
120
121
        self::assertEquals('success', $response['message']);
122
        self::assertArrayHasKey('id', $response);
123
    }
124
}