Passed
Push — master ( ff9225...fa6243 )
by Aimeos
02:02
created

BaseTest::testGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
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-2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Order\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
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()
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->setExpectedException( \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 testAdd()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'add' );
71
		$this->assertSame( $this->object, $this->object->add( -1, [] ) );
72
	}
73
74
75
	public function testCompare()
76
	{
77
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
78
	}
79
80
81
	public function testGet()
82
	{
83
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
84
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
85
86
		$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $item ) );
87
88
		$this->assertInstanceOf( $expected, $this->object->get( -1, false ) );
89
	}
90
91
92
	public function testParse()
93
	{
94
		$this->assertSame( $this->object, $this->object->parse( [] ) );
95
	}
96
97
98
	public function testSave()
99
	{
100
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
101
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
102
103
		$this->stub->expects( $this->once() )->method( 'save' )->will( $this->returnArgument( 0 ) );
104
105
		$this->assertInstanceOf( $expected, $this->object->save( $item ) );
106
	}
107
108
109
	public function testSearch()
110
	{
111
		$total = 0;
112
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
113
114
		$this->stub->expects( $this->once() )->method( 'search' )->will( $this->returnValue( [$item] ) );
115
116
		$this->assertEquals( [$item], $this->object->search( $total ) );
117
	}
118
119
120
	public function testSlice()
121
	{
122
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
123
	}
124
125
126
	public function testSort()
127
	{
128
		$this->assertSame( $this->object, $this->object->sort( 'order.id' ) );
129
	}
130
131
132
	public function testStore()
133
	{
134
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
135
136
		$this->stub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $item ) );
137
138
		$this->assertEquals( $item, $this->object->store() );
139
	}
140
141
142
	public function testGetController()
143
	{
144
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
145
146
		$this->assertSame( $this->stub, $result );
147
	}
148
149
150
	protected function access( $name )
151
	{
152
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Order\Decorator\Base::class );
153
		$method = $class->getMethod( $name );
154
		$method->setAccessible( true );
155
156
		return $method;
157
	}
158
}
159