-
Notifications
You must be signed in to change notification settings - Fork 178
/
FuncTest.php
73 lines (61 loc) · 1.92 KB
/
FuncTest.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
<?php
declare(strict_types=1);
namespace League\Plates\Tests\Template;
use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;
use League\Plates\Template\Func;
use PHPUnit\Framework\TestCase;
class FuncTest extends TestCase
{
private $function;
protected function setUp(): void
{
$this->function = new Func('uppercase', function ($string) {
return strtoupper($string);
});
}
public function testCanCreateInstance()
{
$this->assertInstanceOf(Func::class, $this->function);
}
public function testSetAndGetName()
{
$this->assertInstanceOf(Func::class, $this->function->setName('test'));
$this->assertSame('test', $this->function->getName());
}
public function testSetInvalidName()
{
// Not a valid function name.
$this->expectException(\LogicException::class);
$this->function->setName('invalid-function-name');
}
public function testSetAndGetCallback()
{
$this->assertInstanceOf(Func::class, $this->function->setCallback('strtolower'));
$this->assertSame('strtolower', $this->function->getCallback());
}
public function testSetInvalidCallback()
{
// Not a valid function callback.
$this->expectException(\LogicException::class);
$this->function->setCallback(null);
}
public function testFunctionCall()
{
$this->assertSame('JONATHAN', $this->function->call(null, array('Jonathan')));
}
public function testExtensionFunctionCall()
{
$extension = new class() implements ExtensionInterface {
public function register(Engine $engine)
{
}
public function foo(): string
{
return 'bar';
}
};
$this->function->setCallback(array($extension, 'foo'));
$this->assertSame('bar', $this->function->call(null));
}
}