-
Notifications
You must be signed in to change notification settings - Fork 178
/
FunctionsTest.php
66 lines (54 loc) · 1.85 KB
/
FunctionsTest.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
<?php
declare(strict_types=1);
namespace League\Plates\Tests\Template;
use League\Plates\Template\Functions;
use PHPUnit\Framework\TestCase;
class FunctionsTest extends TestCase
{
private $functions;
protected function setUp(): void
{
$this->functions = new Functions();
}
public function testCanCreateInstance()
{
$this->assertInstanceOf(Functions::class, $this->functions);
}
public function testAddAndGetFunction()
{
$this->assertInstanceOf(Functions::class, $this->functions->add('upper', 'strtoupper'));
$this->assertSame('strtoupper', $this->functions->get('upper')->getCallback());
}
public function testAddFunctionConflict()
{
// The template function name "upper" is already registered.
$this->expectException(\LogicException::class);
$this->functions->add('upper', 'strtoupper');
$this->functions->add('upper', 'strtoupper');
}
public function testGetNonExistentFunction()
{
// The template function "foo" was not found.
$this->expectException(\LogicException::class);
$this->functions->get('foo');
}
public function testRemoveFunction()
{
$this->functions->add('upper', 'strtoupper');
$this->assertTrue($this->functions->exists('upper'));
$this->functions->remove('upper');
$this->assertFalse($this->functions->exists('upper'));
}
public function testRemoveNonExistentFunction()
{
// The template function "foo" was not found.
$this->expectException(\LogicException::class);
$this->functions->remove('foo');
}
public function testFunctionExists()
{
$this->assertFalse($this->functions->exists('upper'));
$this->functions->add('upper', 'strtoupper');
$this->assertTrue($this->functions->exists('upper'));
}
}