From 030f8a21271557be2bdbb4aee629aa6a2c7800f8 Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 17 Feb 2025 00:35:28 +0000 Subject: [PATCH 01/11] Bump dependencies for Laravel 12 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 6e60f0e..ddfc471 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ "require": { "php": "^8.1", "guzzlehttp/guzzle": "^7.0.1", - "illuminate/notifications": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" + "illuminate/notifications": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0" }, "require-dev": { "mockery/mockery": "^1.3.1", - "phpunit/phpunit": "^9.3 || ^10.5", - "orchestra/testbench": "^8.0 || ^9.0", + "phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3", + "orchestra/testbench": "^8.0 || ^9.0 || ^10.0", "dms/phpunit-arraysubset-asserts": ">=0.1.0" }, "suggest": { From 7b4cfccd217746c7c70fc23051f80fc0f807b7d6 Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 17 Feb 2025 00:35:28 +0000 Subject: [PATCH 02/11] Update GitHub Actions for Laravel 12 --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8701631..476082d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: fail-fast: true matrix: php: [8.3, 8.2, 8.1] - laravel: ['8.*', '9.*', '10.*', '11.*'] + laravel: ['8.*', '9.*', '10.*', '11.*', '12.*'] include: - laravel: 10.* testbench: 8.* @@ -24,9 +24,13 @@ jobs: testbench: 6.* - laravel: 11.* testbench: 9.* + - laravel: 12.* + testbench: 10.* exclude: - laravel: 11.* php: 8.1 + - laravel: 12.* + php: 8.1 steps: - name: Checkout code From 9d6bb7e8c8538700dd8217d30c8558638d347d43 Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 21:46:41 +0100 Subject: [PATCH 03/11] Adjust tests to be compatible with newer Laravel versions, also remove device from sent data if no device was set --- .github/workflows/test.yml | 2 +- composer.json | 3 +-- src/PushoverReceiver.php | 23 ++++++++++++++++------- tests/PushoverReceiverTest.php | 32 ++++++++++++++++++++++++-------- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 476082d..d23c2c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.3, 8.2, 8.1] + php: [8.4, 8.3, 8.2, 8.1] laravel: ['8.*', '9.*', '10.*', '11.*', '12.*'] include: - laravel: 10.* diff --git a/composer.json b/composer.json index ddfc471..3678b10 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ "require-dev": { "mockery/mockery": "^1.3.1", "phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3", - "orchestra/testbench": "^8.0 || ^9.0 || ^10.0", - "dms/phpunit-arraysubset-asserts": ">=0.1.0" + "orchestra/testbench": "^8.0 || ^9.0 || ^10.0" }, "suggest": { "ext-exif": "Required for image attachment support" diff --git a/src/PushoverReceiver.php b/src/PushoverReceiver.php index ff8232c..743566c 100644 --- a/src/PushoverReceiver.php +++ b/src/PushoverReceiver.php @@ -11,7 +11,7 @@ class PushoverReceiver /** * PushoverReceiver constructor. * - * @param string $key User or group key. + * @param string $key User or group key. */ protected function __construct(string $key) { @@ -21,7 +21,7 @@ protected function __construct(string $key) /** * Create new Pushover receiver with an user key. * - * @param string $userKey Pushover user key. + * @param string $userKey Pushover user key. * @return PushoverReceiver */ public static function withUserKey(string $userKey): PushoverReceiver @@ -32,7 +32,7 @@ public static function withUserKey(string $userKey): PushoverReceiver /** * Create new Pushover receiver with a group key. * - * @param string $groupKey Pushover group key. + * @param string $groupKey Pushover group key. * @return PushoverReceiver */ public static function withGroupKey(string $groupKey): PushoverReceiver @@ -45,7 +45,7 @@ public static function withGroupKey(string $groupKey): PushoverReceiver /** * Send the message to a specific device. * - * @param array|string $device + * @param array|string $device * @return PushoverReceiver */ public function toDevice(array|string $device): static @@ -81,9 +81,18 @@ public function withApplicationToken($token): static */ public function toArray(): array { - return array_merge([ + $data = [ 'user' => $this->key, - 'device' => implode(',', $this->devices), - ], $this->token ? ['token' => $this->token] : []); + ]; + + if (!empty($this->devices)) { + $data['device'] = implode(',', $this->devices); + } + + if ($this->token) { + $data['token'] = $this->token; + } + + return $data; } } diff --git a/tests/PushoverReceiverTest.php b/tests/PushoverReceiverTest.php index 40ce48d..be42583 100644 --- a/tests/PushoverReceiverTest.php +++ b/tests/PushoverReceiverTest.php @@ -2,7 +2,6 @@ namespace NotificationChannels\Pushover\Test; -use DMS\PHPUnitExtensions\ArraySubset\Assert; use NotificationChannels\Pushover\PushoverReceiver; use Orchestra\Testbench\TestCase; @@ -20,7 +19,9 @@ public function it_can_set_up_a_receiver_with_an_user_key() { $pushoverReceiver = PushoverReceiver::withUserKey('pushover-key'); - Assert::assertArraySubset(['user' => 'pushover-key'], $pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + ], $pushoverReceiver->toArray()); } /** @test */ @@ -28,7 +29,9 @@ public function it_can_set_up_a_receiver_with_a_group_key() { $pushoverReceiver = PushoverReceiver::withGroupKey('pushover-key'); - Assert::assertArraySubset(['user' => 'pushover-key'], $pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + ], $pushoverReceiver->toArray()); } /** @test */ @@ -36,7 +39,10 @@ public function it_can_set_up_a_receiver_with_an_application_token() { $pushoverReceiver = PushoverReceiver::withUserKey('pushover-key')->withApplicationToken('pushover-token'); - Assert::assertArraySubset(['user' => 'pushover-key', 'token' => 'pushover-token'], $pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + 'token' => 'pushover-token', + ], $pushoverReceiver->toArray()); } /** @test */ @@ -54,17 +60,24 @@ public function it_can_add_a_single_device_to_the_receiver() { $this->pushoverReceiver->toDevice('iphone'); - Assert::assertArraySubset(['device' => 'iphone'], $this->pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + 'device' => 'iphone', + ], $this->pushoverReceiver->toArray()); } /** @test */ public function it_can_add_multiple_devices_to_the_receiver() { - $this->pushoverReceiver->toDevice('iphone') + $this->pushoverReceiver + ->toDevice('iphone') ->toDevice('desktop') ->toDevice('macbook'); - Assert::assertArraySubset(['device' => 'iphone,desktop,macbook'], $this->pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + 'device' => 'iphone,desktop,macbook', + ], $this->pushoverReceiver->toArray()); } /** @test */ @@ -72,6 +85,9 @@ public function it_can_add_an_array_of_devices_to_the_receiver() { $this->pushoverReceiver->toDevice(['iphone', 'desktop', 'macbook']); - Assert::assertArraySubset(['device' => 'iphone,desktop,macbook'], $this->pushoverReceiver->toArray()); + $this->assertEquals([ + 'user' => 'pushover-key', + 'device' => 'iphone,desktop,macbook', + ], $this->pushoverReceiver->toArray()); } } From 722deabdeeb194516fd2f234abc998b61b0a3006 Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 21:54:29 +0100 Subject: [PATCH 04/11] Adjust tests for removed device field --- tests/PushoverChannelTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/PushoverChannelTest.php b/tests/PushoverChannelTest.php index 41e8374..55a3e60 100644 --- a/tests/PushoverChannelTest.php +++ b/tests/PushoverChannelTest.php @@ -47,14 +47,15 @@ public function it_can_send_a_message_to_pushover(): void { $notifiable = new Notifiable; - $this->notification->shouldReceive('toPushover') + $this->notification + ->shouldReceive('toPushover') ->with($notifiable) ->andReturn($this->message); - $this->pushover->shouldReceive('send') + $this->pushover + ->shouldReceive('send') ->with(Mockery::subset([ 'user' => 'pushover-key-30characters-long', - 'device' => '', ]), $notifiable) ->once(); @@ -66,11 +67,13 @@ public function it_can_send_a_message_to_pushover_using_a_pushover_receiver(): v { $notifiable = new NotifiableWithPushoverReceiver; - $this->notification->shouldReceive('toPushover') + $this->notification + ->shouldReceive('toPushover') ->with($notifiable) ->andReturn($this->message); - $this->pushover->shouldReceive('send') + $this->pushover + ->shouldReceive('send') ->with(Mockery::subset([ 'user' => 'pushover-key-30characters-long', 'device' => 'iphone,desktop', From 8116dc38b80efc42145a16bbaa8f1de5707ccaea Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 21:56:37 +0100 Subject: [PATCH 05/11] Fix code formatting --- src/PushoverReceiver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PushoverReceiver.php b/src/PushoverReceiver.php index 743566c..d43928f 100644 --- a/src/PushoverReceiver.php +++ b/src/PushoverReceiver.php @@ -11,7 +11,7 @@ class PushoverReceiver /** * PushoverReceiver constructor. * - * @param string $key User or group key. + * @param string $key User or group key. */ protected function __construct(string $key) { @@ -21,7 +21,7 @@ protected function __construct(string $key) /** * Create new Pushover receiver with an user key. * - * @param string $userKey Pushover user key. + * @param string $userKey Pushover user key. * @return PushoverReceiver */ public static function withUserKey(string $userKey): PushoverReceiver @@ -32,7 +32,7 @@ public static function withUserKey(string $userKey): PushoverReceiver /** * Create new Pushover receiver with a group key. * - * @param string $groupKey Pushover group key. + * @param string $groupKey Pushover group key. * @return PushoverReceiver */ public static function withGroupKey(string $groupKey): PushoverReceiver @@ -45,7 +45,7 @@ public static function withGroupKey(string $groupKey): PushoverReceiver /** * Send the message to a specific device. * - * @param array|string $device + * @param array|string $device * @return PushoverReceiver */ public function toDevice(array|string $device): static @@ -85,7 +85,7 @@ public function toArray(): array 'user' => $this->key, ]; - if (!empty($this->devices)) { + if (! empty($this->devices)) { $data['device'] = implode(',', $this->devices); } From b1f2b59665aa3db9dcd30c30ab684694fc75871b Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 22:13:54 +0100 Subject: [PATCH 06/11] Fix service provider test --- tests/PushoverServiceProviderTest.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/PushoverServiceProviderTest.php b/tests/PushoverServiceProviderTest.php index 000676f..3f2b07c 100644 --- a/tests/PushoverServiceProviderTest.php +++ b/tests/PushoverServiceProviderTest.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Pushover\Test; -use Illuminate\Contracts\Foundation\Application; +use GuzzleHttp\Client as HttpClient; use Illuminate\Support\Facades\Config; use Mockery; use NotificationChannels\Pushover\Pushover; @@ -15,17 +15,11 @@ class PushoverServiceProviderTest extends TestCase /** @var PushoverServiceProvider */ protected $provider; - /** @var Application */ - protected $app; - public function setUp(): void { parent::setUp(); - $this->app = Mockery::mock(Application::class); $this->provider = new PushoverServiceProvider($this->app); - - $this->app->shouldReceive('flush'); } /** @test */ @@ -33,12 +27,13 @@ public function it_gives_an_instantiated_pushover_object_when_the_channel_asks_f { Config::shouldReceive('get')->with('services.pushover.token', null)->once()->andReturn('test-token'); - $this->app->shouldReceive('when')->with(PushoverChannel::class)->once()->andReturn($this->app); - $this->app->shouldReceive('needs')->with(Pushover::class)->once()->andReturn($this->app); - $this->app->shouldReceive('give')->with(Mockery::on(function ($pushover) { - return $pushover() instanceof Pushover; - }))->once(); + $this->app->when(PushoverChannel::class)->needs(Pushover::class)->give(function () { + return new Pushover(Mockery::mock(HttpClient::class), 'test-token'); + }); $this->provider->boot(); + + $pushover = $this->app->get(PushoverChannel::class); + $this->assertInstanceOf(PushoverChannel::class, $pushover); } } From 9932e3abfa4d7b08c46fc02fa91bd173ff78717e Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 22:23:01 +0100 Subject: [PATCH 07/11] Fix service provider test --- tests/PushoverServiceProviderTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/PushoverServiceProviderTest.php b/tests/PushoverServiceProviderTest.php index 3f2b07c..f34e087 100644 --- a/tests/PushoverServiceProviderTest.php +++ b/tests/PushoverServiceProviderTest.php @@ -26,6 +26,8 @@ public function setUp(): void public function it_gives_an_instantiated_pushover_object_when_the_channel_asks_for_it(): void { Config::shouldReceive('get')->with('services.pushover.token', null)->once()->andReturn('test-token'); + Config::shouldReceive('get')->with('database.default')->once()->andReturn('array'); + Config::shouldReceive('get')->with('database.connections.array')->once()->andReturn(['driver' => 'array']); $this->app->when(PushoverChannel::class)->needs(Pushover::class)->give(function () { return new Pushover(Mockery::mock(HttpClient::class), 'test-token'); From 5bad5ff6ed7569f0aaa624b14cb1d88048757e4b Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 22:24:33 +0100 Subject: [PATCH 08/11] Fix service provider test --- tests/PushoverServiceProviderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PushoverServiceProviderTest.php b/tests/PushoverServiceProviderTest.php index f34e087..bc3b7fd 100644 --- a/tests/PushoverServiceProviderTest.php +++ b/tests/PushoverServiceProviderTest.php @@ -26,8 +26,8 @@ public function setUp(): void public function it_gives_an_instantiated_pushover_object_when_the_channel_asks_for_it(): void { Config::shouldReceive('get')->with('services.pushover.token', null)->once()->andReturn('test-token'); - Config::shouldReceive('get')->with('database.default')->once()->andReturn('array'); - Config::shouldReceive('get')->with('database.connections.array')->once()->andReturn(['driver' => 'array']); + Config::shouldReceive('get')->with('database.default')->zeroOrMoreTimes()->andReturn('array'); + Config::shouldReceive('get')->with('database.connections.array')->zeroOrMoreTimes()->andReturn(['driver' => 'array']); $this->app->when(PushoverChannel::class)->needs(Pushover::class)->give(function () { return new Pushover(Mockery::mock(HttpClient::class), 'test-token'); From 3182f14ea8610c247de0d45890aec1c529913ecc Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 22:29:15 +0100 Subject: [PATCH 09/11] Fix service provider test, adjust when tests are run --- .editorconfig | 3 +++ .github/workflows/test.yml | 10 ++++++---- tests/PushoverServiceProviderTest.php | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.editorconfig b/.editorconfig index cd8eb86..863e321 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.{yaml,yml}] +indent_size = 2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d23c2c9..f741e37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,10 @@ name: Tests on: - - push - - pull_request + push: + branches: + - master + pull_request: jobs: test: @@ -13,8 +15,8 @@ jobs: strategy: fail-fast: true matrix: - php: [8.4, 8.3, 8.2, 8.1] - laravel: ['8.*', '9.*', '10.*', '11.*', '12.*'] + php: [ 8.4, 8.3, 8.2, 8.1 ] + laravel: [ '8.*', '9.*', '10.*', '11.*', '12.*' ] include: - laravel: 10.* testbench: 8.* diff --git a/tests/PushoverServiceProviderTest.php b/tests/PushoverServiceProviderTest.php index bc3b7fd..245dff9 100644 --- a/tests/PushoverServiceProviderTest.php +++ b/tests/PushoverServiceProviderTest.php @@ -26,8 +26,8 @@ public function setUp(): void public function it_gives_an_instantiated_pushover_object_when_the_channel_asks_for_it(): void { Config::shouldReceive('get')->with('services.pushover.token', null)->once()->andReturn('test-token'); - Config::shouldReceive('get')->with('database.default')->zeroOrMoreTimes()->andReturn('array'); - Config::shouldReceive('get')->with('database.connections.array')->zeroOrMoreTimes()->andReturn(['driver' => 'array']); + Config::shouldReceive('get')->with('database.default')->andReturn('array'); + Config::shouldReceive('get')->with('database.connections.array')->andReturn(['driver' => 'array']); $this->app->when(PushoverChannel::class)->needs(Pushover::class)->give(function () { return new Pushover(Mockery::mock(HttpClient::class), 'test-token'); From d92cb86ba1acbdfe1a5c83a36c0a7f0014c9da9e Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 23:22:37 +0100 Subject: [PATCH 10/11] Split testing for different PHPUnit versions --- .github/workflows/test.yml | 43 ++++++++++++++++++++++++++++++++------ .gitignore | 1 + composer.json | 8 ++++++- phpunit.xml.dist | 31 ++++++++++++++++----------- phpunit.xml.legacy.dist | 30 ++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 phpunit.xml.legacy.dist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f741e37..eeb6735 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,14 +16,10 @@ jobs: fail-fast: true matrix: php: [ 8.4, 8.3, 8.2, 8.1 ] - laravel: [ '8.*', '9.*', '10.*', '11.*', '12.*' ] + laravel: [ '10.*', '11.*', '12.*' ] include: - laravel: 10.* testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - testbench: 6.* - laravel: 11.* testbench: 9.* - laravel: 12.* @@ -50,4 +46,39 @@ jobs: composer update --prefer-stable --prefer-dist --no-interaction --no-suggest - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/phpunit -c phpunit.xml.dist + + test-legacy: + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [ 8.4, 8.3, 8.2, 8.1 ] + laravel: [ '8.*', '9.*' ] + include: + - laravel: 8.* + testbench: 6.* + - laravel: 9.* + testbench: 7.* + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set correct PHP version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: pcov + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --prefer-stable --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit -c phpunit.xml.legacy.dist + diff --git a/.gitignore b/.gitignore index 74b638a..9443913 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.phpunit.cache /vendor build .phpunit.result.cache diff --git a/composer.json b/composer.json index 3678b10..938dc41 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,12 @@ "email": "mail@casperboone.nl", "homepage": "https://casperboone.nl", "role": "Developer" + }, + { + "name": "Kevin Woblick", + "email": "contact@woblick.dev", + "homepage": "https://woblick.dev", + "role": "Developer" } ], "require": { @@ -20,7 +26,7 @@ "require-dev": { "mockery/mockery": "^1.3.1", "phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3", - "orchestra/testbench": "^8.0 || ^9.0 || ^10.0" + "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" }, "suggest": { "ext-exif": "Required for image attachment support" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4d263c2..5e66750 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,36 @@ - + + tests - + + - ./src + src + + + + diff --git a/phpunit.xml.legacy.dist b/phpunit.xml.legacy.dist new file mode 100644 index 0000000..4d263c2 --- /dev/null +++ b/phpunit.xml.legacy.dist @@ -0,0 +1,30 @@ + + + + + tests + + + + + ./src + + + + + + + + + + + From 2afc6c3d10ceaca626729caef946c0bd18a4b5d5 Mon Sep 17 00:00:00 2001 From: Kovah Date: Tue, 25 Feb 2025 23:25:17 +0100 Subject: [PATCH 11/11] Fix phpunit config file --- phpunit.xml.dist | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5e66750..554eadd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,11 +4,8 @@ bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" - shortenArraysForExportThreshold="10" beStrictAboutOutputDuringTests="true" displayDetailsOnPhpunitDeprecations="true" - failOnPhpunitDeprecation="false" - failOnWarning="false" failOnRisky="true"> @@ -17,7 +14,7 @@ - + src