Skip to content

Commit

Permalink
Really run libnotify in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrech committed Apr 29, 2024
1 parent e415645 commit db1ed85
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
5 changes: 0 additions & 5 deletions tests/Notifier/CliBasedNotifierTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ public function testSendThrowsExceptionWhenNotificationHasAnEmptyBody()
}
}

public function getIconDir(): string
{
return realpath(\dirname(__DIR__) . '/fixtures');
}

abstract protected function getExpectedCommandLineForNotification(): string;

abstract protected function getExpectedCommandLineForNotificationWithATitle(): string;
Expand Down
59 changes: 52 additions & 7 deletions tests/Notifier/LibNotifyNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
use Joli\JoliNotif\Notification;
use Joli\JoliNotif\Notifier;
use Joli\JoliNotif\Notifier\LibNotifyNotifier;
use PHPUnit\Framework\TestCase;

class LibNotifyNotifierTest extends TestCase
class LibNotifyNotifierTest extends NotifierTestCase
{
public function testGetPriority()
{
Expand Down Expand Up @@ -46,12 +45,58 @@ public function testInitialize()
$this->markTestSkipped('Looks like libnotify is not installed');
}

$closureToInitialize = \Closure::bind(static function (LibNotifyNotifier $notifier) {
$notifier->initialize();
}, null, LibNotifyNotifier::class);

$this->assertTrue($notifier->isSupported());
$closureToInitialize($notifier);
}

public function testSendThrowsExceptionWhenNotificationDoesntHaveBody()
{
$notifier = $this->getNotifier();

$notification = new Notification();

try {
$notifier->send($notification);
$this->fail('Expected a InvalidNotificationException');
} catch (\Exception $e) {
$this->assertInstanceOf('Joli\JoliNotif\Exception\InvalidNotificationException', $e);
}
}

public function testSendThrowsExceptionWhenNotificationHasAnEmptyBody()
{
$notifier = $this->getNotifier();

$notification = new Notification();
$notification->setBody('');

try {
$notifier->send($notification);
$this->fail('Expected a InvalidNotificationException');
} catch (\Exception $e) {
$this->assertInstanceOf('Joli\JoliNotif\Exception\InvalidNotificationException', $e);
}
}

public function testSendNotificationWithAllOptions()
{
$notifier = $this->getNotifier();

$notification = (new Notification())
->setBody('I\'m the notification body')
->setTitle('I\'m the notification title')
->addOption('subtitle', 'I\'m the notification subtitle')
->addOption('sound', 'Frog')
->addOption('url', 'https://google.com')
->setIcon($this->getIconDir() . '/image.gif')
;

$result = $notifier->send($notification);

if (!$result) {
$this->markTestSkipped('Notification was not sent');
}

$this->assertTrue($notifier->send($notification));
}

protected function getNotifier(): LibNotifyNotifier
Expand Down
5 changes: 5 additions & 0 deletions tests/Notifier/NotifierTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ abstract class NotifierTestCase extends TestCase
{
abstract protected function getNotifier(): Notifier;

protected function getIconDir(): string
{
return realpath(\dirname(__DIR__) . '/fixtures');
}

/**
* Call protected/private method of a class.
*
Expand Down

0 comments on commit db1ed85

Please sign in to comment.