Skip to content

Commit d1ce45e

Browse files
committed
Add tests
1 parent cadd698 commit d1ce45e

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

tests/_support/AlertsTestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Tatter Alerts.
5+
*
6+
* (c) 2021 Tatter Software
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\Support;
13+
14+
use CodeIgniter\Test\CIUnitTestCase;
15+
use Config\Services;
16+
17+
abstract class AlertsTestCase extends CIUnitTestCase
18+
{
19+
protected function setUp(): void
20+
{
21+
Services::reset();
22+
23+
parent::setUp();
24+
}
25+
}

tests/unit/LibraryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Tatter Alerts.
5+
*
6+
* (c) 2021 Tatter Software
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
use Tatter\Alerts\Alerts;
13+
use Tests\Support\AlertsTestCase;
14+
15+
/**
16+
* @internal
17+
*/
18+
final class LibraryTest extends AlertsTestCase
19+
{
20+
public function testAdd()
21+
{
22+
$expected = [
23+
[
24+
'class' => 'fruit',
25+
'text' => 'banana',
26+
],
27+
[
28+
'class' => 'candy',
29+
'text' => 'snickers',
30+
],
31+
];
32+
33+
service('alerts')->add('fruit', 'banana');
34+
service('alerts')->add('candy', 'snickers');
35+
36+
$this->assertSame($expected, session('alerts-queue'));
37+
}
38+
39+
public function testCss()
40+
{
41+
$expected = view('Tatter\Alerts\Views\css', ['prefix' => 'alerts-']);
42+
$result = service('alerts')->css();
43+
44+
$this->assertSame($expected, $result);
45+
}
46+
}

tests/unit/ServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* the LICENSE file that was distributed with this source code.
1010
*/
1111

12-
use CodeIgniter\Test\CIUnitTestCase;
1312
use Tatter\Alerts\Alerts;
13+
use Tests\Support\AlertsTestCase;
1414

1515
/**
1616
* @internal
1717
*/
18-
final class ServiceTest extends CIUnitTestCase
18+
final class ServiceTest extends AlertsTestCase
1919
{
2020
public function testServiceReturnsLibrary()
2121
{

0 commit comments

Comments
 (0)