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

StandardTest::testProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
rs 9.7333
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 Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\Controller\Frontend\Service;
11
12
13
class StandardTest 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...
14
{
15
	private $object;
16
	private $context;
17
	private static $basket;
18
19
20
	protected function setUp()
21
	{
22
		\Aimeos\MShop::cache( true );
23
24
		$this->context = \TestHelperFrontend::getContext();
25
		$this->object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context );
26
	}
27
28
29
	public static function setUpBeforeClass()
30
	{
31
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperFrontend::getContext() );
32
		$orderBaseMgr = $orderManager->getSubManager( 'base' );
33
		self::$basket = $orderBaseMgr->createItem();
34
	}
35
36
37
	protected function tearDown()
38
	{
39
		\Aimeos\MShop::cache( false );
40
		unset( $this->object, $this->context );
41
	}
42
43
44
	public function testFind()
45
	{
46
		$item = $this->object->find( $this->getServiceItem()->getCode() );
47
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Item\\Iface', $item );
48
	}
49
50
51
	public function testGet()
52
	{
53
		$item = $this->object->get( $this->getServiceItem()->getId() );
54
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Item\\Iface', $item );
55
	}
56
57
58
	public function testGetProvider()
59
	{
60
		$provider = $this->object->getProvider( $this->getServiceItem()->getId() );
61
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider );
62
	}
63
64
65
	public function testGetProviders()
66
	{
67
		$providers = $this->object->getProviders( 'delivery' );
68
		$this->assertGreaterThan( 0, count( $providers ) );
69
70
		foreach( $providers as $provider ) {
71
			$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider );
72
		}
73
	}
74
75
76
	public function testProcess()
77
	{
78
		$form = new \Aimeos\MShop\Common\Helper\Form\Standard();
79
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
80
		$serviceId = \Aimeos\MShop::create( $this->context, 'service' )->findItem( 'unitcode' )->getId();
81
82
		$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' )
83
			->disableOriginalConstructor()
84
			->setMethods( ['process'] )
85
			->getMock();
86
87
		$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' )
88
			->setConstructorArgs( [$this->context] )
89
			->setMethods( ['getProvider'] )
90
			->getMock();
91
92
		\Aimeos\MShop::inject( 'service', $manager );
93
94
		$provider->expects( $this->once() )->method( 'process' )->will( $this->returnValue( $form ) );
95
		$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) );
96
97
98
		$result = $this->object->process( $item, $serviceId, [], [] );
99
		$this->assertInstanceOf( \Aimeos\MShop\Common\Helper\Form\Iface::class, $result );
100
	}
101
102
103
	public function testUpdatePush()
104
	{
105
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
106
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
107
108
		$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) );
109
110
		$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'unitcode' ) );
111
	}
112
113
114
	public function testUpdateSync()
115
	{
116
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
117
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
118
119
		$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' )
120
			->setMethods( ['updateSync', 'query', 'isImplemented'] )
121
			->disableOriginalConstructor()
122
			->getMock();
123
124
		$orderManager = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
125
			->setConstructorArgs( array( $this->context ) )
126
			->setMethods( ['getItem'] )
127
			->getMock();
128
129
		$serviceManager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' )
130
			->setConstructorArgs( array( $this->context ) )
131
			->setMethods( ['getProvider'] )
132
			->getMock();
133
134
		\Aimeos\MShop::inject( 'order', $orderManager );
135
		\Aimeos\MShop::inject( 'service', $serviceManager );
136
137
138
		$orderManager->expects( $this->once() )->method( 'getItem' )->will( $this->returnValue( $item ) );
139
		$serviceManager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) );
140
		$provider->expects( $this->once() )->method( 'updateSync' )->will( $this->returnValue( $item ) );
141
		$provider->expects( $this->once() )->method( 'isImplemented' )->will( $this->returnValue( true ) );
142
		$provider->expects( $this->once() )->method( 'query' );
143
144
		$this->object->updateSync( $request, 'unitcode', -1 );
145
	}
146
147
148
	/**
149
	 * @return \Aimeos\MShop\Service\Item\Iface
150
	 */
151
	protected function getServiceItem()
152
	{
153
		$manager = \Aimeos\MShop\Service\Manager\Factory::create( \TestHelperFrontend::getContext() );
154
		return $manager->findItem( 'unitcode' );
155
	}
156
}
157