Passed
Push — master ( ef4aba...66430f )
by Aimeos
32:26 queued 24:14
created

BaseTest::testAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
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), 2017-2022
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Order\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\Order\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\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\Order\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\Order\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\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 testCompare()
69
	{
70
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
71
	}
72
73
74
	public function testGet()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
77
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
78
79
		$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $item ) );
80
81
		$this->assertInstanceOf( $expected, $this->object->get( -1, false ) );
82
	}
83
84
85
	public function testParse()
86
	{
87
		$this->assertSame( $this->object, $this->object->parse( [] ) );
88
	}
89
90
91
	public function testSave()
92
	{
93
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
94
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
95
96
		$this->stub->expects( $this->once() )->method( 'save' )->will( $this->returnArgument( 0 ) );
97
98
		$this->assertInstanceOf( $expected, $this->object->save( $item ) );
99
	}
100
101
102
	public function testSearch()
103
	{
104
		$total = 0;
105
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
106
107
		$this->stub->expects( $this->once() )->method( 'search' )
108
			->will( $this->returnValue( map( [$item] ) ) );
109
110
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
111
	}
112
113
114
	public function testSlice()
115
	{
116
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
117
	}
118
119
120
	public function testSort()
121
	{
122
		$this->assertSame( $this->object, $this->object->sort( 'order.id' ) );
123
	}
124
125
126
	public function testUses()
127
	{
128
		$this->assertSame( $this->object, $this->object->uses( ['order'] ) );
129
	}
130
131
132
	public function testGetController()
133
	{
134
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
135
136
		$this->assertSame( $this->stub, $result );
137
	}
138
139
140
	protected function access( $name )
141
	{
142
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Order\Decorator\Base::class );
143
		$method = $class->getMethod( $name );
144
		$method->setAccessible( true );
145
146
		return $method;
147
	}
148
}
149