Skip to content

Commit 651e64c

Browse files
committed
Always use the same method to assert equality
1 parent de4b2b1 commit 651e64c

1 file changed

Lines changed: 36 additions & 28 deletions

File tree

tests/Unit/Messaging/ApnsConfigTest.php

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@ public function itIsEmptyWhenItIsEmpty(): void
2525
#[Test]
2626
public function itHasADefaultSound(): void
2727
{
28-
$expected = [
28+
$config = ApnsConfig::fromArray([
2929
'payload' => [
3030
'aps' => [
3131
'sound' => 'default',
3232
],
3333
],
34-
];
34+
]);
3535

3636
$this->assertJsonStringEqualsJsonString(
37-
Json::encode($expected),
37+
Json::encode($config),
3838
Json::encode(ApnsConfig::new()->withDefaultSound()),
3939
);
4040
}
4141

4242
#[Test]
4343
public function itHasABadge(): void
4444
{
45-
$expected = [
45+
$config = ApnsConfig::fromArray([
4646
'payload' => [
4747
'aps' => [
4848
'badge' => 123,
4949
],
5050
],
51-
];
51+
]);
5252

5353
$this->assertJsonStringEqualsJsonString(
54-
Json::encode($expected),
54+
Json::encode($config),
5555
Json::encode(ApnsConfig::new()->withBadge(123)),
5656
);
5757
}
@@ -63,34 +63,46 @@ public function itHasABadge(): void
6363
#[Test]
6464
public function itCanBeCreatedFromAnArray(array $data): void
6565
{
66-
$config = ApnsConfig::fromArray($data);
67-
$this->assertEqualsCanonicalizing($data, $config->jsonSerialize());
66+
$this->assertJsonStringEqualsJsonString(
67+
Json::encode($data),
68+
Json::encode(ApnsConfig::fromArray($data)),
69+
);
70+
}
71+
72+
public function itCanBeGivenData(): void
73+
{
74+
$config = ApnsConfig::fromArray(['data' => ['key' => 'value']]);
75+
76+
$this->assertJsonStringEqualsJsonString(
77+
Json::encode($config),
78+
Json::encode(ApnsConfig::new()->withDataField('key', 'value')),
79+
);
6880
}
6981

7082
#[Test]
7183
public function itCanHaveAnImmediatePriority(): void
7284
{
73-
$config = ApnsConfig::new()->withImmediatePriority();
74-
$payload = Json::decode(Json::encode($config), true);
85+
$config = ApnsConfig::fromArray(['headers' => ['apns-priority' => '10']]);
7586

76-
$this->assertArrayHasKey('headers', $payload);
77-
$this->assertArrayHasKey('apns-priority', $payload['headers']);
78-
$this->assertSame('10', $payload['headers']['apns-priority']);
87+
$this->assertJsonStringEqualsJsonString(
88+
Json::encode($config),
89+
Json::encode(ApnsConfig::new()->withImmediatePriority()),
90+
);
7991
}
8092

8193
#[Test]
8294
public function itCanHaveAPowerConservingPriority(): void
8395
{
84-
$config = ApnsConfig::new()->withPowerConservingPriority();
85-
$payload = Json::decode(Json::encode($config), true);
96+
$config = ApnsConfig::fromArray(['headers' => ['apns-priority' => '5']]);
8697

87-
$this->assertArrayHasKey('headers', $payload);
88-
$this->assertArrayHasKey('apns-priority', $payload['headers']);
89-
$this->assertSame('5', $payload['headers']['apns-priority']);
98+
$this->assertJsonStringEqualsJsonString(
99+
Json::encode($config),
100+
Json::encode(ApnsConfig::new()->withPowerConservingPriority()),
101+
);
90102
}
91103

92104
#[Test]
93-
public function itCanBeGivenALiveActivityToken(): void
105+
public function itCanBeGivenALiveActivityTokenInsideAnArray(): void
94106
{
95107
$config = ApnsConfig::fromArray(['live_activity_token' => 'token']);
96108

@@ -103,17 +115,13 @@ public function itCanBeGivenALiveActivityToken(): void
103115
#[Test]
104116
public function itHasASubtitle(): void
105117
{
106-
$expected = [
107-
'payload' => [
108-
'aps' => [
109-
'subtitle' => 'i am a subtitle',
110-
],
111-
],
112-
];
118+
$config = ApnsConfig::fromArray([
119+
'payload' => ['aps' => ['subtitle' => 'subtitle']],
120+
]);
113121

114122
$this->assertJsonStringEqualsJsonString(
115-
Json::encode($expected),
116-
Json::encode(ApnsConfig::new()->withSubtitle('i am a subtitle')),
123+
Json::encode($config),
124+
Json::encode(ApnsConfig::new()->withSubtitle('subtitle')),
117125
);
118126
}
119127

0 commit comments

Comments
 (0)