Example
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 2
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 1
dl 0
loc 2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2024
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Attribute\Decorator;
10
11
12
class Example extends Base
13
{
14
}
15
16
17
class BaseTest extends \PHPUnit\Framework\TestCase
18
{
19
	private $context;
20
	private $object;
21
	private $stub;
22
23
24
	protected function setUp() : void
25
	{
26
		$this->context = \TestHelper::context();
27
28
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Attribute\Decorator\Example( $this->stub, $this->context );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->context, $this->object, $this->stub );
39
	}
40
41
42
	public function testCall()
43
	{
44
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Attribute\Decorator\Example( $stub, $this->context );
50
51
		$stub->expects( $this->once() )->method( '__call' )->willReturn( true );
52
53
		$this->assertTrue( $object->invalid() );
0 ignored issues
show
Bug introduced by
The method invalid() does not exist on Aimeos\Controller\Fronte...ibute\Decorator\Example. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
		$this->assertTrue( $object->/** @scrutinizer ignore-call */ invalid() );
Loading history...
54
	}
55
56
57
	public function testAttribute()
58
	{
59
		$this->assertSame( $this->object, $this->object->attribute( [1, 3] ) );
60
	}
61
62
63
	public function testDomain()
64
	{
65
		$this->assertSame( $this->object, $this->object->domain( 'catalog' ) );
66
	}
67
68
69
	public function testCompare()
70
	{
71
		$this->assertSame( $this->object, $this->object->compare( '==', 'attribute.code', 'test' ) );
72
	}
73
74
75
	public function testFind()
76
	{
77
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create();
78
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
79
80
		$this->stub->expects( $this->once() )->method( 'find' )
81
			->willReturn( $item );
82
83
		$this->assertInstanceOf( $expected, $this->object->find( 'test', 'color' ) );
84
	}
85
86
87
	public function testFunction()
88
	{
89
		$this->stub->expects( $this->once() )->method( 'function' )
90
			->willReturn( 'attribute:prop("type",null,"value")' );
91
92
		$str = $this->object->function( 'attribute:prop', ['type', null, 'value'] );
93
		$this->assertEquals( 'attribute:prop("type",null,"value")', $str );
94
	}
95
96
97
	public function testGet()
98
	{
99
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create();
100
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
101
102
		$this->stub->expects( $this->once() )->method( 'get' )
103
			->willReturn( $item );
104
105
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
106
	}
107
108
109
	public function testHas()
110
	{
111
		$this->assertSame( $this->object, $this->object->has( 'price', 'default', -1 ) );
112
	}
113
114
115
	public function testParse()
116
	{
117
		$this->assertSame( $this->object, $this->object->parse( [] ) );
118
	}
119
120
121
	public function testProperty()
122
	{
123
		$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) );
124
	}
125
126
127
	public function testSearch()
128
	{
129
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->create();
130
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is dead and can be removed.
Loading history...
131
		$total = 0;
132
133
		$this->stub->expects( $this->once() )->method( 'search' )
134
			->willReturn( map( [$item] ) );
135
136
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
137
	}
138
139
140
	public function testSlice()
141
	{
142
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
143
	}
144
145
146
	public function testSort()
147
	{
148
		$this->assertSame( $this->object, $this->object->sort( 'position' ) );
149
	}
150
151
152
	public function testUses()
153
	{
154
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
155
	}
156
157
158
	public function testGetController()
159
	{
160
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
161
162
		$this->assertSame( $this->stub, $result );
163
	}
164
165
166
	protected function access( $name )
167
	{
168
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class );
169
		$method = $class->getMethod( $name );
170
		$method->setAccessible( true );
171
172
		return $method;
173
	}
174
}
175