BaseTest::access()   A
last analyzed

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), 2017-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Order\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\Order\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Order\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\Order\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Order\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\Frontend\Order\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 testCompare()
58
	{
59
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
60
	}
61
62
63
	public function testGet()
64
	{
65
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
66
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
67
68
		$this->stub->expects( $this->once() )->method( 'get' )->willReturn( $item );
69
70
		$this->assertInstanceOf( $expected, $this->object->get( -1, false ) );
71
	}
72
73
74
	public function testParse()
75
	{
76
		$this->assertSame( $this->object, $this->object->parse( [] ) );
77
	}
78
79
80
	public function testSave()
81
	{
82
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
83
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
84
85
		$this->stub->expects( $this->once() )->method( 'save' )->willReturnArgument( 0 );
86
87
		$this->assertInstanceOf( $expected, $this->object->save( $item ) );
88
	}
89
90
91
	public function testSearch()
92
	{
93
		$total = 0;
94
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
95
96
		$this->stub->expects( $this->once() )->method( 'search' )
97
			->willReturn( map( [$item] ) );
98
99
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
100
	}
101
102
103
	public function testSlice()
104
	{
105
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
106
	}
107
108
109
	public function testSort()
110
	{
111
		$this->assertSame( $this->object, $this->object->sort( 'order.id' ) );
112
	}
113
114
115
	public function testUpdate()
116
	{
117
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
118
		$this->assertSame( $this->object, $this->object->update( $item ) );
119
	}
120
121
122
	public function testUses()
123
	{
124
		$this->assertSame( $this->object, $this->object->uses( ['order'] ) );
125
	}
126
127
128
	public function testGetController()
129
	{
130
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
131
132
		$this->assertSame( $this->stub, $result );
133
	}
134
135
136
	protected function access( $name )
137
	{
138
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Order\Decorator\Base::class );
139
		$method = $class->getMethod( $name );
140
		$method->setAccessible( true );
141
142
		return $method;
143
	}
144
}
145