Passed
Push — master ( 6cf50b...92e939 )
by Aimeos
01:45
created

BaseTest::testGet()   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
dl 0
loc 8
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), 2017-2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Service\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock();
42
43
		$this->setExpectedException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class )
59
			->setConstructorArgs( [$stub, $this->context] )
60
			->getMockForAbstractClass();
61
62
		$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) );
63
64
		$this->assertTrue( $object->invalid() );
65
	}
66
67
68
	public function testFind()
69
	{
70
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
71
72
		$this->stub->expects( $this->once() )->method( 'find' )
73
			->will( $this->returnValue( $item ) );
74
75
		$this->assertSame( $item, $this->object->find( 'test' ) );
76
	}
77
78
79
	public function testGet()
80
	{
81
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
82
83
		$this->stub->expects( $this->once() )->method( 'get' )
84
			->will( $this->returnValue( $item ) );
85
86
		$this->assertSame( $item, $this->object->get( -1 ) );
87
	}
88
89
90
	public function testGetProvider()
91
	{
92
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
93
		$provider = $manager->getProvider( $manager->findItem( 'unitcode', [], 'service', 'delivery' ), 'delivery' );
94
95
		$this->stub->expects( $this->once() )->method( 'getProvider' )
96
			->will( $this->returnValue( $provider ) );
97
98
		$this->assertSame( $provider, $this->object->getProvider( -1 ) );
99
	}
100
101
102
	public function testGetProviders()
103
	{
104
		$this->stub->expects( $this->once() )->method( 'getProviders' )
105
			->will( $this->returnValue( [] ) );
106
107
		$this->assertEquals( [], $this->object->getProviders( 'payment' ) );
108
	}
109
110
111
	public function testProcess()
112
	{
113
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
114
115
		$this->stub->expects( $this->once() )->method( 'process' )
116
			->will( $this->returnValue( new \Aimeos\MShop\Common\Helper\Form\Standard() ) );
117
118
		$this->assertInstanceOf( 'Aimeos\MShop\Common\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) );
119
	}
120
121
122
	public function testUpdatePush()
123
	{
124
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
125
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
126
127
		$this->stub->expects( $this->once() )->method( 'updatePush' )
128
			->will( $this->returnValue( $response ) );
129
130
		$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'test' ) );
131
	}
132
133
134
	public function testUpdateSync()
135
	{
136
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
137
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
138
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
139
140
		$this->stub->expects( $this->once() )->method( 'updateSync' )
141
			->will( $this->returnValue( $item ) );
142
143
		$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, $response, [], 'test', -1 ) );
144
	}
145
146
147
	public function testGetController()
148
	{
149
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
150
151
		$this->assertSame( $this->stub, $result );
152
	}
153
154
155
	protected function access( $name )
156
	{
157
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Service\Decorator\Base::class );
158
		$method = $class->getMethod( $name );
159
		$method->setAccessible( true );
160
161
		return $method;
162
	}
163
}
164