Test Failed
Branch master (8efd2a)
by Ridvan Lakas ng Bayan
05:20 queued 02:59
created

SendSmsTest::testSendViaChikkaFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
use ridvanbaluyos\sms\SmsProviderServicesInterface as SmsProviderServicesInterface;
3
use ridvanbaluyos\sms\Sms as Sms;
4
use ridvanbaluyos\sms\providers\PromoTexter as PromoTexter;
5
use ridvanbaluyos\sms\providers\RisingTide as RisingTide;
6
use ridvanbaluyos\sms\providers\Semaphore as Semaphore;
7
use ridvanbaluyos\sms\providers\Chikka as Chikka;
8
use ridvanbaluyos\sms\providers\Nexmo as Nexmo;
9
use ridvanbaluyos\sms\providers\Twilio as Twilio;
10
11
class SendSmsTest extends \Codeception\Test\Unit
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
    /**
14
     * @var \UnitTester
15
     */
16
    protected $tester;
17
    protected $phoneNumber = '639989764990';
18
    protected $message = 'Unit Testing for SendSmsTest';
19
20
    protected function _before()
21
    {
22
    }
23
24
    protected function _after()
25
    {
26
    }
27
28 View Code Duplication
    protected function sendSuccess(SmsProviderServicesInterface $provider)
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...
29
    {
30
        $sms = new Sms($provider);
31
//        if ($sms->getSmsProviderName() != 'Chikka') return;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
33
        $response = $sms->send($this->phoneNumber, $this->message);
34
35
        $this->assertJson($response);
36
        $response = json_decode($response, true);
37
38
        $this->assertArrayHasKey('data', $response);
39
        $this->assertArrayHasKey('code', $response['data']);
40
        $this->assertArrayHasKey('message', $response['data']);
41
        $this->assertArrayHasKey('provider', $response['data']);
42
        $this->assertArrayHasKey('metadata', $response['data']);
43
44
        $this->assertTrue(is_int($response['data']['code']));
45
        $this->assertEquals($sms->getSmsProviderName(), $response['data']['provider']);
46
        $this->assertLessThanOrEqual(299, $response['data']['code']);
47
        $this->assertGreaterThanOrEqual(200, $response['data']['code']);
48
        $this->assertNotEmpty($response['data']['metadata']);
49
    }
50
51 View Code Duplication
    protected function sendFail(SmsProviderServicesInterface $provider)
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...
52
    {
53
        $sms = new Sms($provider);
54
//        if ($sms->getSmsProviderName() != 'Chikka') return;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
56
        $response = $sms->send($this->phoneNumber, $this->message);
57
58
        $this->assertJson($response);
59
        $response = json_decode($response, true);
60
61
        $this->assertArrayHasKey('error', $response);
62
        $this->assertArrayHasKey('code', $response['error']);
63
        $this->assertArrayHasKey('message', $response['error']);
64
        $this->assertArrayHasKey('provider', $response['error']);
65
        $this->assertArrayHasKey('metadata', $response['error']);
66
67
        $this->assertTrue(is_int($response['error']['code']));
68
        $this->assertEquals($sms->getSmsProviderName(), $response['error']['provider']);
69
        $this->assertLessThanOrEqual(599, $response['error']['code']);
70
        $this->assertGreaterThanOrEqual(400, $response['error']['code']);
71
        $this->assertNotEmpty($response['error']['metadata']);
72
    }
73
74
    // Send via PromoTexter Success
75
    public function testSendViaPromoTexterSuccess()
76
    {
77
        $provider = new PromoTexter();
78
        $this->sendSuccess($provider);
79
80
    }
81
82
    // Send via PromoTexter Fail (Incorrect Phone Number Format)
83
    public function testSendViaPromoTexterFail()
84
    {
85
        $this->phoneNumber = 'AAA';
86
        $provider = new PromoTexter();
87
        $this->sendFail($provider);
88
    }
89
90
    // Send via RisingTide Success
91
    public function testSendViaRisingTideSuccess()
92
    {
93
        $provider = new RisingTide();
94
        $this->sendSuccess($provider);
95
    }
96
97
    // Send via RisingTide Fail
98
    public function testSendViaRisingTideFail()
99
    {
100
        $this->phoneNumber = 'AAA';
101
        $provider = new RisingTide();
102
        $this->sendFail($provider);
103
    }
104
105
    // Send via Semaphore Success
106
    public function testSendViaSemaphoreSuccess()
107
    {
108
        $provider = new Semaphore();
109
        $this->sendSuccess($provider);
110
    }
111
112
    // Send via Semaphore Fail
113
    public function testSendViaSemaphoreFail()
114
    {
115
        $this->phoneNumber = 'AAA';
116
        $provider = new Semaphore();
117
        $this->sendFail($provider);
118
    }
119
120
    // Send via Chikka Success
121
    public function testSendViaChikkaSuccess()
122
    {
123
        $provider = new Chikka();
124
        $this->sendSuccess($provider);
125
    }
126
127
    // Send via Chikka Fail
128
    public function testSendViaChikkaFail()
129
    {
130
        $this->phoneNumber = 'AAA';
131
        $provider = new Chikka();
132
        $this->sendFail($provider);
133
    }
134
135
    // Send via Chikka Success
136
    public function testSendViaNexmoSuccess()
137
    {
138
        $provider = new Nexmo();
139
        $this->sendSuccess($provider);
140
    }
141
142
    // Send via Nexmo Fail
143
    public function testSendViaNexmoFail()
144
    {
145
        $this->phoneNumber = 'AAA';
146
        $provider = new Nexmo();
147
        $this->sendFail($provider);
148
    }
149
150
    // Send via Twilio Success
151
    public function testSendViaTwilioSuccess()
152
    {
153
        $provider = new Twilio();
154
        $this->sendSuccess($provider);
155
    }
156
157
    // Send via Nexmo Fail
158
    public function testSendViaTwilioFail()
159
    {
160
        $this->phoneNumber = 'AAA';
161
        $provider = new Twilio();
162
        $this->sendFail($provider);
163
    }
164
}