CartManagerTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A fakeCartFull() 0 4 1
A fakeCartPermanent() 0 10 1
A testCartTemp() 0 12 1
A fakeCartTemp() 0 3 1
A testCartFull() 0 12 1
A setUp() 0 3 1
A testCartPermanent() 0 12 1
A createKernel() 0 3 1
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()
0 ignored issues
show
Unused Code introduced by
The method fakeCartFull() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on GGGGino\SkuskuCartBundle\Service\CartManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        $cartManager->/** @scrutinizer ignore-call */ 
60
                      expects($this->any())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $cart can also be of type null; however, parameter $cart of GGGGino\SkuskuCartBundle...rtManager::isCartTemp() does only seem to accept GGGGino\SkuskuCartBundle\Model\SkuskuCart, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        $this->assertTrue($cartManager->isCartTemp(/** @scrutinizer ignore-type */ $cart));
Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $cart can also be of type null; however, parameter $cart of GGGGino\SkuskuCartBundle...rtManager::isCartTemp() does only seem to accept GGGGino\SkuskuCartBundle\Model\SkuskuCart, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
        $this->assertFalse($cartManager->isCartTemp(/** @scrutinizer ignore-type */ $cart));
Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $cart can also be of type null; however, parameter $cart of GGGGino\SkuskuCartBundle...rtManager::isCartTemp() does only seem to accept GGGGino\SkuskuCartBundle\Model\SkuskuCart, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
        $this->assertFalse($cartManager->isCartTemp(/** @scrutinizer ignore-type */ $cart));
Loading history...
95
    }
96
}