BaseTest::testSearch()   A
last analyzed

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-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Site\Decorator;
10
11
12
class Example extends Base
13
{
14
}
15
16
17
class BaseTest extends \PHPUnit\Framework\TestCase
18
{
19
	private $context;
20
	private $object;
21
	private $stub;
22
23
24
	protected function setUp() : void
25
	{
26
		$this->context = \TestHelper::context();
27
28
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Site\Decorator\Example( $this->stub, $this->context );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->context, $this->object, $this->stub );
39
	}
40
41
42
	public function testCall()
43
	{
44
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Site\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Site\Decorator\Example( $stub, $this->context );
50
51
		$stub->expects( $this->once() )->method( '__call' )->willReturn( true );
52
53
		$this->assertTrue( $object->invalid() );
0 ignored issues
show
Bug introduced by
The method invalid() does not exist on Aimeos\Controller\Frontend\Site\Decorator\Example. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
		$this->assertTrue( $object->/** @scrutinizer ignore-call */ invalid() );
Loading history...
54
	}
55
56
57
	public function testCompare()
58
	{
59
		$this->assertSame( $this->object, $this->object->compare( '==', 'locale.site.code', 'test' ) );
60
	}
61
62
63
	public function testFind()
64
	{
65
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
66
		$expected = \Aimeos\MShop\Locale\Item\Site\Iface::class;
67
68
		$this->stub->expects( $this->once() )->method( 'find' )
69
			->willReturn( $item );
70
71
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
72
	}
73
74
75
	public function testGet()
76
	{
77
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
78
		$expected = \Aimeos\MShop\Locale\Item\Site\Iface::class;
79
80
		$this->stub->expects( $this->once() )->method( 'get' )
81
			->willReturn( $item );
82
83
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
84
	}
85
86
87
	public function testParse()
88
	{
89
		$this->assertSame( $this->object, $this->object->parse( [] ) );
90
	}
91
92
93
	public function testGetPath()
94
	{
95
		$this->stub->expects( $this->once() )->method( 'getPath' )
96
			->willReturn( [] );
97
98
		$this->assertEquals( [], $this->object->getPath( -1 ) );
99
	}
100
101
102
	public function testGetTree()
103
	{
104
		$catItem = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
105
106
		$this->stub->expects( $this->once() )->method( 'getTree' )
107
			->willReturn( $catItem );
108
109
		$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $this->object->getTree() );
110
	}
111
112
113
	public function testRoot()
114
	{
115
		$this->assertSame( $this->object, $this->object->root( -1 ) );
116
	}
117
118
119
	public function testSearch()
120
	{
121
		$total = 0;
122
		$item = \Aimeos\MShop::create( $this->context, 'locale/site' )->create();
123
124
		$this->stub->expects( $this->once() )->method( 'search' )
125
			->willReturn( map( [$item] ) );
126
127
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
128
	}
129
130
131
	public function testSlice()
132
	{
133
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
134
	}
135
136
137
	public function testSort()
138
	{
139
		$this->assertSame( $this->object, $this->object->sort( 'locale.site.label' ) );
140
	}
141
142
143
	public function testGetController()
144
	{
145
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
146
147
		$this->assertSame( $this->stub, $result );
148
	}
149
150
151
	protected function access( $name )
152
	{
153
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Site\Decorator\Base::class );
154
		$method = $class->getMethod( $name );
155
		$method->setAccessible( true );
156
157
		return $method;
158
	}
159
}
160