Completed
Push — master ( 9109fd...709bda )
by Aimeos
02:33
created

BaseTest::testSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
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), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Subscription\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\Subscription\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\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\Subscription\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\Subscription\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\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 testCancel()
69
	{
70
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->createItem();
71
72
		$this->stub->expects( $this->once() )->method( 'cancel' )
73
			->will( $this->returnValue( $item ) );
74
75
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->cancel( -1 ) );
76
	}
77
78
79
	public function testCompare()
80
	{
81
		$expected = \Aimeos\Controller\Frontend\Subscription\Iface::class;
82
83
		$this->stub->expects( $this->once() )->method( 'compare' )
84
			->will( $this->returnValue( $this->stub ) );
85
86
		$this->assertInstanceOf( $expected, $this->object->compare( '==', 'supplier.status', 1 ) );
87
	}
88
89
90
	public function testGet()
91
	{
92
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->createItem();
93
94
		$this->stub->expects( $this->once() )->method( 'get' )
95
			->will( $this->returnValue( $item ) );
96
97
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->get( -1 ) );
98
	}
99
100
101
	public function testGetIntervals()
102
	{
103
		$this->stub->expects( $this->once() )->method( 'getIntervals' )
104
			->will( $this->returnValue( [] ) );
105
106
		$this->assertEquals( [], $this->object->getIntervals() );
107
	}
108
109
110
	public function testParse()
111
	{
112
		$expected = \Aimeos\Controller\Frontend\Subscription\Iface::class;
113
114
		$this->stub->expects( $this->once() )->method( 'parse' )
115
			->will( $this->returnValue( $this->stub ) );
116
117
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
118
	}
119
120
121
	public function testSave()
122
	{
123
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->createItem();
124
125
		$this->stub->expects( $this->once() )->method( 'save' )
126
			->will( $this->returnValue( $item ) );
127
128
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->save( $item ) );
129
	}
130
131
132
	public function testSearch()
133
	{
134
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->createItem();
135
136
		$this->stub->expects( $this->once() )->method( 'search' )
137
			->will( $this->returnValue( [$item] ) );
138
139
		$this->assertEquals( [$item], $this->object->search() );
140
	}
141
142
143
	public function testSlice()
144
	{
145
		$expected = \Aimeos\Controller\Frontend\Subscription\Iface::class;
146
147
		$this->stub->expects( $this->once() )->method( 'slice' )
148
			->will( $this->returnValue( $this->stub ) );
149
150
		$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) );
151
	}
152
153
154
	public function testSort()
155
	{
156
		$expected = \Aimeos\Controller\Frontend\Subscription\Iface::class;
157
158
		$this->stub->expects( $this->once() )->method( 'sort' )
159
			->will( $this->returnValue( $this->stub ) );
160
161
		$this->assertInstanceOf( $expected, $this->object->sort( 'interval' ) );
162
	}
163
164
165
	public function testGetController()
166
	{
167
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
168
169
		$this->assertSame( $this->stub, $result );
170
	}
171
172
173
	protected function access( $name )
174
	{
175
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Subscription\Decorator\Base::class );
176
		$method = $class->getMethod( $name );
177
		$method->setAccessible( true );
178
179
		return $method;
180
	}
181
}
182