Passed
Push — master ( 6ee4ae...fdac5c )
by Aimeos
03:28
created

BaseTest::testProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
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-2020
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Stock\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 = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Stock\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Stock\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\Stock\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\Stock\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Stock\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 testProduct()
69
	{
70
		$this->assertSame( $this->object, $this->object->product( ['123', '456'] ) );
71
	}
72
73
74
	public function testCompare()
75
	{
76
		$this->assertSame( $this->object, $this->object->compare( '==', 'stock.dateback', '2000-01-01 00:00:00' ) );
77
	}
78
79
80
	public function testGet()
81
	{
82
		$item = \Aimeos\MShop::create( $this->context, 'stock' )->createItem();
83
		$expected = \Aimeos\MShop\Stock\Item\Iface::class;
84
85
		$this->stub->expects( $this->once() )->method( 'get' )
86
			->will( $this->returnValue( $item ) );
87
88
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
89
	}
90
91
92
	public function testParse()
93
	{
94
		$this->assertSame( $this->object, $this->object->parse( [] ) );
95
	}
96
97
98
	public function testSearch()
99
	{
100
		$item = \Aimeos\MShop::create( $this->context, 'stock' )->createItem();
101
102
		$this->stub->expects( $this->once() )->method( 'search' )
103
			->will( $this->returnValue( map( [$item] ) ) );
104
105
		$this->assertEquals( [$item], $this->object->search()->toArray() );
106
	}
107
108
109
	public function testSlice()
110
	{
111
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
112
	}
113
114
115
	public function testSort()
116
	{
117
		$this->assertSame( $this->object, $this->object->sort( 'stock' ) );
118
	}
119
120
121
	public function testGetController()
122
	{
123
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
124
	}
125
126
127
	protected function access( $name )
128
	{
129
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Stock\Decorator\Base::class );
130
		$method = $class->getMethod( $name );
131
		$method->setAccessible( true );
132
133
		return $method;
134
	}
135
}
136