Passed
Push — master ( 62fde5...4f02ab )
by Aimeos
05:13
created

TraitsTest::testProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\MW\Macro;
10
11
12
class TraitsTest extends \PHPUnit\Framework\TestCase
13
{
14
	public function testCall()
15
	{
16
		$this->assertEquals( 'B', ( new TestC() )->where() );
17
	}
18
19
20
	public function testProperty()
21
	{
22
		TestA::macro( 'test', function() {
23
			return $this->name;
0 ignored issues
show
Bug introduced by
The property name is declared private in PHPUnit\Framework\TestCase and cannot be accessed from this context.
Loading history...
24
		} );
25
26
		$this->assertEquals( 'A', ( new TestC() )->where() );
27
	}
28
29
30
	public function testMacroParent()
31
	{
32
		TestB::macro( 'test', function() {
33
			return 'B';
34
		} );
35
36
		$this->assertEquals( 'B', ( new TestC() )->where() );
37
	}
38
39
40
	public function testMacro()
41
	{
42
		TestC::macro( 'test', function() {
43
			return 'C';
44
		} );
45
46
		$this->assertEquals( 'C', ( new TestC() )->where() );
47
	}
48
}
49
50
51
class TestA implements Iface
52
{
53
	use Traits;
54
55
	private $name = 'A';
56
}
57
58
59
class TestB extends TestA
60
{
61
	protected function test( $arg )
62
	{
63
		return $arg;
64
	}
65
}
66
67
68
class TestC extends TestB
69
{
70
	public function where()
71
	{
72
		return $this->call( 'test', 'B' );
73
	}
74
}
75