ProductsServiceTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 31
c 1
b 0
f 0
dl 0
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A getById_WithValidId_BatchUsageFalse() 0 12 1
A getById_WithValidId_ValidResponse() 0 17 1
A getById_WithValidId_BatchUsage() 0 12 1
1
<?php
2
3
namespace Dolibarr\Client\Tests\Service;
4
5
use Dolibarr\Client\Domain\Product\Product;
6
use Dolibarr\Client\Domain\Product\ProductId;
7
use Dolibarr\Client\Service\ProductsService;
8
9
/**
10
 * @package Dolibarr\Client\Tests\Service
11
 */
12
final class ProductsServiceTest extends ServiceTest
13
{
14
    /**
15
     * @var ProductsService()
16
     */
17
    private $service;
18
19
    /**
20
     * Setup the service.
21
     */
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
        $this->service = new ProductsService($this->mockClient(), $this->serializer());
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function getById_WithValidId_ValidResponse()
32
    {
33
        $this->mockClient()
34
            ->expects($this->once())
35
            ->method('get')
36
            ->with('products/121')
37
            ->willReturn($this->buildResponse('Products/getById'));
38
39
        $product = $this->service->getById(new ProductId(121));
40
41
        $this->assertInstanceOf(Product::class, $product);
42
43
        $this->assertEquals('test', $product->getLabel());
44
        $this->assertEquals(121, $product->getId());
45
        $this->assertEquals('86768795768484', $product->getBarcode());
46
47
        $this->assertFalse($product->isBatchUsage());
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function getById_WithValidId_BatchUsage()
54
    {
55
        $this->mockClient()
56
            ->expects($this->once())
57
            ->method('get')
58
            ->with('products/121')
59
            ->willReturn($this->buildResponse('Products/getById-batchUsage'));
60
61
        $product = $this->service->getById(new ProductId(121));
62
63
        $this->assertInstanceOf(Product::class, $product);
64
        $this->assertTrue($product->isBatchUsage());
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function getById_WithValidId_BatchUsageFalse()
71
    {
72
        $this->mockClient()
73
            ->expects($this->once())
74
            ->method('get')
75
            ->with('products/121')
76
            ->willReturn($this->buildResponse('Products/getById-batchUsage-false'));
77
78
        $product = $this->service->getById(new ProductId(121));
79
80
        $this->assertInstanceOf(Product::class, $product);
81
        $this->assertFalse($product->isBatchUsage());
82
    }
83
}
84