Passed
Push — master ( c9dfc7...a4ce90 )
by Aimeos
01:38
created

BaseTest::testUses()   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
dl 0
loc 3
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\Catalog\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\Catalog\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\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\Catalog\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\Catalog\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\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( '==', 'catalog.code', 'test' ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
77
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
78
79
		$this->stub->expects( $this->once() )->method( 'find' )
80
			->will( $this->returnValue( $item ) );
81
82
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
83
	}
84
85
86
	public function testGet()
87
	{
88
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
89
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
90
91
		$this->stub->expects( $this->once() )->method( 'get' )
92
			->will( $this->returnValue( $item ) );
93
94
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
95
	}
96
97
98
	public function testParse()
99
	{
100
		$this->assertSame( $this->object, $this->object->parse( [] ) );
101
	}
102
103
104
	public function testGetPath()
105
	{
106
		$this->stub->expects( $this->once() )->method( 'getPath' )
107
			->will( $this->returnValue( [] ) );
108
109
		$this->assertEquals( [], $this->object->getPath( -1 ) );
110
	}
111
112
113
	public function testGetTree()
114
	{
115
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
116
117
		$this->stub->expects( $this->once() )->method( 'getTree' )
118
			->will( $this->returnValue( $catItem ) );
119
120
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
121
	}
122
123
124
	public function testRoot()
125
	{
126
		$this->assertSame( $this->object, $this->object->root( -1 ) );
127
	}
128
129
130
	public function testUses()
131
	{
132
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
133
	}
134
135
136
	public function testVisible()
137
	{
138
		$this->assertSame( $this->object, $this->object->visible( [1, 2] ) );
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\Catalog\Decorator\Base::class );
153
		$method = $class->getMethod( $name );
154
		$method->setAccessible( true );
155
156
		return $method;
157
	}
158
}
159