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 8701631..eeb6735 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,20 +15,54 @@ jobs: strategy: fail-fast: true matrix: - php: [8.3, 8.2, 8.1] - laravel: ['8.*', '9.*', '10.*', '11.*'] + php: [ 8.4, 8.3, 8.2, 8.1 ] + laravel: [ '10.*', '11.*', '12.*' ] include: - laravel: 10.* testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - 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 + 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.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 @@ -44,4 +80,5 @@ 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.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 6e60f0e..938dc41 100644 --- a/composer.json +++ b/composer.json @@ -9,19 +9,24 @@ "email": "mail@casperboone.nl", "homepage": "https://casperboone.nl", "role": "Developer" + }, + { + "name": "Kevin Woblick", + "email": "contact@woblick.dev", + "homepage": "https://woblick.dev", + "role": "Developer" } ], "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", - "dms/phpunit-arraysubset-asserts": ">=0.1.0" + "phpunit/phpunit": "^9.3 || ^10.5 || ^11.5.3", + "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..554eadd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,33 @@ - + + 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 + + + + + + + + + + + diff --git a/src/PushoverReceiver.php b/src/PushoverReceiver.php index ff8232c..d43928f 100644 --- a/src/PushoverReceiver.php +++ b/src/PushoverReceiver.php @@ -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/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', 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()); } } diff --git a/tests/PushoverServiceProviderTest.php b/tests/PushoverServiceProviderTest.php index 000676f..245dff9 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,30 +15,27 @@ 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 */ 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')->andReturn('array'); + Config::shouldReceive('get')->with('database.connections.array')->andReturn(['driver' => 'array']); - $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); } }