Passed
Push — master ( 216152...7bdf82 )
by Aimeos
02:00
created

BaseTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Supplier\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\Supplier\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\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\Supplier\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\Supplier\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\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( '==', 'supplier.status', 1 ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
77
		$expected = \Aimeos\MShop\Supplier\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' ) );
83
	}
84
85
86
	public function testGet()
87
	{
88
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
89
		$expected = \Aimeos\MShop\Supplier\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 ) );
95
	}
96
97
98
	public function testHas()
99
	{
100
		$this->assertSame( $this->object, $this->object->has( 'product', 'default', -1 ) );
101
	}
102
103
104
	public function testParse()
105
	{
106
		$this->assertSame( $this->object, $this->object->parse( [] ) );
107
	}
108
109
110
	public function testSearch()
111
	{
112
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->createItem();
113
114
		$this->stub->expects( $this->once() )->method( 'search' )
115
			->will( $this->returnValue( [$item] ) );
116
117
		$this->assertEquals( [$item], $this->object->search() );
118
	}
119
120
121
	public function testSlice()
122
	{
123
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
124
	}
125
126
127
	public function testSort()
128
	{
129
		$this->assertSame( $this->object, $this->object->sort( 'supplier.label' ) );
130
	}
131
132
133
	public function testUses()
134
	{
135
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
136
	}
137
138
139
	public function testGetController()
140
	{
141
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
142
143
		$this->assertSame( $this->stub, $result );
144
	}
145
146
147
	protected function access( $name )
148
	{
149
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Supplier\Decorator\Base::class );
150
		$method = $class->getMethod( $name );
151
		$method->setAccessible( true );
152
153
		return $method;
154
	}
155
}
156