Passed
Push — master ( ff9225...fa6243 )
by Aimeos
02:02
created

StandardTest::testGetItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\Controller\Frontend\Order;
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
18
19
	protected function setUp()
20
	{
21
		\Aimeos\MShop::cache( true );
22
23
		$this->context = \TestHelperFrontend::getContext();
24
		$this->object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
25
	}
26
27
28
	protected function tearDown()
29
	{
30
		\Aimeos\MShop::cache( false );
31
		unset( $this->object, $this->context );
32
	}
33
34
35
	public function testAdd()
36
	{
37
		$this->assertSame( $this->object, $this->object->add( -1, [] ) );
38
	}
39
40
41
	public function testCompare()
42
	{
43
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
44
	}
45
46
47
	public function testGet()
48
	{
49
		$manager = \Aimeos\MShop::create( $this->context, 'order' );
50
		$items = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1) );
51
52
		if( ( $item = reset( $items ) ) === null ) {
53
			throw new \RuntimeException( 'No order item found' );
54
		}
55
56
		$this->assertEquals( $item, $this->object->get( $item->getId(), false ) );
57
	}
58
59
60
	public function testParse()
61
	{
62
		$this->assertSame( $this->object, $this->object->parse( [] ) );
63
	}
64
65
66
	public function testSave()
67
	{
68
		$manager = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class )
69
			->setConstructorArgs( [$this->context] )
70
			->setMethods( ['saveItem'] )
71
			->getMock();
72
73
		\Aimeos\MShop::inject( 'order', $manager );
74
75
		$item = $manager->createItem();
76
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
77
78
		$manager->expects( $this->once() )->method( 'saveItem' )->will( $this->returnArgument( 0 ) );
79
80
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $object->save( $item ) );
81
	}
82
83
84
	public function testSearch()
85
	{
86
		$userId = \Aimeos\MShop::create( $this->context, 'customer' )->findItem( 'UTC001' )->getId();
87
		$this->context->setUserId( $userId );
88
89
		$total = 0;
90
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
91
92
		$this->assertGreaterThanOrEqual( 10, $object->search( $total ) );
93
	}
94
95
96
	public function testSlice()
97
	{
98
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
99
	}
100
101
102
	public function testSort()
103
	{
104
		$this->assertSame( $this->object, $this->object->sort( 'order.id' ) );
105
	}
106
107
108
	public function testStore()
109
	{
110
		$class = \Aimeos\Controller\Common\Order\Standard::class;
111
112
		$manager = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class )
113
			->setConstructorArgs( [$this->context] )
114
			->setMethods( ['saveItem'] )
115
			->getMock();
116
117
		\Aimeos\MShop::inject( 'order', $manager );
118
119
		$stub = $this->getMockBuilder( $class )
120
			->setConstructorArgs( [$this->context] )
121
			->setMethods( ['block'] )
122
			->getMock();
123
124
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
125
		$item = $manager->createItem()->setBaseId( 1 );
126
127
		$manager->expects( $this->once() )->method( 'saveItem' )->will( $this->returnValue( $item ) );
128
		$stub->expects( $this->once() )->method( 'block' )->will( $this->returnValue( $item ) );
129
130
		\Aimeos\Controller\Common\Order\Factory::inject( $class, $stub );
131
		$this->assertEquals( $item, $object->store() );
132
		\Aimeos\Controller\Common\Order\Factory::inject( $class, null );
133
	}
134
135
136
	public function testStoreLimit()
137
	{
138
		$this->context->getConfig()->set( 'controller/frontend/order/limit-seconds', 86400 * 365 );
139
140
		$manager = \Aimeos\MShop::create( $this->context, 'order/base' );
141
		$result = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1 ) );
142
143
		if( ( $item = reset( $result ) ) === false ) {
144
			throw new \RuntimeException( 'No order base item found' );
145
		}
146
147
		$this->setExpectedException( \Aimeos\Controller\Frontend\Order\Exception::class );
148
		$this->object->add( $item->getId() )->store();
149
	}
150
}
151