Completed
Push — master ( a4e8a9...31faa3 )
by Aimeos
02:22
created

BaseTest::access()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Attribute\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()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Attribute\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Attribute\Decorator\Base' )
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 testAddFilterTypes()
40
	{
41
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' )->createSearch();
42
43
		$this->stub->expects( $this->once() )->method( 'addFilterTypes' )
44
			->will( $this->returnArgument( 0 ) );
45
46
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addFilterTypes( $search, [] ) );
47
	}
48
49
50
	public function testCreateFilter()
51
	{
52
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' )->createSearch();
53
54
		$this->stub->expects( $this->once() )->method( 'createFilter' )
55
			->will( $this->returnValue( $search ) );
56
57
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() );
58
	}
59
60
61
	public function testGetItem()
62
	{
63
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' )->createItem();
64
65
		$this->stub->expects( $this->once() )->method( 'getItem' )
66
			->will( $this->returnValue( $item ) );
67
68
		$this->assertInstanceOf( '\Aimeos\MShop\Attribute\Item\Iface', $this->object->getItem( -1 ) );
69
	}
70
71
72
	public function testSearchItems()
73
	{
74
		$filter = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' )->createSearch();
75
76
		$this->stub->expects( $this->once() )->method( 'searchItems' )
77
			->will( $this->returnValue( [] ) );
78
79
		$this->assertEquals( [], $this->object->searchItems( $filter, ['media'] ) );
80
	}
81
82
83
	public function testGetContext()
84
	{
85
		$result = $this->access( 'getContext' )->invokeArgs( $this->object, [] );
86
87
		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result );
88
	}
89
90
91
	protected function access( $name )
92
	{
93
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Attribute\Decorator\Base' );
94
		$method = $class->getMethod( $name );
95
		$method->setAccessible( true );
96
97
		return $method;
98
	}
99
}
100