diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ba456..2270002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Not released yet +* Remove deprecated code: + * Joli\JoliNotif\NotifierFactory + * Joli\JoliNotif\Notifier interface and all implementations + * Toaster notifier and binary + * Joli\JoliNotif\Util\OsHelper class + ## 2.7.3 (2024-09-30) * Fixed SnoreToast and Notifu Windows drivers to be non blocking diff --git a/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll b/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll deleted file mode 100755 index 4542663..0000000 Binary files a/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll and /dev/null differ diff --git a/bin/toaster/Microsoft.WindowsAPICodePack.dll b/bin/toaster/Microsoft.WindowsAPICodePack.dll deleted file mode 100755 index ac86949..0000000 Binary files a/bin/toaster/Microsoft.WindowsAPICodePack.dll and /dev/null differ diff --git a/bin/toaster/README.md b/bin/toaster/README.md deleted file mode 100644 index 1ccca58..0000000 --- a/bin/toaster/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Toaster - -These toaster binary files come from the [nels-o/toaster](https://github.com/nels-o/toaster) -project. All credits for this Windows 8 application goes to [nels-o](https://github.com/nels-o). - -Only the required files were extracted here. If you want to fully test it, -please have a look at the github project instead. diff --git a/bin/toaster/toast.exe b/bin/toaster/toast.exe deleted file mode 100755 index 64af9c8..0000000 Binary files a/bin/toaster/toast.exe and /dev/null differ diff --git a/doc/03-drivers.md b/doc/03-drivers.md index 1155f98..19deab5 100644 --- a/doc/03-drivers.md +++ b/doc/03-drivers.md @@ -98,18 +98,6 @@ binaries in the system temp directory to be able to execute them. Toaster can display notification with a body, a title and an icon. -#### NotifuDriver - -This driver uses the Windows application called Notifu. It works on Windows 7. -Because Notifu is probably not installed on your system, JoliNotif embed the -binary inside the [bin/notifu](bin/notifu) directory. - -When you use JoliNotif inside a phar archive, we take care to extract this -binary in the system temp directory to be able to execute it. - -Notifu can display notification with a body, a title and an icon. Sadly, Notifu -can only display icon with the .ico format. - #### WslNotifySendDriver This driver uses the executable `wsl-notify-send`. diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php deleted file mode 100644 index aaba09f..0000000 --- a/src/Exception/Exception.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Exception; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" interface is deprecated and will be removed in 3.0.', Exception::class); - -/** - * @deprecated since 2.7, will be removed in 3.0 - */ -interface Exception -{ -} diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 64f5b8a..9d50721 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -11,6 +11,6 @@ namespace Joli\JoliNotif\Exception; -interface ExceptionInterface extends Exception, \Throwable +interface ExceptionInterface extends \Throwable { } diff --git a/src/Exception/NoSupportedNotifierException.php b/src/Exception/NoSupportedNotifierException.php deleted file mode 100644 index 80d6e9b..0000000 --- a/src/Exception/NoSupportedNotifierException.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Exception; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', NoSupportedNotifierException::class); - -/** - * @deprecated since 2.7, will be removed in 3.0 - */ -class NoSupportedNotifierException extends \RuntimeException implements Exception -{ - public function __construct( - string $message = 'No supported notifier', - int $code = 0, - ?\Throwable $previous = null, - ) { - parent::__construct($message, $code, $previous); - } -} diff --git a/src/LegacyNotifier.php b/src/LegacyNotifier.php deleted file mode 100644 index 36d743c..0000000 --- a/src/LegacyNotifier.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif; - -use Joli\JoliNotif\Driver\DriverInterface; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0. Use %s', LegacyNotifier::class, DefaultNotifier::class); - -/** - * @deprecated since 2.7, will be removed in 3.0. Use DefaultNotifier instead. - */ -class LegacyNotifier extends DefaultNotifier implements Notifier -{ - /** @param list $drivers */ - public function __construct(array $drivers) - { - parent::__construct(null, $drivers, true); - - $this->loadDriver(); - } - - public function isSupported(): bool - { - return true; - } - - public function getPriority(): int - { - return Notifier::PRIORITY_HIGH; - } -} diff --git a/src/Notifier.php b/src/Notifier.php deleted file mode 100644 index 5f274e6..0000000 --- a/src/Notifier.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif; - -use Joli\JoliNotif\Driver\DriverInterface; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" interface is deprecated and will be removed in 3.0. Use "%s" instead.', Notifier::class, NotifierInterface::class); - -/** - * @deprecated since 2.7, use NotifierInterface instead - */ -interface Notifier extends NotifierInterface, DriverInterface -{ -} diff --git a/src/Notifier/AppleScriptNotifier.php b/src/Notifier/AppleScriptNotifier.php deleted file mode 100644 index 379b81b..0000000 --- a/src/Notifier/AppleScriptNotifier.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\AppleScriptDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', AppleScriptNotifier::class); - -/** - * This notifier can be used on Mac OS X 10.9+. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class AppleScriptNotifier extends AppleScriptDriver implements Notifier -{ -} diff --git a/src/Notifier/BinaryProvider.php b/src/Notifier/BinaryProvider.php deleted file mode 100644 index 190c7d7..0000000 --- a/src/Notifier/BinaryProvider.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" interface is deprecated and will be removed in 3.0.', BinaryProvider::class); - -/** - * Interface implemented by notifiers when they provide their own binaries in - * case the executable is not natively supported. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -interface BinaryProvider -{ - /** - * Return whether the embedded binary can be used on the current system. - */ - public function canBeUsed(): bool; - - /** - * Return the absolute path of the directory containing all the files. - */ - public function getRootDir(): string; - - /** - * Return the path of the embedded binary. - * - * The path should be relative to the directory pointed by getRootDir(). - */ - public function getEmbeddedBinary(): string; - - /** - * Return an array of files that should be extracted when JoliNotif is - * used inside a phar archive. - * - * All paths should be relative to the directory pointed by getRootDir(). - * - * @return list - */ - public function getExtraFiles(): array; -} diff --git a/src/Notifier/CliBasedNotifier.php b/src/Notifier/CliBasedNotifier.php deleted file mode 100644 index 26deb6f..0000000 --- a/src/Notifier/CliBasedNotifier.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\AbstractCliBasedDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', CliBasedNotifier::class); - -/** - * @deprecated since 2.7, will be removed in 3.0 - */ -abstract class CliBasedNotifier extends AbstractCliBasedDriver implements Notifier -{ -} diff --git a/src/Notifier/GrowlNotifyNotifier.php b/src/Notifier/GrowlNotifyNotifier.php deleted file mode 100644 index 94fd5c7..0000000 --- a/src/Notifier/GrowlNotifyNotifier.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\GrowlNotifyDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', GrowlNotifyNotifier::class); - -/** - * This notifier can be used on Mac OS X when growlnotify command is available. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class GrowlNotifyNotifier extends GrowlNotifyDriver implements Notifier -{ -} diff --git a/src/Notifier/KDialogNotifier.php b/src/Notifier/KDialogNotifier.php deleted file mode 100644 index afe661d..0000000 --- a/src/Notifier/KDialogNotifier.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\KDialogDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', KDialogNotifier::class); - -/** - * This notifier can be used on Linux distributions running KDE, using the command kdialog. - * This command is shipped by default with KDE. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class KDialogNotifier extends KDialogDriver implements Notifier -{ -} diff --git a/src/Notifier/LibNotifyNotifier.php b/src/Notifier/LibNotifyNotifier.php deleted file mode 100644 index 59c71a4..0000000 --- a/src/Notifier/LibNotifyNotifier.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\LibNotifyDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', LibNotifyNotifier::class); - -/** - * @deprecated since 2.7, will be removed in 3.0 - */ -class LibNotifyNotifier extends LibNotifyDriver implements Notifier -{ -} diff --git a/src/Notifier/NotifuNotifier.php b/src/Notifier/NotifuNotifier.php deleted file mode 100644 index d2f8620..0000000 --- a/src/Notifier/NotifuNotifier.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\NotifuDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', NotifuNotifier::class); - -/** - * This notifier can be used on Windows Seven and provides its own binaries if - * not natively available. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class NotifuNotifier extends NotifuDriver implements Notifier -{ -} diff --git a/src/Notifier/NotifySendNotifier.php b/src/Notifier/NotifySendNotifier.php deleted file mode 100644 index 9eed887..0000000 --- a/src/Notifier/NotifySendNotifier.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\NotifySendDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', NotifySendNotifier::class); - -/** - * This notifier can be used on most Linux distributions, using the command notify-send. - * This command is packaged in libnotify-bin. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class NotifySendNotifier extends NotifySendDriver implements Notifier -{ -} diff --git a/src/Notifier/NullNotifier.php b/src/Notifier/NullNotifier.php deleted file mode 100644 index ba379d3..0000000 --- a/src/Notifier/NullNotifier.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Notification; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', NullNotifier::class); - -/** - * @deprecated since 2.7, will be removed in 3.0 - */ -class NullNotifier implements Notifier -{ - public function isSupported(): bool - { - return true; - } - - public function getPriority(): int - { - return static::PRIORITY_LOW; - } - - public function send(Notification $notification): bool - { - return false; - } -} diff --git a/src/Notifier/SnoreToastNotifier.php b/src/Notifier/SnoreToastNotifier.php deleted file mode 100644 index f8e50c7..0000000 --- a/src/Notifier/SnoreToastNotifier.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\SnoreToastDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', SnoreToastNotifier::class); - -/** - * This notifier can be used on Windows Eight and higher and provides its own - * binaries if not natively available. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class SnoreToastNotifier extends SnoreToastDriver implements Notifier -{ -} diff --git a/src/Notifier/TerminalNotifierNotifier.php b/src/Notifier/TerminalNotifierNotifier.php deleted file mode 100644 index d58e235..0000000 --- a/src/Notifier/TerminalNotifierNotifier.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Driver\TerminalNotifierDriver; -use Joli\JoliNotif\Notifier; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', TerminalNotifierNotifier::class); - -/** - * This notifier can be used on Mac OS X 10.8, or higher, using the - * terminal-notifier binary. - * - * @deprecated since 2.7, will be removed in 3.0 - */ -class TerminalNotifierNotifier extends TerminalNotifierDriver implements Notifier -{ -} diff --git a/src/Notifier/ToasterNotifier.php b/src/Notifier/ToasterNotifier.php deleted file mode 100644 index d1f936f..0000000 --- a/src/Notifier/ToasterNotifier.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Notification; -use Joli\JoliNotif\Notifier; -use JoliCode\PhpOsHelper\OsHelper; - -trigger_deprecation('jolicode/jolinotif', '2.3', 'The "%s" class is deprecated and will be removed in 3.0.', ToasterNotifier::class); - -/** - * This notifier can be used on Windows Eight and higher and provides its own - * binaries if not natively available. - * - * @deprecated since 2.3, will be removed in 3.0 - */ -class ToasterNotifier extends CliBasedNotifier implements BinaryProvider -{ - public function getBinary(): string - { - return 'toast'; - } - - public function getPriority(): int - { - return static::PRIORITY_MEDIUM; - } - - public function canBeUsed(): bool - { - return - (OsHelper::isWindows() && OsHelper::isWindowsEightOrHigher()) - || OsHelper::isWindowsSubsystemForLinux(); - } - - public function getRootDir(): string - { - return \dirname(__DIR__, 2) . '/bin/toaster'; - } - - public function getEmbeddedBinary(): string - { - return 'toast.exe'; - } - - public function getExtraFiles(): array - { - return [ - 'Microsoft.WindowsAPICodePack.dll', - 'Microsoft.WindowsAPICodePack.Shell.dll', - ]; - } - - protected function getCommandLineArguments(Notification $notification): array - { - $arguments = [ - '-m', - $notification->getBody() ?? '', - ]; - - if ($notification->getTitle()) { - $arguments[] = '-t'; - $arguments[] = $notification->getTitle(); - } - - if ($notification->getIcon()) { - $arguments[] = '-p'; - $arguments[] = $notification->getIcon(); - } - - return $arguments; - } -} diff --git a/src/Notifier/WslNotifySendNotifier.php b/src/Notifier/WslNotifySendNotifier.php deleted file mode 100644 index 6d398eb..0000000 --- a/src/Notifier/WslNotifySendNotifier.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Notifier; - -use Joli\JoliNotif\Notification; -use JoliCode\PhpOsHelper\OsHelper; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0.', WslNotifySendNotifier::class); - -/** - * This notifier can be used on Windows Subsystem for Linux and provides notifications using the `wsl-notify-send` binary. - * - * @see https://github.com/stuartleeks/wsl-notify-send the source code of the `wsl-notify-send` binary - * @deprecated since 2.7, will be removed in 3.0 - */ -class WslNotifySendNotifier extends CliBasedNotifier implements BinaryProvider -{ - public function getBinary(): string - { - return 'wsl-notify-send'; - } - - public function getPriority(): int - { - return static::PRIORITY_HIGH; - } - - public function canBeUsed(): bool - { - return OsHelper::isWindowsSubsystemForLinux(); - } - - public function getRootDir(): string - { - return \dirname(__DIR__, 2) . '/bin/wsl-notify-send'; - } - - public function getEmbeddedBinary(): string - { - return 'wsl-notify-send.exe'; - } - - public function getExtraFiles(): array - { - return []; - } - - protected function getCommandLineArguments(Notification $notification): array - { - $arguments = [ - '--appId', - 'JoliNotif', - $notification->getBody() ?? '', - ]; - - if ($notification->getTitle()) { - $arguments[] = '-c'; - $arguments[] = $notification->getTitle(); - } - - return $arguments; - } -} diff --git a/src/NotifierFactory.php b/src/NotifierFactory.php deleted file mode 100644 index 02ff457..0000000 --- a/src/NotifierFactory.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif; - -use Joli\JoliNotif\Exception\NoSupportedNotifierException; -use Joli\JoliNotif\Notifier\AppleScriptNotifier; -use Joli\JoliNotif\Notifier\GrowlNotifyNotifier; -use Joli\JoliNotif\Notifier\KDialogNotifier; -use Joli\JoliNotif\Notifier\LibNotifyNotifier; -use Joli\JoliNotif\Notifier\NotifuNotifier; -use Joli\JoliNotif\Notifier\NotifySendNotifier; -use Joli\JoliNotif\Notifier\SnoreToastNotifier; -use Joli\JoliNotif\Notifier\TerminalNotifierNotifier; -use Joli\JoliNotif\Notifier\WslNotifySendNotifier; -use JoliCode\PhpOsHelper\OsHelper; - -trigger_deprecation('jolicode/jolinotif', '2.7', 'The "%s" class is deprecated and will be removed in 3.0. Use the %s class directly', NotifierFactory::class, DefaultNotifier::class); - -/** - * @deprecated since 2.7, will be removed in 3.0. Use the DefaultNotifier class directly. - */ -class NotifierFactory -{ - /** - * @param Notifier[] $notifiers - */ - public static function create(array $notifiers = []): Notifier - { - return new LegacyNotifier($notifiers); - } - - /** - * @param Notifier[] $notifiers - */ - public static function createOrThrowException(array $notifiers = []): Notifier - { - $legacyNotifier = new LegacyNotifier($notifiers); - - if (!$legacyNotifier->getDriver()) { - throw new NoSupportedNotifierException(); - } - - return $legacyNotifier; - } - - /** - * @return Notifier[] - */ - public static function getDefaultNotifiers(): array - { - // Don't retrieve notifiers which are certainly not supported on this - // system. This helps to lower the number of process to run. - if (OsHelper::isUnix() && !OsHelper::isWindowsSubsystemForLinux()) { - return self::getUnixNotifiers(); - } - - return self::getWindowsNotifiers(); - } - - /** - * @return Notifier[] - */ - private static function getUnixNotifiers(): array - { - return [ - new LibNotifyNotifier(), - new GrowlNotifyNotifier(), - new TerminalNotifierNotifier(), - new AppleScriptNotifier(), - new KDialogNotifier(), - new NotifySendNotifier(), - ]; - } - - /** - * @return Notifier[] - */ - private static function getWindowsNotifiers(): array - { - return [ - new SnoreToastNotifier(), - new NotifuNotifier(), - new WslNotifySendNotifier(), - ]; - } -} diff --git a/src/Util/OsHelper.php b/src/Util/OsHelper.php deleted file mode 100644 index 4c54c23..0000000 --- a/src/Util/OsHelper.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\Util; - -use JoliCode\PhpOsHelper\OsHelper as BaseOsHelper; - -trigger_deprecation('jolicode/jolinotif', '2.6', 'The "%s" class is deprecated and will be removed in 3.0. Use "%s" from jolicode/php-os-helper instead.', OsHelper::class, BaseOsHelper::class); - -/** - * @deprecated since 2.6, use OsHelper from jolicode/php-os-helper instead - */ -class OsHelper extends BaseOsHelper -{ -} diff --git a/tests/DefaultNotifierTest.php b/tests/DefaultNotifierTest.php index 7fe4056..633f6f9 100644 --- a/tests/DefaultNotifierTest.php +++ b/tests/DefaultNotifierTest.php @@ -27,9 +27,6 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; -/** - * @group legacy - */ class DefaultNotifierTest extends TestCase { public function testCreateDefaultNotifier() diff --git a/tests/Notifier/AppleScriptNotifierTest.php b/tests/Notifier/AppleScriptNotifierTest.php deleted file mode 100644 index 8a5db26..0000000 --- a/tests/Notifier/AppleScriptNotifierTest.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\AppleScriptNotifier; -use Joli\JoliNotif\Util\OsHelper; - -/** - * @group legacy - */ -class AppleScriptNotifierTest extends NotifierTestCase -{ - use CliBasedNotifierTestTrait; - - private const BINARY = 'osascript'; - - public function testIsSupported() - { - $notifier = $this->getNotifier(); - - if (OsHelper::isMacOS() && version_compare(OsHelper::getMacOSVersion(), '10.9.0', '>=')) { - $this->assertTrue($notifier->isSupported()); - } else { - $this->assertFalse($notifier->isSupported()); - } - } - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_LOW, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new AppleScriptNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body"' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body" with title "I'\''m the notification title"' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithASubtitle(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body" subtitle "I'\''m the notification subtitle"' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithASound(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body" sound name "Frog"' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body"' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAllOptions(): string - { - return <<<'CLI' - 'osascript' '-e' 'display notification "I'\''m the notification body" with title "I'\''m the notification title" subtitle "I'\''m the notification subtitle" sound name "Frog"' - CLI; - } -} diff --git a/tests/Notifier/BinaryProviderTestTrait.php b/tests/Notifier/BinaryProviderTestTrait.php deleted file mode 100644 index 4f00242..0000000 --- a/tests/Notifier/BinaryProviderTestTrait.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -/** - * Classes using this trait should extend NotifierTestCase. - */ -trait BinaryProviderTestTrait -{ - public function testRootDirectoryExists() - { - $notifier = $this->getNotifier(); - - $this->assertDirectoryExists($notifier->getRootDir()); - } - - public function testEmbeddedBinaryExists() - { - $notifier = $this->getNotifier(); - - $this->assertFileExists($notifier->getRootDir() . \DIRECTORY_SEPARATOR . $notifier->getEmbeddedBinary()); - } - - public function testExtraFilesExist() - { - $notifier = $this->getNotifier(); - - if (!$notifier->getExtraFiles()) { - // Nothing to test here - $this->addToAssertionCount(1); - - return; - } - - foreach ($notifier->getExtraFiles() as $file) { - $this->assertFileExists($notifier->getRootDir() . \DIRECTORY_SEPARATOR . $file); - } - } -} diff --git a/tests/Notifier/CliBasedNotifierTestTrait.php b/tests/Notifier/CliBasedNotifierTestTrait.php deleted file mode 100644 index d17a646..0000000 --- a/tests/Notifier/CliBasedNotifierTestTrait.php +++ /dev/null @@ -1,165 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notification; -use Joli\JoliNotif\Util\OsHelper; -use Symfony\Component\Process\Process; - -/** - * Classes using this trait should define a BINARY constant and extend - * NotifierTestCase. - */ -trait CliBasedNotifierTestTrait -{ - public function testIsSupported() - { - if (OsHelper::isUnix()) { - $commandLine = 'command -v ' . static::BINARY . ' >/dev/null 2>&1'; - } else { - $commandLine = 'where ' . static::BINARY; - } - - passthru($commandLine, $return); - $supported = 0 === $return; - - $this->assertSame($supported, $this->getNotifier()->isSupported()); - } - - /** - * @dataProvider provideValidNotifications - */ - public function testConfigureProcessAcceptAnyValidNotification(Notification $notification, string $expectedCommandLine) - { - try { - $arguments = $this->invokeMethod($this->getNotifier(), 'getCommandLineArguments', [$notification]); - - $this->assertSame($expectedCommandLine, (new Process(array_merge([self::BINARY], $arguments)))->getCommandLine()); - } catch (\Exception $e) { - $this->fail($e->getMessage()); - } - } - - public function provideValidNotifications(): array - { - $iconDir = $this->getIconDir(); - - return [ - [ - (new Notification()) - ->setBody('I\'m the notification body'), - $this->getExpectedCommandLineForNotification(), - ], - [ - (new Notification()) - ->setBody('I\'m the notification body') - ->setTitle('I\'m the notification title'), - $this->getExpectedCommandLineForNotificationWithATitle(), - ], - [ - (new Notification()) - ->setBody('I\'m the notification body') - ->addOption('subtitle', 'I\'m the notification subtitle'), - $this->getExpectedCommandLineForNotificationWithASubtitle(), - ], - [ - (new Notification()) - ->setBody('I\'m the notification body') - ->addOption('sound', 'Frog'), - $this->getExpectedCommandLineForNotificationWithASound(), - ], - [ - (new Notification()) - ->setBody('I\'m the notification body') - ->addOption('url', 'https://google.com'), - $this->getExpectedCommandLineForNotificationWithAnUrl(), - ], - [ - (new Notification()) - ->setBody('I\'m the notification body') - ->setIcon($iconDir . '/image.gif'), - $this->getExpectedCommandLineForNotificationWithAnIcon(), - ], - [ - (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($iconDir . '/image.gif'), - $this->getExpectedCommandLineForNotificationWithAllOptions(), - ], - ]; - } - - 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); - } - } - - abstract protected function getExpectedCommandLineForNotification(): string; - - abstract protected function getExpectedCommandLineForNotificationWithATitle(): string; - - /** - * Subtitle is supported only on few notifier. - */ - protected function getExpectedCommandLineForNotificationWithASubtitle(): string - { - return $this->getExpectedCommandLineForNotification(); - } - - /** - * Sound is supported only on few notifier. - */ - protected function getExpectedCommandLineForNotificationWithASound(): string - { - return $this->getExpectedCommandLineForNotification(); - } - - /** - * Sound is supported only on few notifier. - */ - protected function getExpectedCommandLineForNotificationWithAnUrl(): string - { - return $this->getExpectedCommandLineForNotification(); - } - - abstract protected function getExpectedCommandLineForNotificationWithAnIcon(): string; - - abstract protected function getExpectedCommandLineForNotificationWithAllOptions(): string; -} diff --git a/tests/Notifier/GrowlNotifyNotifierTest.php b/tests/Notifier/GrowlNotifyNotifierTest.php deleted file mode 100644 index 9659753..0000000 --- a/tests/Notifier/GrowlNotifyNotifierTest.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\GrowlNotifyNotifier; - -/** - * @group legacy - */ -class GrowlNotifyNotifierTest extends NotifierTestCase -{ - use CliBasedNotifierTestTrait; - - private const BINARY = 'growlnotify'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_HIGH, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new GrowlNotifyNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'growlnotify' '--message' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'growlnotify' '--message' 'I'\''m the notification body' '--title' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - $iconDir = $this->getIconDir(); - - return <<getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; - -/** - * @group legacy - */ -class KDialogNotifierTest extends NotifierTestCase -{ - use CliBasedNotifierTestTrait; - - private const BINARY = 'kdialog'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_HIGH, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new Notifier\KDialogNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'kdialog' '--passivepopup' 'I'\''m the notification body' '5' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'kdialog' '--title' 'I'\''m the notification title' '--passivepopup' 'I'\''m the notification body' '5' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - return <<<'CLI' - 'kdialog' '--passivepopup' 'I'\''m the notification body' '5' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAllOptions(): string - { - return <<<'CLI' - 'kdialog' '--title' 'I'\''m the notification title' '--passivepopup' 'I'\''m the notification body' '5' - CLI; - } -} diff --git a/tests/Notifier/LibNotifyNotifierTest.php b/tests/Notifier/LibNotifyNotifierTest.php deleted file mode 100644 index 0539412..0000000 --- a/tests/Notifier/LibNotifyNotifierTest.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Exception\InvalidNotificationException; -use Joli\JoliNotif\Notification; -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\LibNotifyNotifier; - -/** - * @group legacy - */ -class LibNotifyNotifierTest extends NotifierTestCase -{ - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_HIGH, $notifier->getPriority()); - } - - public function testSendWithEmptyBody() - { - $notifier = $this->getNotifier(); - - $this->expectException(InvalidNotificationException::class); - $this->expectExceptionMessage('Notification body can not be empty'); - $notifier->send(new Notification()); - } - - /** - * @requires extension ffi - */ - public function testInitialize() - { - $notifier = $this->getNotifier(); - - if (!$notifier::isLibraryExists()) { - $this->markTestSkipped('Looks like libnotify is not installed'); - } - - $this->assertTrue($notifier->isSupported()); - } - - 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); - } - } - - /** - * @requires extension ffi - */ - 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 - { - return new LibNotifyNotifier(); - } -} diff --git a/tests/Notifier/NotifierTestCase.php b/tests/Notifier/NotifierTestCase.php deleted file mode 100644 index b64471d..0000000 --- a/tests/Notifier/NotifierTestCase.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use PHPUnit\Framework\TestCase; - -/** - * @group legacy - */ -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. - * - * @param object $object instantiated object that we will run method on - * @param string $methodName Method name to call - * @param array $parameters array of parameters to pass into method - * - * @return mixed method return - */ - protected function invokeMethod($object, string $methodName, array $parameters = []) - { - $reflection = new \ReflectionClass($object::class); - $method = $reflection->getMethod($methodName); - $method->setAccessible(true); - - return $method->invokeArgs($object, $parameters); - } -} diff --git a/tests/Notifier/NotifuNotifierTest.php b/tests/Notifier/NotifuNotifierTest.php deleted file mode 100644 index 5266fb6..0000000 --- a/tests/Notifier/NotifuNotifierTest.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\NotifuNotifier; - -/** - * @group legacy - */ -class NotifuNotifierTest extends NotifierTestCase -{ - use BinaryProviderTestTrait; - use CliBasedNotifierTestTrait; - - private const BINARY = 'notifu'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_LOW, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new NotifuNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'notifu' '/m' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'notifu' '/m' 'I'\''m the notification body' '/p' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - $iconDir = $this->getIconDir(); - - return <<getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\NotifySendNotifier; - -/** - * @group legacy - */ -class NotifySendNotifierTest extends NotifierTestCase -{ - use CliBasedNotifierTestTrait; - - private const BINARY = 'notify-send'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_MEDIUM, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new NotifySendNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'notify-send' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'notify-send' 'I'\''m the notification title' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - $iconDir = $this->getIconDir(); - - return <<getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notification; -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\NullNotifier; - -/** - * @group legacy - */ -class NullNotifierTest extends NotifierTestCase -{ - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_LOW, $notifier->getPriority()); - } - - public function testIsSupported() - { - $this->assertTrue($this->getNotifier()->isSupported()); - } - - public function testSendReturnsFalse() - { - $notifier = $this->getNotifier(); - - $notification = new Notification(); - $notification->setBody('The notification body'); - - $this->assertFalse($notifier->send($notification)); - } - - protected function getNotifier(): Notifier - { - return new NullNotifier(); - } -} diff --git a/tests/Notifier/SnoreToastNotifierTest.php b/tests/Notifier/SnoreToastNotifierTest.php deleted file mode 100644 index 8e255d1..0000000 --- a/tests/Notifier/SnoreToastNotifierTest.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\SnoreToastNotifier; - -/** - * @group legacy - */ -class SnoreToastNotifierTest extends NotifierTestCase -{ - use BinaryProviderTestTrait; - use CliBasedNotifierTestTrait; - - private const BINARY = 'snoretoast'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_MEDIUM, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new SnoreToastNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'snoretoast' '-m' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'snoretoast' '-m' 'I'\''m the notification body' '-t' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - $iconDir = $this->getIconDir(); - - return <<getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\TerminalNotifierNotifier; -use Joli\JoliNotif\Util\OsHelper; - -/** - * @group legacy - */ -class TerminalNotifierNotifierTest extends NotifierTestCase -{ - use CliBasedNotifierTestTrait; - - private const BINARY = 'terminal-notifier'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_MEDIUM, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new TerminalNotifierNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'terminal-notifier' '-message' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'terminal-notifier' '-message' 'I'\''m the notification body' '-title' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnUrl(): string - { - return <<<'CLI' - 'terminal-notifier' '-message' 'I'\''m the notification body' '-open' 'https://google.com' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - if (OsHelper::isMacOS() && version_compare(OsHelper::getMacOSVersion(), '10.9.0', '>=')) { - $iconDir = $this->getIconDir(); - - return <<=')) { - $iconDir = $this->getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\ToasterNotifier; - -/** - * @group legacy - */ -class ToasterNotifierTest extends NotifierTestCase -{ - use BinaryProviderTestTrait; - use CliBasedNotifierTestTrait; - - private const BINARY = 'toast'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_MEDIUM, $notifier->getPriority()); - } - - protected function getNotifier(): Notifier - { - return new ToasterNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'toast' '-m' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'toast' '-m' 'I'\''m the notification body' '-t' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - $iconDir = $this->getIconDir(); - - return <<getIconDir(); - - return << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Notifier; - -use Joli\JoliNotif\Notifier; -use Joli\JoliNotif\Notifier\WslNotifySendNotifier; - -/** - * @group legacy - */ -class WslNotifySendNotifierTest extends NotifierTestCase -{ - use BinaryProviderTestTrait; - use CliBasedNotifierTestTrait; - - private const BINARY = 'wsl-notify-send'; - - public function testGetBinary() - { - $notifier = $this->getNotifier(); - - $this->assertSame(self::BINARY, $notifier->getBinary()); - } - - public function testGetPriority() - { - $notifier = $this->getNotifier(); - - $this->assertSame(Notifier::PRIORITY_HIGH, $notifier->getPriority()); - } - - protected function getNotifier(): WslNotifySendNotifier - { - return new WslNotifySendNotifier(); - } - - protected function getExpectedCommandLineForNotification(): string - { - return <<<'CLI' - 'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithATitle(): string - { - return <<<'CLI' - 'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' '-c' 'I'\''m the notification title' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAnIcon(): string - { - return <<<'CLI' - 'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' - CLI; - } - - protected function getExpectedCommandLineForNotificationWithAllOptions(): string - { - return <<<'CLI' - 'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' '-c' 'I'\''m the notification title' - CLI; - } -} diff --git a/tests/NotifierFactoryTest.php b/tests/NotifierFactoryTest.php deleted file mode 100644 index cf08c60..0000000 --- a/tests/NotifierFactoryTest.php +++ /dev/null @@ -1,224 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests; - -use Joli\JoliNotif\Driver\AppleScriptDriver; -use Joli\JoliNotif\Driver\GrowlNotifyDriver; -use Joli\JoliNotif\Driver\KDialogDriver; -use Joli\JoliNotif\Driver\LibNotifyDriver; -use Joli\JoliNotif\Driver\NotifuDriver; -use Joli\JoliNotif\Driver\NotifySendDriver; -use Joli\JoliNotif\Driver\SnoreToastDriver; -use Joli\JoliNotif\Driver\TerminalNotifierDriver; -use Joli\JoliNotif\Driver\WslNotifySendDriver; -use Joli\JoliNotif\Exception\NoSupportedNotifierException; -use Joli\JoliNotif\LegacyNotifier; -use Joli\JoliNotif\Notifier\AppleScriptNotifier; -use Joli\JoliNotif\Notifier\GrowlNotifyNotifier; -use Joli\JoliNotif\Notifier\KDialogNotifier; -use Joli\JoliNotif\Notifier\LibNotifyNotifier; -use Joli\JoliNotif\Notifier\NotifuNotifier; -use Joli\JoliNotif\Notifier\NotifySendNotifier; -use Joli\JoliNotif\Notifier\SnoreToastNotifier; -use Joli\JoliNotif\Notifier\TerminalNotifierNotifier; -use Joli\JoliNotif\Notifier\WslNotifySendNotifier; -use Joli\JoliNotif\NotifierFactory; -use Joli\JoliNotif\tests\fixtures\ConfigurableNotifier; -use JoliCode\PhpOsHelper\OsHelper; -use PHPUnit\Framework\TestCase; - -/** - * @group legacy - */ -class NotifierFactoryTest extends TestCase -{ - public function testGetDefaultNotifiers() - { - $notifiers = NotifierFactory::getDefaultNotifiers(); - - if (OsHelper::isUnix()) { - $expectedNotifierClasses = [ - LibNotifyNotifier::class, - GrowlNotifyNotifier::class, - TerminalNotifierNotifier::class, - AppleScriptNotifier::class, - KDialogNotifier::class, - NotifySendNotifier::class, - ]; - } else { - $expectedNotifierClasses = [ - SnoreToastNotifier::class, - NotifuNotifier::class, - WslNotifySendNotifier::class, - ]; - } - - $this->assertNotifierClasses($expectedNotifierClasses, $notifiers); - } - - public function testCreateUsesDefaultNotifiers() - { - $notifier = NotifierFactory::create(); - - if (OsHelper::isUnix()) { - $expectedDriverClasses = [ - LibNotifyDriver::class, - GrowlNotifyDriver::class, - TerminalNotifierDriver::class, - AppleScriptDriver::class, - KDialogDriver::class, - NotifySendDriver::class, - ]; - } else { - $expectedDriverClasses = [ - SnoreToastDriver::class, - NotifuDriver::class, - WslNotifySendDriver::class, - ]; - } - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertContains($driver::class, $expectedDriverClasses); - } - - public function testCreateUsesGivenNotifiers() - { - $notifier = NotifierFactory::create([ - new ConfigurableNotifier(true), - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertInstanceOf(ConfigurableNotifier::class, $driver); - } - - public function testCreateWithNoSupportedNotifiersReturnsANullNotifier() - { - $notifier = NotifierFactory::create([ - new ConfigurableNotifier(false), - new ConfigurableNotifier(false), - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertNull($driver); - } - - public function testCreateUsesTheOnlySupportedNotifier() - { - $expectedNotifier = new ConfigurableNotifier(true); - - $notifier = NotifierFactory::create([ - $expectedNotifier, - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertSame($expectedNotifier, $driver); - } - - public function testCreateUsesTheFirstSupportedNotifierWhenNoPrioritiesAreGiven() - { - $notifier1 = new ConfigurableNotifier(false); - $notifier2 = new ConfigurableNotifier(true); - $notifier3 = new ConfigurableNotifier(true); - $notifier4 = new ConfigurableNotifier(true); - - $notifier = NotifierFactory::create([ - $notifier1, - $notifier2, - $notifier3, - $notifier4, - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertSame($notifier2, $driver); - } - - public function testCreateUsesTheBestSupportedNotifier() - { - $notifier1 = new ConfigurableNotifier(false); - $notifier2 = new ConfigurableNotifier(true, 5); - $notifier3 = new ConfigurableNotifier(true, 8); - $notifier4 = new ConfigurableNotifier(false); - $notifier5 = new ConfigurableNotifier(true, 6); - - $notifier = NotifierFactory::create([ - $notifier1, - $notifier2, - $notifier3, - $notifier4, - $notifier5, - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertSame($notifier3, $driver); - } - - public function testCreateUsesTheFirstOfTheBestSupportedNotifiers() - { - $notifier1 = new ConfigurableNotifier(false); - $notifier2 = new ConfigurableNotifier(true, 5); - $notifier3 = new ConfigurableNotifier(true, 8); - $notifier4 = new ConfigurableNotifier(false); - $notifier5 = new ConfigurableNotifier(true, 8); - - $notifier = NotifierFactory::create([ - $notifier1, - $notifier2, - $notifier3, - $notifier4, - $notifier5, - ]); - - $this->assertInstanceOf(LegacyNotifier::class, $notifier); - - $driver = $notifier->getDriver(); - - $this->assertSame($notifier3, $driver); - } - - public function testCreateOrThrowExceptionWithNoSupportedNotifiersThrowsException() - { - $this->expectException(NoSupportedNotifierException::class); - - NotifierFactory::createOrThrowException([ - new ConfigurableNotifier(false), - new ConfigurableNotifier(false), - ]); - } - - private function assertNotifierClasses(array $expectedNotifierClasses, array $notifiers) - { - $expectedCount = \count($expectedNotifierClasses); - $this->assertSame($expectedCount, \count($notifiers)); - - for ($i = 0; $i < $expectedCount; ++$i) { - $this->assertInstanceOf($expectedNotifierClasses[$i], $notifiers[$i]); - } - } -} diff --git a/tests/Util/OsHelperTest.php b/tests/Util/OsHelperTest.php deleted file mode 100644 index 02d72c3..0000000 --- a/tests/Util/OsHelperTest.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Joli\JoliNotif\tests\Util; - -use Joli\JoliNotif\Util\OsHelper; -use PHPUnit\Framework\TestCase; - -/** - * @group legacy - */ -class OsHelperTest extends TestCase -{ - public function testIsUnix() - { - if ('\\' === \DIRECTORY_SEPARATOR) { - $this->assertFalse(OsHelper::isUnix()); - } - - if ('/' === \DIRECTORY_SEPARATOR) { - $this->assertTrue(OsHelper::isUnix()); - } - } - - public function testIsWindows() - { - if ('\\' === \DIRECTORY_SEPARATOR) { - $this->assertTrue(OsHelper::isWindows()); - } - - if ('/' === \DIRECTORY_SEPARATOR) { - $this->assertFalse(OsHelper::isWindows()); - } - } - - public function testIsWindowsSeven() - { - if (!OsHelper::isWindows()) { - $this->markTestSkipped('Can only be run on Windows'); - } - - $isSeven = '6.1' === php_uname('r'); - - $this->assertSame($isSeven, OsHelper::isWindowsSeven()); - } - - public function testIsWindowsEightOrHigher() - { - if (!OsHelper::isWindows()) { - $this->markTestSkipped('Can only be run on Windows'); - } - - $eightOrHigher = [ - '6.2', // 8 - '6.3', // 8.1 - '6.4', // 10 - ]; - $isEightOrHigher = \in_array(php_uname('r'), $eightOrHigher, true); - - $this->assertSame($isEightOrHigher, OsHelper::isWindowsEightOrHigher()); - } - - public function testIsMacOS() - { - $uname = php_uname(); - $isDarwin = 'Darwin' === substr($uname, 0, 6); - - $this->assertSame($isDarwin, OsHelper::isMacOS()); - } - - public function testGetMacOSVersion() - { - if (!OsHelper::isMacOS()) { - $this->markTestSkipped('Can only be run on MacOS'); - } - - $expectedMacOsVersion = exec('sw_vers -productVersion', $output); - - $macOsVersion = OsHelper::getMacOSVersion(); - - $this->assertRegExp('#\d{1,2}\.\d{1,2}(\.\d{1,2})?#', $macOsVersion); - $this->assertSame($expectedMacOsVersion, $macOsVersion); - } -}