BaseTest   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 36
dl 0
loc 106
c 0
b 0
f 0
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A testCompare() 0 3 1
A testSort() 0 3 1
A testProduct() 0 3 1
A setUp() 0 9 1
A testSlice() 0 3 1
A access() 0 7 1
A testSearch() 0 8 1
A testGetController() 0 3 1
A testParse() 0 3 1
A testGet() 0 9 1
A testCall() 0 12 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Stock\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\Stock\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Stock\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\Stock\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Stock\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\Stock\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 testProduct()
58
	{
59
		$this->assertSame( $this->object, $this->object->product( ['123', '456'] ) );
60
	}
61
62
63
	public function testCompare()
64
	{
65
		$this->assertSame( $this->object, $this->object->compare( '==', 'stock.dateback', '2000-01-01 00:00:00' ) );
66
	}
67
68
69
	public function testGet()
70
	{
71
		$item = \Aimeos\MShop::create( $this->context, 'stock' )->create();
72
		$expected = \Aimeos\MShop\Stock\Item\Iface::class;
73
74
		$this->stub->expects( $this->once() )->method( 'get' )
75
			->willReturn( $item );
76
77
		$this->assertInstanceOf( $expected, $this->object->get( 1 ) );
78
	}
79
80
81
	public function testParse()
82
	{
83
		$this->assertSame( $this->object, $this->object->parse( [] ) );
84
	}
85
86
87
	public function testSearch()
88
	{
89
		$item = \Aimeos\MShop::create( $this->context, 'stock' )->create();
90
91
		$this->stub->expects( $this->once() )->method( 'search' )
92
			->willReturn( map( [$item] ) );
93
94
		$this->assertEquals( [$item], $this->object->search()->toArray() );
95
	}
96
97
98
	public function testSlice()
99
	{
100
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
101
	}
102
103
104
	public function testSort()
105
	{
106
		$this->assertSame( $this->object, $this->object->sort( 'stock' ) );
107
	}
108
109
110
	public function testGetController()
111
	{
112
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
113
	}
114
115
116
	protected function access( $name )
117
	{
118
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Stock\Decorator\Base::class );
119
		$method = $class->getMethod( $name );
120
		$method->setAccessible( true );
121
122
		return $method;
123
	}
124
}
125