Skip to content

Commit 9d6bb7e

Browse files
committed
Adjust tests to be compatible with newer Laravel versions, also remove device from sent data if no device was set
1 parent 7b4cfcc commit 9d6bb7e

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [8.3, 8.2, 8.1]
16+
php: [8.4, 8.3, 8.2, 8.1]
1717
laravel: ['8.*', '9.*', '10.*', '11.*', '12.*']
1818
include:
1919
- laravel: 10.*

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"require-dev": {
2121
"mockery/mockery": "^1.3.1",
2222
"phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3",
23-
"orchestra/testbench": "^8.0 || ^9.0 || ^10.0",
24-
"dms/phpunit-arraysubset-asserts": ">=0.1.0"
23+
"orchestra/testbench": "^8.0 || ^9.0 || ^10.0"
2524
},
2625
"suggest": {
2726
"ext-exif": "Required for image attachment support"

src/PushoverReceiver.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PushoverReceiver
1111
/**
1212
* PushoverReceiver constructor.
1313
*
14-
* @param string $key User or group key.
14+
* @param string $key User or group key.
1515
*/
1616
protected function __construct(string $key)
1717
{
@@ -21,7 +21,7 @@ protected function __construct(string $key)
2121
/**
2222
* Create new Pushover receiver with an user key.
2323
*
24-
* @param string $userKey Pushover user key.
24+
* @param string $userKey Pushover user key.
2525
* @return PushoverReceiver
2626
*/
2727
public static function withUserKey(string $userKey): PushoverReceiver
@@ -32,7 +32,7 @@ public static function withUserKey(string $userKey): PushoverReceiver
3232
/**
3333
* Create new Pushover receiver with a group key.
3434
*
35-
* @param string $groupKey Pushover group key.
35+
* @param string $groupKey Pushover group key.
3636
* @return PushoverReceiver
3737
*/
3838
public static function withGroupKey(string $groupKey): PushoverReceiver
@@ -45,7 +45,7 @@ public static function withGroupKey(string $groupKey): PushoverReceiver
4545
/**
4646
* Send the message to a specific device.
4747
*
48-
* @param array|string $device
48+
* @param array|string $device
4949
* @return PushoverReceiver
5050
*/
5151
public function toDevice(array|string $device): static
@@ -81,9 +81,18 @@ public function withApplicationToken($token): static
8181
*/
8282
public function toArray(): array
8383
{
84-
return array_merge([
84+
$data = [
8585
'user' => $this->key,
86-
'device' => implode(',', $this->devices),
87-
], $this->token ? ['token' => $this->token] : []);
86+
];
87+
88+
if (!empty($this->devices)) {
89+
$data['device'] = implode(',', $this->devices);
90+
}
91+
92+
if ($this->token) {
93+
$data['token'] = $this->token;
94+
}
95+
96+
return $data;
8897
}
8998
}

tests/PushoverReceiverTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace NotificationChannels\Pushover\Test;
44

5-
use DMS\PHPUnitExtensions\ArraySubset\Assert;
65
use NotificationChannels\Pushover\PushoverReceiver;
76
use Orchestra\Testbench\TestCase;
87

@@ -20,23 +19,30 @@ public function it_can_set_up_a_receiver_with_an_user_key()
2019
{
2120
$pushoverReceiver = PushoverReceiver::withUserKey('pushover-key');
2221

23-
Assert::assertArraySubset(['user' => 'pushover-key'], $pushoverReceiver->toArray());
22+
$this->assertEquals([
23+
'user' => 'pushover-key',
24+
], $pushoverReceiver->toArray());
2425
}
2526

2627
/** @test */
2728
public function it_can_set_up_a_receiver_with_a_group_key()
2829
{
2930
$pushoverReceiver = PushoverReceiver::withGroupKey('pushover-key');
3031

31-
Assert::assertArraySubset(['user' => 'pushover-key'], $pushoverReceiver->toArray());
32+
$this->assertEquals([
33+
'user' => 'pushover-key',
34+
], $pushoverReceiver->toArray());
3235
}
3336

3437
/** @test */
3538
public function it_can_set_up_a_receiver_with_an_application_token()
3639
{
3740
$pushoverReceiver = PushoverReceiver::withUserKey('pushover-key')->withApplicationToken('pushover-token');
3841

39-
Assert::assertArraySubset(['user' => 'pushover-key', 'token' => 'pushover-token'], $pushoverReceiver->toArray());
42+
$this->assertEquals([
43+
'user' => 'pushover-key',
44+
'token' => 'pushover-token',
45+
], $pushoverReceiver->toArray());
4046
}
4147

4248
/** @test */
@@ -54,24 +60,34 @@ public function it_can_add_a_single_device_to_the_receiver()
5460
{
5561
$this->pushoverReceiver->toDevice('iphone');
5662

57-
Assert::assertArraySubset(['device' => 'iphone'], $this->pushoverReceiver->toArray());
63+
$this->assertEquals([
64+
'user' => 'pushover-key',
65+
'device' => 'iphone',
66+
], $this->pushoverReceiver->toArray());
5867
}
5968

6069
/** @test */
6170
public function it_can_add_multiple_devices_to_the_receiver()
6271
{
63-
$this->pushoverReceiver->toDevice('iphone')
72+
$this->pushoverReceiver
73+
->toDevice('iphone')
6474
->toDevice('desktop')
6575
->toDevice('macbook');
6676

67-
Assert::assertArraySubset(['device' => 'iphone,desktop,macbook'], $this->pushoverReceiver->toArray());
77+
$this->assertEquals([
78+
'user' => 'pushover-key',
79+
'device' => 'iphone,desktop,macbook',
80+
], $this->pushoverReceiver->toArray());
6881
}
6982

7083
/** @test */
7184
public function it_can_add_an_array_of_devices_to_the_receiver()
7285
{
7386
$this->pushoverReceiver->toDevice(['iphone', 'desktop', 'macbook']);
7487

75-
Assert::assertArraySubset(['device' => 'iphone,desktop,macbook'], $this->pushoverReceiver->toArray());
88+
$this->assertEquals([
89+
'user' => 'pushover-key',
90+
'device' => 'iphone,desktop,macbook',
91+
], $this->pushoverReceiver->toArray());
7692
}
7793
}

0 commit comments

Comments
 (0)