forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupportMacroableTest.php
More file actions
57 lines (43 loc) · 1.36 KB
/
SupportMacroableTest.php
File metadata and controls
57 lines (43 loc) · 1.36 KB
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
<?php
class SupportMacroableTest extends PHPUnit_Framework_TestCase {
private $macroable;
public function setUp()
{
$this->macroable = $this->createObjectForTrait();
}
private function createObjectForTrait()
{
$traitName = 'Illuminate\Support\Traits\Macroable';
return $this->getObjectForTrait($traitName);
}
public function testRegisterMacro()
{
$macroable = $this->macroable;
$macroable::macro(__CLASS__, function() { return 'Taylor'; });
$this->assertEquals('Taylor', $macroable::{__CLASS__}());
}
public function testRegisterMacroAndCallWithoutStatic()
{
$macroable = $this->macroable;
$macroable::macro(__CLASS__, function() { return 'Taylor'; });
$this->assertEquals('Taylor', $macroable->{__CLASS__}());
}
public function testWhenCallingMacroClosureIsBoundToObject()
{
TestMacroable::macro('tryInstance', function() { return $this->protectedVariable; } );
TestMacroable::macro('tryStatic', function() { return static::getProtectedStatic(); } );
$instance = new TestMacroable;
$result = $instance->tryInstance();
$this->assertEquals('instance', $result);
$result = TestMacroable::tryStatic();
$this->assertEquals('static', $result);
}
}
class TestMacroable {
use Illuminate\Support\Traits\Macroable;
protected $protectedVariable = 'instance';
protected static function getProtectedStatic()
{
return 'static';
}
}