Skip to content

Commit 4c7dd17

Browse files
authored
Merge pull request #67 from laravel-notification-channels/laravel-shift-l12-compatibility
Laravel shift l12 compatibility
2 parents 31ff8c1 + 2afc6c3 commit 4c7dd17

File tree

10 files changed

+159
-54
lines changed

10 files changed

+159
-54
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ trim_trailing_whitespace = true
1313

1414
[*.md]
1515
trim_trailing_whitespace = false
16+
17+
[*.{yaml,yml}]
18+
indent_size = 2

.github/workflows/test.yml

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Tests
22

33
on:
4-
- push
5-
- pull_request
4+
push:
5+
branches:
6+
- master
7+
pull_request:
68

79
jobs:
810
test:
@@ -13,20 +15,54 @@ jobs:
1315
strategy:
1416
fail-fast: true
1517
matrix:
16-
php: [8.3, 8.2, 8.1]
17-
laravel: ['8.*', '9.*', '10.*', '11.*']
18+
php: [ 8.4, 8.3, 8.2, 8.1 ]
19+
laravel: [ '10.*', '11.*', '12.*' ]
1820
include:
1921
- laravel: 10.*
2022
testbench: 8.*
21-
- laravel: 9.*
22-
testbench: 7.*
23-
- laravel: 8.*
24-
testbench: 6.*
2523
- laravel: 11.*
2624
testbench: 9.*
25+
- laravel: 12.*
26+
testbench: 10.*
2727
exclude:
2828
- laravel: 11.*
2929
php: 8.1
30+
- laravel: 12.*
31+
php: 8.1
32+
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v2
36+
37+
- name: Set correct PHP version
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: ${{ matrix.php }}
41+
coverage: pcov
42+
43+
- name: Install dependencies
44+
run: |
45+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
46+
composer update --prefer-stable --prefer-dist --no-interaction --no-suggest
47+
48+
- name: Execute tests
49+
run: vendor/bin/phpunit -c phpunit.xml.dist
50+
51+
test-legacy:
52+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
53+
54+
runs-on: ubuntu-latest
55+
56+
strategy:
57+
fail-fast: true
58+
matrix:
59+
php: [ 8.4, 8.3, 8.2, 8.1 ]
60+
laravel: [ '8.*', '9.*' ]
61+
include:
62+
- laravel: 8.*
63+
testbench: 6.*
64+
- laravel: 9.*
65+
testbench: 7.*
3066

3167
steps:
3268
- name: Checkout code
@@ -44,4 +80,5 @@ jobs:
4480
composer update --prefer-stable --prefer-dist --no-interaction --no-suggest
4581
4682
- name: Execute tests
47-
run: vendor/bin/phpunit
83+
run: vendor/bin/phpunit -c phpunit.xml.legacy.dist
84+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.phpunit.cache
12
/vendor
23
build
34
.phpunit.result.cache

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@
99
"email": "[email protected]",
1010
"homepage": "https://casperboone.nl",
1111
"role": "Developer"
12+
},
13+
{
14+
"name": "Kevin Woblick",
15+
"email": "[email protected]",
16+
"homepage": "https://woblick.dev",
17+
"role": "Developer"
1218
}
1319
],
1420
"require": {
1521
"php": "^8.1",
1622
"guzzlehttp/guzzle": "^7.0.1",
17-
"illuminate/notifications": "^8.0 || ^9.0 || ^10.0 || ^11.0",
18-
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0"
23+
"illuminate/notifications": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0",
24+
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0"
1925
},
2026
"require-dev": {
2127
"mockery/mockery": "^1.3.1",
22-
"phpunit/phpunit": "^9.3 || ^10.5",
23-
"orchestra/testbench": "^8.0 || ^9.0",
24-
"dms/phpunit-arraysubset-asserts": ">=0.1.0"
28+
"phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3",
29+
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
2530
},
2631
"suggest": {
2732
"ext-exif": "Required for image attachment support"

phpunit.xml.dist

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
beStrictAboutOutputDuringTests="true"
8+
displayDetailsOnPhpunitDeprecations="true"
9+
failOnRisky="true">
10+
1211
<testsuites>
1312
<testsuite name="Laravel Pushover Notifications Test Suite">
1413
<directory>tests</directory>
1514
</testsuite>
1615
</testsuites>
17-
<coverage>
16+
17+
<source restrictNotices="true" restrictWarnings="true">
1818
<include>
19-
<directory suffix=".php">./src</directory>
19+
<directory>src</directory>
2020
</include>
21+
</source>
22+
23+
<coverage>
2124
<report>
2225
<html outputDirectory="build/coverage"/>
2326
<text outputFile="build/coverage.txt"/>
2427
<clover outputFile="build/logs/clover.xml"/>
2528
</report>
2629
</coverage>
30+
2731
<logging>
2832
<junit outputFile="build/report.junit.xml"/>
2933
</logging>

phpunit.xml.legacy.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Laravel Pushover Notifications Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<coverage>
18+
<include>
19+
<directory suffix=".php">./src</directory>
20+
</include>
21+
<report>
22+
<html outputDirectory="build/coverage"/>
23+
<text outputFile="build/coverage.txt"/>
24+
<clover outputFile="build/logs/clover.xml"/>
25+
</report>
26+
</coverage>
27+
<logging>
28+
<junit outputFile="build/report.junit.xml"/>
29+
</logging>
30+
</phpunit>

src/PushoverReceiver.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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/PushoverChannelTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ public function it_can_send_a_message_to_pushover(): void
4747
{
4848
$notifiable = new Notifiable;
4949

50-
$this->notification->shouldReceive('toPushover')
50+
$this->notification
51+
->shouldReceive('toPushover')
5152
->with($notifiable)
5253
->andReturn($this->message);
5354

54-
$this->pushover->shouldReceive('send')
55+
$this->pushover
56+
->shouldReceive('send')
5557
->with(Mockery::subset([
5658
'user' => 'pushover-key-30characters-long',
57-
'device' => '',
5859
]), $notifiable)
5960
->once();
6061

@@ -66,11 +67,13 @@ public function it_can_send_a_message_to_pushover_using_a_pushover_receiver(): v
6667
{
6768
$notifiable = new NotifiableWithPushoverReceiver;
6869

69-
$this->notification->shouldReceive('toPushover')
70+
$this->notification
71+
->shouldReceive('toPushover')
7072
->with($notifiable)
7173
->andReturn($this->message);
7274

73-
$this->pushover->shouldReceive('send')
75+
$this->pushover
76+
->shouldReceive('send')
7477
->with(Mockery::subset([
7578
'user' => 'pushover-key-30characters-long',
7679
'device' => 'iphone,desktop',

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
}

tests/PushoverServiceProviderTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace NotificationChannels\Pushover\Test;
44

5-
use Illuminate\Contracts\Foundation\Application;
5+
use GuzzleHttp\Client as HttpClient;
66
use Illuminate\Support\Facades\Config;
77
use Mockery;
88
use NotificationChannels\Pushover\Pushover;
@@ -15,30 +15,27 @@ class PushoverServiceProviderTest extends TestCase
1515
/** @var PushoverServiceProvider */
1616
protected $provider;
1717

18-
/** @var Application */
19-
protected $app;
20-
2118
public function setUp(): void
2219
{
2320
parent::setUp();
2421

25-
$this->app = Mockery::mock(Application::class);
2622
$this->provider = new PushoverServiceProvider($this->app);
27-
28-
$this->app->shouldReceive('flush');
2923
}
3024

3125
/** @test */
3226
public function it_gives_an_instantiated_pushover_object_when_the_channel_asks_for_it(): void
3327
{
3428
Config::shouldReceive('get')->with('services.pushover.token', null)->once()->andReturn('test-token');
29+
Config::shouldReceive('get')->with('database.default')->andReturn('array');
30+
Config::shouldReceive('get')->with('database.connections.array')->andReturn(['driver' => 'array']);
3531

36-
$this->app->shouldReceive('when')->with(PushoverChannel::class)->once()->andReturn($this->app);
37-
$this->app->shouldReceive('needs')->with(Pushover::class)->once()->andReturn($this->app);
38-
$this->app->shouldReceive('give')->with(Mockery::on(function ($pushover) {
39-
return $pushover() instanceof Pushover;
40-
}))->once();
32+
$this->app->when(PushoverChannel::class)->needs(Pushover::class)->give(function () {
33+
return new Pushover(Mockery::mock(HttpClient::class), 'test-token');
34+
});
4135

4236
$this->provider->boot();
37+
38+
$pushover = $this->app->get(PushoverChannel::class);
39+
$this->assertInstanceOf(PushoverChannel::class, $pushover);
4340
}
4441
}

0 commit comments

Comments
 (0)