Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 5b7bb65

Browse files
committed
Improve test suite
1 parent ff2887b commit 5b7bb65

File tree

5 files changed

+71
-140
lines changed

5 files changed

+71
-140
lines changed

tests/DownstreamResponseTest.php

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
class DownstreamResponseTest extends FCMTestCase
77
{
8-
/**
9-
* @test
10-
*/
11-
public function it_construct_a_response_with_a_success()
8+
public function testItConstructAResponseWith_a_success()
129
{
1310
$token = 'new_token';
1411

@@ -35,10 +32,7 @@ public function it_construct_a_response_with_a_success()
3532
$this->assertCount(0, $downstreamResponse->tokensToModify());
3633
}
3734

38-
/**
39-
* @test
40-
*/
41-
public function it_construct_a_response_with_multiple_successes()
35+
public function testItConstructAResponseWith_multiple_successes()
4236
{
4337
$tokens = [
4438
'first_token',
@@ -71,10 +65,7 @@ public function it_construct_a_response_with_multiple_successes()
7165
$this->assertCount(0, $downstreamResponse->tokensToModify());
7266
}
7367

74-
/**
75-
* @test
76-
*/
77-
public function it_construct_a_response_with_a_failure()
68+
public function testItConstructAResponseWith_a_failure()
7869
{
7970
$token = 'new_token';
8071

@@ -103,10 +94,7 @@ public function it_construct_a_response_with_a_failure()
10394
$this->assertCount(0, $downstreamResponse->tokensToModify());
10495
}
10596

106-
/**
107-
* @test
108-
*/
109-
public function it_construct_a_response_with_multiple_failures()
97+
public function testItConstructAResponseWith_multiple_failures()
11098
{
11199
$tokens = [
112100
'first_token',
@@ -145,10 +133,7 @@ public function it_construct_a_response_with_multiple_failures()
145133
$this->assertCount(0, $downstreamResponse->tokensToModify());
146134
}
147135

148-
/**
149-
* @test
150-
*/
151-
public function it_construct_a_response_with_a_token_to_change()
136+
public function testItConstructAResponseWith_a_token_to_change()
152137
{
153138
$token = 'new_token';
154139

@@ -178,10 +163,7 @@ public function it_construct_a_response_with_a_token_to_change()
178163
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $token ]);
179164
}
180165

181-
/**
182-
* @test
183-
*/
184-
public function it_construct_a_response_with_multiple_tokens_to_change()
166+
public function testItConstructAResponseWith_multiple_tokens_to_change()
185167
{
186168
$tokens = [
187169
'first_token',
@@ -223,10 +205,7 @@ public function it_construct_a_response_with_multiple_tokens_to_change()
223205
$this->assertEquals('34', $downstreamResponse->tokensToModify()[ $tokens[ 2 ] ]);
224206
}
225207

226-
/**
227-
* @test
228-
*/
229-
public function it_construct_a_response_with_a_token_unavailable()
208+
public function testItConstructAResponseWith_a_token_unavailable()
230209
{
231210
$token = 'first_token';
232211

@@ -257,10 +236,7 @@ public function it_construct_a_response_with_a_token_unavailable()
257236
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
258237
}
259238

260-
/**
261-
* @test
262-
*/
263-
public function it_construct_a_response_with_a_token_server_error()
239+
public function testItConstructAResponseWith_a_token_server_error()
264240
{
265241
$token = 'first_token';
266242

@@ -291,10 +267,7 @@ public function it_construct_a_response_with_a_token_server_error()
291267
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
292268
}
293269

294-
/**
295-
* @test
296-
*/
297-
public function it_construct_a_response_with_a_token_exceeded()
270+
public function testItConstructAResponseWith_a_token_exceeded()
298271
{
299272
$token = 'first_token';
300273

@@ -325,10 +298,7 @@ public function it_construct_a_response_with_a_token_exceeded()
325298
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
326299
}
327300

328-
/**
329-
* @test
330-
*/
331-
public function it_construct_a_response_with_a_mixed_token_to_retry()
301+
public function testItConstructAResponseWith_a_mixed_token_to_retry()
332302
{
333303
$tokens = [
334304
'first_token',
@@ -376,10 +346,7 @@ public function it_construct_a_response_with_a_mixed_token_to_retry()
376346
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToRetry()[ 5 ]);
377347
}
378348

379-
/**
380-
* @test
381-
*/
382-
public function it_construct_a_response_with_mixed_response()
349+
public function testItConstructAResponseWith_mixed_response()
383350
{
384351
$tokens = [
385352
'first_token',
@@ -425,10 +392,7 @@ public function it_construct_a_response_with_mixed_response()
425392
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $tokens[ 4 ] ]);
426393
}
427394

428-
/**
429-
* @test
430-
*/
431-
public function it_construct_a_response_with_multiples_response()
395+
public function testItConstructAResponseWith_multiples_response()
432396
{
433397
$tokens = [
434398
'first_token',

tests/DownstreamTest.php

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88

99
class ResponseTest extends FCMTestCase
1010
{
11-
/**
12-
* @test
13-
*/
14-
public function it_send_a_notification_to_a_device()
11+
public function testItSendANotificationToADevice()
1512
{
16-
$response = new Response(200, [], '{
17-
"multicast_id": 216,
18-
"success": 3,
19-
"failure": 3,
20-
"canonical_ids": 1,
21-
"results": [
22-
{ "message_id": "1:0408" }
23-
]
24-
}');
13+
$response = new Response(200, [], json_encode(
14+
[
15+
'multicast_id' => 216,
16+
'success' => 3,
17+
'failure' => 3,
18+
'canonical_ids' => 1,
19+
'results' => [
20+
['message_id' => '1:0408'],
21+
]
22+
]
23+
));
2524

2625
$handlerStack = HandlerStack::create(new MockHandler([$response]));
2726
$client = new Client(['handler' => $handlerStack]);
@@ -32,28 +31,27 @@ public function it_send_a_notification_to_a_device()
3231
$logger->pushHandler(new \Monolog\Handler\NullHandler());
3332

3433
$fcm = new FCMSender($client, 'http://test.test', $logger);
35-
$fcm->sendTo($tokens);
34+
$this->assertNotNull($fcm->sendTo($tokens));
3635
}
3736

38-
/**
39-
* @test
40-
*/
41-
public function it_send_a_notification_to_more_than_1000_devices()
37+
public function testItSendANotificationTo_moreThan1000Devices()
4238
{
43-
$response = new Response(200, [], '{
44-
"multicast_id": 216,
45-
"success": 3,
46-
"failure": 3,
47-
"canonical_ids": 1,
48-
"results": [
49-
{ "message_id": "1:0408" },
50-
{ "error": "Unavailable" },
51-
{ "error": "InvalidRegistration" },
52-
{ "message_id": "1:1516" },
53-
{ "message_id": "1:2342", "registration_id": "32" },
54-
{ "error": "NotRegistered"}
55-
]
56-
}');
39+
$response = new Response(200, [], json_encode(
40+
[
41+
'multicast_id' => 216,
42+
'success' => 3,
43+
'failure' => 3,
44+
'canonical_ids' => 1,
45+
'results' => [
46+
['message_id' => '1:0408'],
47+
['error' => 'Unavailable'],
48+
['error' => 'InvalidRegistration'],
49+
['message_id' => '1:1516'],
50+
['message_id' => '1:2342', 'registration_id' => '32'],
51+
['error' => 'NotRegistered']
52+
]
53+
]
54+
));
5755

5856
$mock = new MockHandler([
5957
$response, $response, $response, $response, $response,
@@ -64,35 +62,34 @@ public function it_send_a_notification_to_more_than_1000_devices()
6462

6563
$tokens = [];
6664
for ($i = 0; $i < 10000; ++$i) {
67-
$tokens[$i] = 'token_'.$i;
65+
$tokens[$i] = 'token_' . $i;
6866
}
6967

7068
$logger = new \Monolog\Logger('test');
7169
$logger->pushHandler(new \Monolog\Handler\NullHandler());
7270

7371
$fcm = new FCMSender($client, 'http://test.test', $logger);
74-
$fcm->sendTo($tokens);
72+
$this->assertNotNull($fcm->sendTo($tokens));
7573
}
7674

77-
/**
78-
* @test
79-
*/
80-
public function an_empty_array_of_tokens_thrown_an_exception()
75+
public function testAnEmptyArrayOfTokensThrownAnException()
8176
{
82-
$response = new Response(400, [], '{
83-
"multicast_id": 216,
84-
"success": 3,
85-
"failure": 3,
86-
"canonical_ids": 1,
87-
"results": [
88-
{ "message_id": "1:0408" },
89-
{ "error": "Unavailable" },
90-
{ "error": "InvalidRegistration" },
91-
{ "message_id": "1:1516" },
92-
{ "message_id": "1:2342", "registration_id": "32" },
93-
{ "error": "NotRegistered"}
94-
]
95-
}');
77+
$response = new Response(400, [], json_encode(
78+
[
79+
'multicast_id' => 216,
80+
'success' => 3,
81+
'failure' => 3,
82+
'canonical_ids' => 1,
83+
'results' => [
84+
['message_id' => '1:0408'],
85+
['error' => 'Unavailable'],
86+
['error' => 'InvalidRegistration'],
87+
['message_id' => '1:1516'],
88+
['message_id' => '1:2342', 'registration_id' => '32'],
89+
['error' => 'NotRegistered']
90+
]
91+
]
92+
));
9693

9794
$handlerStack = HandlerStack::create(new MockHandler([$response]));
9895
$client = new Client(['handler' => $handlerStack]);

tests/GroupResponseTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class GroupResponseTest extends FCMTestCase
66
{
7-
/**
8-
* @test
9-
*/
10-
public function it_construct_a_response_with_successes()
7+
public function testItConstructAResponseWithSuccesses()
118
{
129
$notificationKey = 'notificationKey';
1310

@@ -26,10 +23,7 @@ public function it_construct_a_response_with_successes()
2623
$this->assertCount(0, $responseGroup->tokensFailed());
2724
}
2825

29-
/**
30-
* @test
31-
*/
32-
public function it_construct_a_response_with_failures()
26+
public function testItConstructAResponseWithFailures()
3327
{
3428
$notificationKey = 'notificationKey';
3529

@@ -54,10 +48,7 @@ public function it_construct_a_response_with_failures()
5448
$this->assertEquals('regId2', $responseGroup->tokensFailed()[ 1]);
5549
}
5650

57-
/**
58-
* @test
59-
*/
60-
public function it_construct_a_response_with_partials_failures()
51+
public function testItConstructAResponseWithPartialsFailures()
6152
{
6253
$notificationKey = 'notificationKey';
6354

tests/MessageTest.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
class PayloadTest extends FCMTestCase
1010
{
11-
/**
12-
* @test
13-
*/
14-
public function it_construct_a_valid_json_with_option()
11+
public function testItConstructAValidJsonWithOption()
1512
{
1613
$targetPartial = '{
1714
"collapse_key":"collapseKey",
@@ -83,10 +80,7 @@ public function testBuildOptionsDirectBootOk()
8380
$this->assertJsonStringEqualsJsonString($targetFull, $json);
8481
}
8582

86-
/**
87-
* @test
88-
*/
89-
public function it_construct_a_valid_json_with_data()
83+
public function testItConstructAValidJson_with_data()
9084
{
9185
$targetAdd = '{
9286
"first_data":"first",
@@ -113,10 +107,7 @@ public function it_construct_a_valid_json_with_data()
113107
$this->assertJsonStringEqualsJsonString($targetSet, $json);
114108
}
115109

116-
/**
117-
* @test
118-
*/
119-
public function it_construct_a_valid_json_with_notification()
110+
public function testItConstructAValidJsonWithNotification()
120111
{
121112
$targetPartial = '{
122113
"title":"test_title",
@@ -170,10 +161,7 @@ public function it_construct_a_valid_json_with_notification()
170161
$this->assertJsonStringEqualsJsonString($targetFull, $json);
171162
}
172163

173-
/**
174-
* @test
175-
*/
176-
public function it_throws_an_invalidoptionsexception_if_the_interval_is_too_big()
164+
public function testItThrowsAnInvalidOptionsExceptionIfTheIntervalIsTooBig()
177165
{
178166
$this->setExceptionExpected(InvalidOptionsException::class);
179167

tests/TopicResponseTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
class TopicsResponseTest extends FCMTestCase
77
{
8-
/**
9-
* @test
10-
*/
11-
public function it_construct_a_topic_response_with_success()
8+
public function testItConstructATopicResponse_with_success()
129
{
1310
$topic = new \LaravelFCM\Message\Topics();
1411
$topic->topic('topicName');
@@ -27,10 +24,7 @@ public function it_construct_a_topic_response_with_success()
2724
$this->assertNull($topicResponse->error());
2825
}
2926

30-
/**
31-
* @test
32-
*/
33-
public function it_construct_a_topic_response_with_error()
27+
public function testItConstructATopicResponseWithError()
3428
{
3529
$topic = new \LaravelFCM\Message\Topics();
3630
$topic->topic('topicName');
@@ -49,10 +43,7 @@ public function it_construct_a_topic_response_with_error()
4943
$this->assertEquals('MessageTooBig', $topicResponse->error());
5044
}
5145

52-
/**
53-
* @test
54-
*/
55-
public function it_construct_a_topic_response_with_error_and_it_should_retry()
46+
public function testItConstructATopicResponseWithErrorAndItShouldRetry()
5647
{
5748
$topic = new \LaravelFCM\Message\Topics();
5849
$topic->topic('topicName');

0 commit comments

Comments
 (0)