BaseTest   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 133
rs 10
c 1
b 0
f 0
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A testFunction() 0 7 1
A tearDown() 0 3 1
A testCall() 0 12 1
A testSlice() 0 3 1
A access() 0 7 1
A testGet() 0 8 1
A testGetController() 0 5 1
A testParse() 0 3 1
A testSearch() 0 7 1
A setUp() 0 9 1
A testFind() 0 8 1
A testHas() 0 3 1
A testSort() 0 3 1
A testCompare() 0 3 1
A testUses() 0 3 1
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\Cms\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\Cms\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Cms\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\Cms\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Cms\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\Cms\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( '==', 'cms.status', 1 ) );
60
	}
61
62
63
	public function testFind()
64
	{
65
		$item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
66
		$expected = \Aimeos\MShop\Cms\Item\Iface::class;
67
68
		$this->stub->expects( $this->once() )->method( 'find' )->willReturn( $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
			->willReturn( 'cms:has("domain","type","refid")' );
78
79
		$str = $this->object->function( 'cms:has', ['domain', 'type', 'refid'] );
80
		$this->assertEquals( 'cms:has("domain","type","refid")', $str );
81
	}
82
83
84
	public function testGet()
85
	{
86
		$item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
87
		$expected = \Aimeos\MShop\Cms\Item\Iface::class;
88
89
		$this->stub->expects( $this->once() )->method( 'get' )->willReturn( $item );
90
91
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
92
	}
93
94
95
	public function testHas()
96
	{
97
		$this->assertSame( $this->object, $this->object->has( 'product', 'default', -1 ) );
98
	}
99
100
101
	public function testParse()
102
	{
103
		$this->assertSame( $this->object, $this->object->parse( [] ) );
104
	}
105
106
107
	public function testSearch()
108
	{
109
		$item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
110
111
		$this->stub->expects( $this->once() )->method( 'search' )->willReturn( map( [$item] ) );
112
113
		$this->assertEquals( [$item], $this->object->search()->toArray() );
114
	}
115
116
117
	public function testSlice()
118
	{
119
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
120
	}
121
122
123
	public function testSort()
124
	{
125
		$this->assertSame( $this->object, $this->object->sort( 'cms.label' ) );
126
	}
127
128
129
	public function testUses()
130
	{
131
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
132
	}
133
134
135
	public function testGetController()
136
	{
137
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
138
139
		$this->assertSame( $this->stub, $result );
140
	}
141
142
143
	protected function access( $name )
144
	{
145
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Cms\Decorator\Base::class );
146
		$method = $class->getMethod( $name );
147
		$method->setAccessible( true );
148
149
		return $method;
150
	}
151
}
152