BaseTest   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 46
dl 0
loc 136
c 0
b 0
f 0
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A setUp() 0 9 1
A access() 0 7 1
A testSlice() 0 3 1
A testCall() 0 12 1
A testUses() 0 3 1
A testGet() 0 8 1
A testGetController() 0 3 1
A testSearch() 0 8 1
A testParse() 0 3 1
A testSort() 0 3 1
A testGetIntervals() 0 6 1
A testCompare() 0 3 1
A testCancel() 0 8 1
A testSave() 0 8 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Subscription\Decorator;
10
11
12
class Example extends Base
13
{
14
}
15
16
17
class BaseTest extends \PHPUnit\Framework\TestCase
18
{
19
	private $context;
20
	private $object;
21
	private $stub;
22
23
24
	protected function setUp() : void
25
	{
26
		$this->context = \TestHelper::context();
27
28
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Subscription\Decorator\Example( $this->stub, $this->context );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->context, $this->object, $this->stub );
39
	}
40
41
42
	public function testCall()
43
	{
44
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Subscription\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Subscription\Decorator\Example( $stub, $this->context );
50
51
		$stub->expects( $this->once() )->method( '__call' )->willReturn( true );
52
53
		$this->assertTrue( $object->invalid() );
0 ignored issues
show
Bug introduced by
The method invalid() does not exist on Aimeos\Controller\Fronte...ption\Decorator\Example. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
		$this->assertTrue( $object->/** @scrutinizer ignore-call */ invalid() );
Loading history...
54
	}
55
56
57
	public function testCancel()
58
	{
59
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
60
61
		$this->stub->expects( $this->once() )->method( 'cancel' )
62
			->willReturn( $item );
63
64
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->cancel( -1 ) );
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 testGet()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
77
78
		$this->stub->expects( $this->once() )->method( 'get' )
79
			->willReturn( $item );
80
81
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->get( -1 ) );
82
	}
83
84
85
	public function testGetIntervals()
86
	{
87
		$this->stub->expects( $this->once() )->method( 'getIntervals' )
88
			->willReturn( map() );
89
90
		$this->assertInstanceOf( \Aimeos\Map::class, $this->object->getIntervals() );
91
	}
92
93
94
	public function testParse()
95
	{
96
		$this->assertSame( $this->object, $this->object->parse( [] ) );
97
	}
98
99
100
	public function testSave()
101
	{
102
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
103
104
		$this->stub->expects( $this->once() )->method( 'save' )
105
			->willReturn( $item );
106
107
		$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->save( $item ) );
108
	}
109
110
111
	public function testSearch()
112
	{
113
		$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create();
114
115
		$this->stub->expects( $this->once() )->method( 'search' )
116
			->willReturn( map( [$item] ) );
117
118
		$this->assertEquals( [$item], $this->object->search()->toArray() );
119
	}
120
121
122
	public function testSlice()
123
	{
124
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
125
	}
126
127
128
	public function testSort()
129
	{
130
		$this->assertSame( $this->object, $this->object->sort( 'interval' ) );
131
	}
132
133
134
	public function testUses()
135
	{
136
		$this->assertSame( $this->object, $this->object->uses( ['order'] ) );
137
	}
138
139
140
	public function testGetController()
141
	{
142
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
143
	}
144
145
146
	protected function access( $name )
147
	{
148
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Subscription\Decorator\Base::class );
149
		$method = $class->getMethod( $name );
150
		$method->setAccessible( true );
151
152
		return $method;
153
	}
154
}
155