Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
55 changes: 46 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Tests

on:
- push
- pull_request
push:
branches:
- master
pull_request:

jobs:
test:
Expand All @@ -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
Expand All @@ -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

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpunit.cache
/vendor
build
.phpunit.result.cache
Expand Down
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
"email": "[email protected]",
"homepage": "https://casperboone.nl",
"role": "Developer"
},
{
"name": "Kevin Woblick",
"email": "[email protected]",
"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"
Expand Down
28 changes: 16 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnRisky="true">

<testsuites>
<testsuite name="Laravel Pushover Notifications Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>

<source restrictNotices="true" restrictWarnings="true">
<include>
<directory suffix=".php">./src</directory>
<directory>src</directory>
</include>
</source>

<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>

<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
Expand Down
30 changes: 30 additions & 0 deletions phpunit.xml.legacy.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Laravel Pushover Notifications Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
15 changes: 12 additions & 3 deletions src/PushoverReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 8 additions & 5 deletions tests/PushoverChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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',
Expand Down
32 changes: 24 additions & 8 deletions tests/PushoverReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace NotificationChannels\Pushover\Test;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use NotificationChannels\Pushover\PushoverReceiver;
use Orchestra\Testbench\TestCase;

Expand All @@ -20,23 +19,30 @@ 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 */
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 */
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 */
Expand All @@ -54,24 +60,34 @@ 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 */
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());
}
}
21 changes: 9 additions & 12 deletions tests/PushoverServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}