Passed
Push — master ( 365418...ec127b )
by Aimeos
02:19
created

BaseTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
eloc 59
c 1
b 0
f 0
dl 0
loc 157
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompare() 0 3 1
A testRoot() 0 3 1
A testSearch() 0 9 1
A testSort() 0 3 1
A testGetController() 0 5 1
A testCall() 0 14 1
A testFind() 0 9 1
A testGetPath() 0 6 1
A testConstructException() 0 9 1
A access() 0 7 1
A setUp() 0 11 1
A testGet() 0 9 1
A tearDown() 0 3 1
A testParse() 0 3 1
A testGetTree() 0 8 1
A testSlice() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Site\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 = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\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 testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock();
42
43
		$this->expectException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Decorator\Base::class )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Decorator\Base::class )
59
			->setConstructorArgs( [$stub, $this->context] )
60
			->getMockForAbstractClass();
61
62
		$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) );
63
64
		$this->assertTrue( $object->invalid() );
65
	}
66
67
68
	public function testCompare()
69
	{
70
		$this->assertSame( $this->object, $this->object->compare( '==', 'locale.site.code', 'test' ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
77
		$expected = \Aimeos\MShop\Locale\Item\Site\Iface::class;
78
79
		$this->stub->expects( $this->once() )->method( 'find' )
80
			->will( $this->returnValue( $item ) );
81
82
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
83
	}
84
85
86
	public function testGet()
87
	{
88
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
89
		$expected = \Aimeos\MShop\Locale\Item\Site\Iface::class;
90
91
		$this->stub->expects( $this->once() )->method( 'get' )
92
			->will( $this->returnValue( $item ) );
93
94
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
95
	}
96
97
98
	public function testParse()
99
	{
100
		$this->assertSame( $this->object, $this->object->parse( [] ) );
101
	}
102
103
104
	public function testGetPath()
105
	{
106
		$this->stub->expects( $this->once() )->method( 'getPath' )
107
			->will( $this->returnValue( [] ) );
108
109
		$this->assertEquals( [], $this->object->getPath( -1 ) );
110
	}
111
112
113
	public function testGetTree()
114
	{
115
		$catItem = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
116
117
		$this->stub->expects( $this->once() )->method( 'getTree' )
118
			->will( $this->returnValue( $catItem ) );
119
120
		$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $this->object->getTree() );
121
	}
122
123
124
	public function testRoot()
125
	{
126
		$this->assertSame( $this->object, $this->object->root( -1 ) );
127
	}
128
129
130
	public function testSearch()
131
	{
132
		$total = 0;
133
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
134
135
		$this->stub->expects( $this->once() )->method( 'search' )
136
			->will( $this->returnValue( map( [$item] ) ) );
137
138
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
139
	}
140
141
142
	public function testSlice()
143
	{
144
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
145
	}
146
147
148
	public function testSort()
149
	{
150
		$this->assertSame( $this->object, $this->object->sort( 'locale.site.label' ) );
151
	}
152
153
154
	public function testGetController()
155
	{
156
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
157
158
		$this->assertSame( $this->stub, $result );
159
	}
160
161
162
	protected function access( $name )
163
	{
164
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Site\Decorator\Base::class );
165
		$method = $class->getMethod( $name );
166
		$method->setAccessible( true );
167
168
		return $method;
169
	}
170
}
171