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

BaseTest::access()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
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-2023
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 = \TestHelper::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 testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\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 testCancel()
57
	{
58
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
59
60
		$this->stub->expects( $this->once() )->method( 'cancel' )
61
			->will( $this->returnValue( $item ) );
62
63
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->cancel( -1 ) );
64
	}
65
66
67
	public function testCompare()
68
	{
69
		$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) );
70
	}
71
72
73
	public function testGet()
74
	{
75
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
76
77
		$this->stub->expects( $this->once() )->method( 'get' )
78
			->will( $this->returnValue( $item ) );
79
80
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->get( -1 ) );
81
	}
82
83
84
	public function testGetIntervals()
85
	{
86
		$this->stub->expects( $this->once() )->method( 'getIntervals' )
87
			->will( $this->returnValue( map() ) );
88
89
		$this->assertInstanceOf( \Aimeos\Map::class, $this->object->getIntervals() );
90
	}
91
92
93
	public function testParse()
94
	{
95
		$this->assertSame( $this->object, $this->object->parse( [] ) );
96
	}
97
98
99
	public function testSave()
100
	{
101
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
102
103
		$this->stub->expects( $this->once() )->method( 'save' )
104
			->will( $this->returnValue( $item ) );
105
106
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->save( $item ) );
107
	}
108
109
110
	public function testSearch()
111
	{
112
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
113
114
		$this->stub->expects( $this->once() )->method( 'search' )
115
			->will( $this->returnValue( map( [$item] ) ) );
116
117
		$this->assertEquals( [$item], $this->object->search()->toArray() );
118
	}
119
120
121
	public function testSlice()
122
	{
123
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
124
	}
125
126
127
	public function testSort()
128
	{
129
		$this->assertSame( $this->object, $this->object->sort( 'interval' ) );
130
	}
131
132
133
	public function testUses()
134
	{
135
		$this->assertSame( $this->object, $this->object->uses( ['order'] ) );
136
	}
137
138
139
	public function testGetController()
140
	{
141
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
142
	}
143
144
145
	protected function access( $name )
146
	{
147
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Subscription\Decorator\Base::class );
148
		$method = $class->getMethod( $name );
149
		$method->setAccessible( true );
150
151
		return $method;
152
	}
153
}
154