BaseTest   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
eloc 60
dl 0
loc 174
c 1
b 0
f 0
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
A testSlice() 0 3 1
A testSort() 0 3 1
A testSearch() 0 9 1
A testRoot() 0 3 1
A access() 0 7 1
A testVisible() 0 3 1
A testGetController() 0 5 1
A setUp() 0 9 1
A testCall() 0 12 1
A testResolve() 0 8 1
A testFunction() 0 7 1
A testCompare() 0 3 1
A testGet() 0 9 1
A testGetPath() 0 6 1
A testHas() 0 3 1
A tearDown() 0 3 1
A testFind() 0 9 1
A testParse() 0 3 1
A testGetTree() 0 8 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Catalog\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\Catalog\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Catalog\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\Catalog\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Catalog\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...talog\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 testCompare()
58
	{
59
		$this->assertSame( $this->object, $this->object->compare( '==', 'catalog.code', 'test' ) );
60
	}
61
62
63
	public function testFind()
64
	{
65
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
66
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
67
68
		$this->stub->expects( $this->once() )->method( 'find' )
69
			->willReturn( $item );
70
71
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
72
	}
73
74
75
	public function testFunction()
76
	{
77
		$this->stub->expects( $this->once() )->method( 'function' )
78
			->willReturn( 'catalog:has("domain","type","refid")' );
79
80
		$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] );
81
		$this->assertEquals( 'catalog:has("domain","type","refid")', $str );
82
	}
83
84
85
	public function testGet()
86
	{
87
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
88
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
89
90
		$this->stub->expects( $this->once() )->method( 'get' )
91
			->willReturn( $item );
92
93
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
94
	}
95
96
97
	public function testHas()
98
	{
99
		$this->assertSame( $this->object, $this->object->has( 'media', 'default', -1 ) );
100
	}
101
102
103
	public function testParse()
104
	{
105
		$this->assertSame( $this->object, $this->object->parse( [] ) );
106
	}
107
108
109
	public function testGetPath()
110
	{
111
		$this->stub->expects( $this->once() )->method( 'getPath' )
112
			->willReturn( [] );
113
114
		$this->assertEquals( [], $this->object->getPath( -1 ) );
115
	}
116
117
118
	public function testGetTree()
119
	{
120
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
121
122
		$this->stub->expects( $this->once() )->method( 'getTree' )
123
			->willReturn( $catItem );
124
125
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
126
	}
127
128
129
	public function testResolve()
130
	{
131
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
132
133
		$this->stub->expects( $this->once() )->method( 'resolve' )
134
			->willReturn( $item );
135
136
		$this->assertEquals( $item, $this->object->resolve( 'test' ) );
137
	}
138
139
140
	public function testRoot()
141
	{
142
		$this->assertSame( $this->object, $this->object->root( -1 ) );
143
	}
144
145
146
	public function testSearch()
147
	{
148
		$total = 0;
149
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
150
151
		$this->stub->expects( $this->once() )->method( 'search' )
152
			->willReturn( map( [$item] ) );
153
154
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
155
	}
156
157
158
	public function testSlice()
159
	{
160
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
161
	}
162
163
164
	public function testSort()
165
	{
166
		$this->assertSame( $this->object, $this->object->sort( 'catalog.label' ) );
167
	}
168
169
170
	public function testVisible()
171
	{
172
		$this->assertSame( $this->object, $this->object->visible( [1, 2] ) );
173
	}
174
175
176
	public function testGetController()
177
	{
178
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
179
180
		$this->assertSame( $this->stub, $result );
181
	}
182
183
184
	protected function access( $name )
185
	{
186
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class );
187
		$method = $class->getMethod( $name );
188
		$method->setAccessible( true );
189
190
		return $method;
191
	}
192
}
193