|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GGGGino\SkuskuCartBundle\Tests\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
6
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
|
7
|
|
|
use Doctrine\ORM\EntityManager; |
|
8
|
|
|
use Doctrine\ORM\EntityRepository; |
|
9
|
|
|
use GGGGino\SkuskuCartBundle\Model\SkuskuCart; |
|
10
|
|
|
use GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface; |
|
11
|
|
|
use GGGGino\SkuskuCartBundle\Service\CartManager; |
|
12
|
|
|
use GGGGino\SkuskuCartBundle\Tests\TestKernel; |
|
13
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
14
|
|
|
|
|
15
|
|
|
class CartManagerTest extends WebTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
private $client; |
|
18
|
|
|
|
|
19
|
|
|
protected static function createKernel(array $options = []) |
|
20
|
|
|
{ |
|
21
|
|
|
return new TestKernel(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @inheritdoc |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->client = static::createClient(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private function fakeCartTemp() |
|
33
|
|
|
{ |
|
34
|
|
|
return new SkuskuCart(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function fakeCartPermanent() |
|
38
|
|
|
{ |
|
39
|
|
|
$cart = new SkuskuCart(); |
|
40
|
|
|
$reflectionClass = new \ReflectionClass(SkuskuCart::class); |
|
41
|
|
|
|
|
42
|
|
|
$reflectionProperty = $reflectionClass->getProperty('id'); |
|
43
|
|
|
$reflectionProperty->setAccessible(true); |
|
44
|
|
|
$reflectionProperty->setValue($cart, 6); |
|
45
|
|
|
|
|
46
|
|
|
return $cart; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function fakeCartFull() |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$cart = $this->fakeCartPermanent(); |
|
52
|
|
|
return $cart; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testCartTemp() |
|
56
|
|
|
{ |
|
57
|
|
|
/** @var CartManager $cartManager */ |
|
58
|
|
|
$cartManager = $this->createPartialMock(CartManager::class, array('getCartFromCustomer')); |
|
59
|
|
|
$cartManager->expects($this->any()) |
|
|
|
|
|
|
60
|
|
|
->method('getCartFromCustomer') |
|
61
|
|
|
->willReturn($this->fakeCartTemp()); |
|
62
|
|
|
|
|
63
|
|
|
$cart = $cartManager->getCartFromCustomer(); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals(SkuskuCart::class, get_class($cart)); |
|
66
|
|
|
$this->assertTrue($cartManager->isCartTemp($cart)); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testCartPermanent() |
|
70
|
|
|
{ |
|
71
|
|
|
/** @var CartManager $cartManager */ |
|
72
|
|
|
$cartManager = $this->createPartialMock(CartManager::class, array('getCartFromCustomer')); |
|
73
|
|
|
$cartManager->expects($this->any()) |
|
74
|
|
|
->method('getCartFromCustomer') |
|
75
|
|
|
->willReturn($this->fakeCartPermanent()); |
|
76
|
|
|
|
|
77
|
|
|
$cart = $cartManager->getCartFromCustomer(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals(SkuskuCart::class, get_class($cart)); |
|
80
|
|
|
$this->assertFalse($cartManager->isCartTemp($cart)); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testCartFull() |
|
84
|
|
|
{ |
|
85
|
|
|
/** @var CartManager $cartManager */ |
|
86
|
|
|
$cartManager = $this->createPartialMock(CartManager::class, array('getCartFromCustomer')); |
|
87
|
|
|
$cartManager->expects($this->any()) |
|
88
|
|
|
->method('getCartFromCustomer') |
|
89
|
|
|
->willReturn($this->fakeCartPermanent()); |
|
90
|
|
|
|
|
91
|
|
|
$cart = $cartManager->getCartFromCustomer(); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertEquals(SkuskuCart::class, get_class($cart)); |
|
94
|
|
|
$this->assertFalse($cartManager->isCartTemp($cart)); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
} |
This check looks for private methods that have been defined, but are not used inside the class.