GGGGino /
SkuskuCartBundle
| 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
|
|||||||
| 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
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
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
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
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
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
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
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
Loading history...
|
|||||||
| 95 | } |
||||||
| 96 | } |
This check looks for private methods that have been defined, but are not used inside the class.