Completed
Push — master ( 7bc99f...7ea700 )
by Aimeos
02:12
created

BaseTest::testUpdatePush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Service\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()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Service\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Service\Decorator\Base' )
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' )->getMock();
42
43
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Exception' );
44
45
		$this->getMockBuilder( '\Aimeos\Controller\Frontend\Service\Decorator\Base' )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Service\Standard' )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Service\Decorator\Base' )
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 testCheckAttributes()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'checkAttributes' )
71
			->will( $this->returnValue( [] ) );
72
73
		$this->assertEquals( [], $this->object->checkAttributes( -1, [] ) );
74
	}
75
76
77
	public function testGetProvider()
78
	{
79
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' );
80
		$provider = $manager->getProvider( $manager->findItem( 'unitcode', [], 'service', 'delivery' ) );
81
82
		$this->stub->expects( $this->once() )->method( 'getProvider' )
83
			->will( $this->returnValue( $provider ) );
84
85
		$this->assertSame( $provider, $this->object->getProvider( -1 ) );
86
	}
87
88
89
	public function testGetProviders()
90
	{
91
		$this->stub->expects( $this->once() )->method( 'getProviders' )
92
			->will( $this->returnValue( [] ) );
93
94
		$this->assertEquals( [], $this->object->getProviders( 'payment' ) );
95
	}
96
97
98
	public function testProcess()
99
	{
100
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
101
102
		$this->stub->expects( $this->once() )->method( 'process' )
103
			->will( $this->returnValue( new \Aimeos\MShop\Common\Item\Helper\Form\Standard() ) );
104
105
		$this->assertInstanceOf( 'Aimeos\MShop\Common\Item\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) );
106
	}
107
108
109
	public function testUpdatePush()
110
	{
111
		$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock();
112
		$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock();
113
114
		$this->stub->expects( $this->once() )->method( 'updatePush' )
115
			->will( $this->returnValue( $response ) );
116
117
		$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $this->object->updatePush( $request, $response, 'test' ) );
118
	}
119
120
121
	public function testUpdateSync()
122
	{
123
		$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock();
124
		$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock();
125
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
126
127
		$this->stub->expects( $this->once() )->method( 'updateSync' )
128
			->will( $this->returnValue( $item ) );
129
130
		$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, $response, [], 'test', -1 ) );
131
	}
132
133
134
	public function testGetController()
135
	{
136
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
137
138
		$this->assertSame( $this->stub, $result );
139
	}
140
141
142
	protected function access( $name )
143
	{
144
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Service\Decorator\Base' );
145
		$method = $class->getMethod( $name );
146
		$method->setAccessible( true );
147
148
		return $method;
149
	}
150
}
151