Passed
Push — master ( 5b861b...ddbcd6 )
by Aimeos
16:40 queued 03:20
created

BaseTest::testCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2023
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Catalog\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->context = \TestHelper::context();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
47
			->setConstructorArgs( [$stub, $this->context] )
48
			->getMockForAbstractClass();
49
50
		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) );
51
52
		$this->assertTrue( $object->invalid() );
53
	}
54
55
56
	public function testCompare()
57
	{
58
		$this->assertSame( $this->object, $this->object->compare( '==', 'catalog.code', 'test' ) );
59
	}
60
61
62
	public function testFind()
63
	{
64
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
65
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
66
67
		$this->stub->expects( $this->once() )->method( 'find' )
68
			->will( $this->returnValue( $item ) );
69
70
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
71
	}
72
73
74
	public function testFunction()
75
	{
76
		$this->stub->expects( $this->once() )->method( 'function' )
77
			->will( $this->returnValue( 'catalog:has("domain","type","refid")' ) );
78
79
		$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] );
80
		$this->assertEquals( 'catalog:has("domain","type","refid")', $str );
81
	}
82
83
84
	public function testGet()
85
	{
86
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
87
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
88
89
		$this->stub->expects( $this->once() )->method( 'get' )
90
			->will( $this->returnValue( $item ) );
91
92
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
93
	}
94
95
96
	public function testHas()
97
	{
98
		$this->assertSame( $this->object, $this->object->has( 'media', 'default', -1 ) );
99
	}
100
101
102
	public function testParse()
103
	{
104
		$this->assertSame( $this->object, $this->object->parse( [] ) );
105
	}
106
107
108
	public function testGetPath()
109
	{
110
		$this->stub->expects( $this->once() )->method( 'getPath' )
111
			->will( $this->returnValue( [] ) );
112
113
		$this->assertEquals( [], $this->object->getPath( -1 ) );
114
	}
115
116
117
	public function testGetTree()
118
	{
119
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
120
121
		$this->stub->expects( $this->once() )->method( 'getTree' )
122
			->will( $this->returnValue( $catItem ) );
123
124
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
125
	}
126
127
128
	public function testRoot()
129
	{
130
		$this->assertSame( $this->object, $this->object->root( -1 ) );
131
	}
132
133
134
	public function testSearch()
135
	{
136
		$total = 0;
137
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
138
139
		$this->stub->expects( $this->once() )->method( 'search' )
140
			->will( $this->returnValue( map( [$item] ) ) );
141
142
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
143
	}
144
145
146
	public function testSlice()
147
	{
148
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
149
	}
150
151
152
	public function testSort()
153
	{
154
		$this->assertSame( $this->object, $this->object->sort( 'catalog.label' ) );
155
	}
156
157
158
	public function testVisible()
159
	{
160
		$this->assertSame( $this->object, $this->object->visible( [1, 2] ) );
161
	}
162
163
164
	public function testGetController()
165
	{
166
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
167
168
		$this->assertSame( $this->stub, $result );
169
	}
170
171
172
	protected function access( $name )
173
	{
174
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class );
175
		$method = $class->getMethod( $name );
176
		$method->setAccessible( true );
177
178
		return $method;
179
	}
180
}
181