forked from jolicode/JoliNotif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationTest.php
78 lines (63 loc) · 2.4 KB
/
NotificationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the JoliNotif project.
*
* (c) Loïck Piera <[email protected]>
*
* 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\Notification;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
class NotificationTest extends TestCase
{
public function testItExtractsIconFromPhar()
{
$key = (string) random_int(0, 10000);
$iconContent = $key;
$rootPackage = \dirname(__DIR__);
$iconRelativePath = 'Resources/notification/icon-' . $key . '.png';
$testDir = sys_get_temp_dir() . '/test-jolinotif';
$pharPath = $testDir . '/notification-extract-icon-' . $key . '.phar';
$extractedIconPath = sys_get_temp_dir() . '/jolinotif/' . $iconRelativePath;
if (!is_dir($testDir)) {
mkdir($testDir);
}
$bootstrap = <<<'PHAR_BOOTSTRAP'
<?php
require __DIR__.'/vendor/autoload.php';
$iconPath = '/{{ THE_ICON }}';
$notification = new \Joli\JoliNotif\Notification();
$notification->setBody('My notification');
$notification->setIcon(__DIR__.$iconPath);
PHAR_BOOTSTRAP;
$files = (new Finder())
->in("{$rootPackage}/src")
->in("{$rootPackage}/tests/fixtures")
->in("{$rootPackage}/vendor")
->notPath('vendor/symfony/phpunit-bridge/bin/simple-phpunit')
->files()
;
$phar = new \Phar($pharPath);
$phar->buildFromIterator($files, $rootPackage);
$phar->addFromString('bootstrap.php', str_replace(
'{{ THE_ICON }}',
$iconRelativePath,
$bootstrap
));
$phar->addFromString($iconRelativePath, $iconContent);
$phar->setStub($phar->createDefaultStub('bootstrap.php'));
$this->assertFileExists($pharPath);
exec('php ' . $pharPath);
$this->assertFileExists($extractedIconPath);
$this->assertSame($iconContent, file_get_contents($extractedIconPath));
}
public function testItResolvesRealPathToIcon()
{
$notification = new Notification();
$notification->setIcon(__DIR__ . '/../tests/fixtures/image.gif');
$this->assertFileEquals(__DIR__ . '/fixtures/image.gif', $notification->getIcon());
}
}