Passed
Push — master ( ee42b0...a87169 )
by Aimeos
07:53
created

BaseTest::access()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2022
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() : void
20
	{
21
		$this->context = \TestHelperFrontend::context();
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() : 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\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' )->create();
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
		$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) );
82
	}
83
84
85
	public function testGet()
86
	{
87
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
88
89
		$this->stub->expects( $this->once() )->method( 'get' )
90
			->will( $this->returnValue( $item ) );
91
92
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->get( -1 ) );
93
	}
94
95
96
	public function testGetIntervals()
97
	{
98
		$this->stub->expects( $this->once() )->method( 'getIntervals' )
99
			->will( $this->returnValue( map() ) );
100
101
		$this->assertInstanceOf( \Aimeos\Map::class, $this->object->getIntervals() );
102
	}
103
104
105
	public function testParse()
106
	{
107
		$this->assertSame( $this->object, $this->object->parse( [] ) );
108
	}
109
110
111
	public function testSave()
112
	{
113
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
114
115
		$this->stub->expects( $this->once() )->method( 'save' )
116
			->will( $this->returnValue( $item ) );
117
118
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->save( $item ) );
119
	}
120
121
122
	public function testSearch()
123
	{
124
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
125
126
		$this->stub->expects( $this->once() )->method( 'search' )
127
			->will( $this->returnValue( map( [$item] ) ) );
128
129
		$this->assertEquals( [$item], $this->object->search()->toArray() );
130
	}
131
132
133
	public function testSlice()
134
	{
135
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
136
	}
137
138
139
	public function testSort()
140
	{
141
		$this->assertSame( $this->object, $this->object->sort( 'interval' ) );
142
	}
143
144
145
	public function testUses()
146
	{
147
		$this->assertSame( $this->object, $this->object->uses( ['order/base'] ) );
148
	}
149
150
151
	public function testGetController()
152
	{
153
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
154
	}
155
156
157
	protected function access( $name )
158
	{
159
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Subscription\Decorator\Base::class );
160
		$method = $class->getMethod( $name );
161
		$method->setAccessible( true );
162
163
		return $method;
164
	}
165
}
166