BundleTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddProductNoBundle() 0 9 1
A testAddProductBundle() 0 9 1
A tearDown() 0 6 1
A setUp() 0 5 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\Basket\Decorator;
10
11
12
class BundleTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelper::context();
21
		$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context );
22
		$this->object = new \Aimeos\Controller\Frontend\Basket\Decorator\Bundle( $object, $this->context );
23
	}
24
25
26
	protected function tearDown() : void
27
	{
28
		$this->object->clear();
29
		$this->context->session()->set( 'aimeos', [] );
30
31
		unset( $this->object );
32
	}
33
34
35
	public function testAddProductBundle()
36
	{
37
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
38
		$item = $manager->find( 'U:BUNDLE', ['attribute', 'media', 'price', 'product', 'text'] );
39
40
		$this->assertSame( $this->object, $this->object->addProduct( $item, 1 ) );
41
		$this->assertEquals( 1, count( $this->object->get()->getProducts() ) );
42
		$this->assertEquals( 'U:BUNDLE', $this->object->get()->getProduct( 0 )->getProductCode() );
43
		$this->assertEquals( 2, count( $this->object->get()->getProduct( 0 )->getProducts() ) );
44
	}
45
46
47
	public function testAddProductNoBundle()
48
	{
49
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
50
		$item = $manager->find( 'CNC', ['attribute', 'media', 'price', 'product', 'text'] );
51
52
		$this->assertSame( $this->object, $this->object->addProduct( $item, 1 ) );
53
		$this->assertEquals( 1, count( $this->object->get()->getProducts() ) );
54
		$this->assertEquals( 'CNC', $this->object->get()->getProduct( 0 )->getProductCode() );
55
		$this->assertEquals( 0, count( $this->object->get()->getProduct( 0 )->getProducts() ) );
56
	}
57
}
58