CartItemTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testNullDescription() 0 5 1
A testValidation() 0 24 4
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway;
4
5
use InvalidArgumentException;
6
use PHPUnit\Framework\TestCase;
7
8
class CartItemTest extends TestCase
9
{
10
11
	public function testNullDescription(): void
12
	{
13
		$cartItem = new CartItem('foo name', 1, 99);
14
15
		self::assertNull($cartItem->getDescription());
16
	}
17
18
	public function testValidation(): void
19
	{
20
		try {
21
			new CartItem('foo name', 0, 99);
22
			self::fail();
23
24
		} catch (InvalidArgumentException $e) {
25
			self::assertSame('Quantity must be greater than 0. 0 given.', $e->getMessage());
26
		}
27
28
		try {
29
			new CartItem('very long long long cart item name', 1, 99);
30
			self::fail();
31
32
		} catch (InvalidArgumentException $e) {
33
			self::assertSame('Cart item name can have maximum of 20 characters.', $e->getMessage());
34
		}
35
36
		try {
37
			new CartItem('foo name', 1, 99, 'very long long long long long long long long long long cart item description');
38
			self::fail();
39
40
		} catch (InvalidArgumentException $e) {
41
			self::assertSame('Cart item description can have maximum of 40 characters.', $e->getMessage());
42
		}
43
	}
44
45
}
46