Passed
Push — master ( d6e4b0...5d8aa0 )
by Aimeos
22:21 queued 08:52
created

BaseTest::testResolve()   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
c 0
b 0
f 0
dl 0
loc 8
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-2023
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Supplier\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 = \TestHelper::context();
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() : void
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Supplier\Decorator\Base::class )
47
			->setConstructorArgs( [$stub, $this->context] )
48
			->getMockForAbstractClass();
49
50
		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) );
51
52
		$this->assertTrue( $object->invalid() );
53
	}
54
55
56
	public function testCompare()
57
	{
58
		$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) );
59
	}
60
61
62
	public function testFind()
63
	{
64
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->create();
65
		$expected = \Aimeos\MShop\Supplier\Item\Iface::class;
66
67
		$this->stub->expects( $this->once() )->method( 'find' )
68
			->will( $this->returnValue( $item ) );
69
70
		$this->assertInstanceOf( $expected, $this->object->find( 'test' ) );
71
	}
72
73
74
	public function testFunction()
75
	{
76
		$this->stub->expects( $this->once() )->method( 'function' )
77
			->will( $this->returnValue( 'supplier:has("domain","type","refid")' ) );
78
79
		$str = $this->object->function( 'supplier:has', ['domain', 'type', 'refid'] );
80
		$this->assertEquals( 'supplier:has("domain","type","refid")', $str );
81
	}
82
83
84
	public function testGet()
85
	{
86
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->create();
87
		$expected = \Aimeos\MShop\Supplier\Item\Iface::class;
88
89
		$this->stub->expects( $this->once() )->method( 'get' )
90
			->will( $this->returnValue( $item ) );
91
92
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
93
	}
94
95
96
	public function testHas()
97
	{
98
		$this->assertSame( $this->object, $this->object->has( 'media', 'default', -1 ) );
99
	}
100
101
102
	public function testParse()
103
	{
104
		$this->assertSame( $this->object, $this->object->parse( [] ) );
105
	}
106
107
108
	public function testResolve()
109
	{
110
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->create();
111
112
		$this->stub->expects( $this->once() )->method( 'resolve' )
113
			->will( $this->returnValue( $item ) );
114
115
		$this->assertEquals( $item, $this->object->resolve( 'test' ) );
116
	}
117
118
119
	public function testSearch()
120
	{
121
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->create();
122
123
		$this->stub->expects( $this->once() )->method( 'search' )
124
			->will( $this->returnValue( map( [$item] ) ) );
125
126
		$this->assertEquals( [$item], $this->object->search()->toArray() );
127
	}
128
129
130
	public function testSlice()
131
	{
132
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
133
	}
134
135
136
	public function testSort()
137
	{
138
		$this->assertSame( $this->object, $this->object->sort( 'supplier.label' ) );
139
	}
140
141
142
	public function testUses()
143
	{
144
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
145
	}
146
147
148
	public function testGetController()
149
	{
150
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
151
152
		$this->assertSame( $this->stub, $result );
153
	}
154
155
156
	protected function access( $name )
157
	{
158
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Supplier\Decorator\Base::class );
159
		$method = $class->getMethod( $name );
160
		$method->setAccessible( true );
161
162
		return $method;
163
	}
164
}
165