Passed
Push — master ( 411768...2359f2 )
by Aimeos
02:19
created

BaseTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 16
eloc 56
c 2
b 0
f 0
dl 0
loc 152
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompare() 0 3 1
A testFind() 0 9 1
A tearDown() 0 3 1
A testConstructException() 0 9 1
A setUp() 0 11 1
A testCall() 0 14 1
A testUses() 0 3 1
A testGetController() 0 5 1
A testSort() 0 3 1
A testFunction() 0 7 1
A access() 0 7 1
A testHas() 0 3 1
A testParse() 0 3 1
A testSearch() 0 8 1
A testGet() 0 9 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), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Supplier\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()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\Decorator\Base::class )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown()
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->setExpectedException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\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\Supplier\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\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( '==', 'supplier.status', 1 ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
77
		$expected = \Aimeos\MShop\Supplier\Item\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' ) );
83
	}
84
85
86
	public function testFunction()
87
	{
88
		$this->stub->expects( $this->once() )->method( 'function' )
89
			->will( $this->returnValue( 'supplier:has("domain","type","refid")' ) );
90
91
		$str = $this->object->function( 'supplier:has', ['domain', 'type', 'refid'] );
92
		$this->assertEquals( 'supplier:has("domain","type","refid")', $str );
93
	}
94
95
96
	public function testGet()
97
	{
98
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
99
		$expected = \Aimeos\MShop\Supplier\Item\Iface::class;
100
101
		$this->stub->expects( $this->once() )->method( 'get' )
102
			->will( $this->returnValue( $item ) );
103
104
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
105
	}
106
107
108
	public function testHas()
109
	{
110
		$this->assertSame( $this->object, $this->object->has( 'product', 'default', -1 ) );
111
	}
112
113
114
	public function testParse()
115
	{
116
		$this->assertSame( $this->object, $this->object->parse( [] ) );
117
	}
118
119
120
	public function testSearch()
121
	{
122
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
123
124
		$this->stub->expects( $this->once() )->method( 'search' )
125
			->will( $this->returnValue( [$item] ) );
126
127
		$this->assertEquals( [$item], $this->object->search() );
128
	}
129
130
131
	public function testSlice()
132
	{
133
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
134
	}
135
136
137
	public function testSort()
138
	{
139
		$this->assertSame( $this->object, $this->object->sort( 'supplier.label' ) );
140
	}
141
142
143
	public function testUses()
144
	{
145
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
146
	}
147
148
149
	public function testGetController()
150
	{
151
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
152
153
		$this->assertSame( $this->stub, $result );
154
	}
155
156
157
	protected function access( $name )
158
	{
159
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Supplier\Decorator\Base::class );
160
		$method = $class->getMethod( $name );
161
		$method->setAccessible( true );
162
163
		return $method;
164
	}
165
}
166