Passed
Push — master ( 5b861b...ddbcd6 )
by Aimeos
16:40 queued 03:20
created

BaseTest::testConstructException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
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), 2021-2023
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Site\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\Site\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\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\Site\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\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( '==', 'locale.site.code', 'test' ) );
59
	}
60
61
62
	public function testFind()
63
	{
64
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
65
		$expected = \Aimeos\MShop\Locale\Item\Site\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', ['text'] ) );
71
	}
72
73
74
	public function testGet()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
77
		$expected = \Aimeos\MShop\Locale\Item\Site\Iface::class;
78
79
		$this->stub->expects( $this->once() )->method( 'get' )
80
			->will( $this->returnValue( $item ) );
81
82
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
83
	}
84
85
86
	public function testParse()
87
	{
88
		$this->assertSame( $this->object, $this->object->parse( [] ) );
89
	}
90
91
92
	public function testGetPath()
93
	{
94
		$this->stub->expects( $this->once() )->method( 'getPath' )
95
			->will( $this->returnValue( [] ) );
96
97
		$this->assertEquals( [], $this->object->getPath( -1 ) );
98
	}
99
100
101
	public function testGetTree()
102
	{
103
		$catItem = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
104
105
		$this->stub->expects( $this->once() )->method( 'getTree' )
106
			->will( $this->returnValue( $catItem ) );
107
108
		$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $this->object->getTree() );
109
	}
110
111
112
	public function testRoot()
113
	{
114
		$this->assertSame( $this->object, $this->object->root( -1 ) );
115
	}
116
117
118
	public function testSearch()
119
	{
120
		$total = 0;
121
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
122
123
		$this->stub->expects( $this->once() )->method( 'search' )
124
			->will( $this->returnValue( map( [$item] ) ) );
125
126
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
127
	}
128
129
130
	public function testSlice()
131
	{
132
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
133
	}
134
135
136
	public function testSort()
137
	{
138
		$this->assertSame( $this->object, $this->object->sort( 'locale.site.label' ) );
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\Site\Decorator\Base::class );
153
		$method = $class->getMethod( $name );
154
		$method->setAccessible( true );
155
156
		return $method;
157
	}
158
}
159