|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Client\Product; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Product\DiscountCollection; |
|
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\ProductCollection; |
|
9
|
|
|
use LauLamanApps\IzettleApi\Client\Product\DiscountBuilderInterface; |
|
10
|
|
|
use LauLamanApps\IzettleApi\Client\Product\LibraryBuilder; |
|
11
|
|
|
use LauLamanApps\IzettleApi\Client\Product\ProductBuilderInterface; |
|
12
|
|
|
use Mockery; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Ramsey\Uuid\Uuid; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @small |
|
18
|
|
|
*/ |
|
19
|
|
|
final class LibraryBuilderTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
*/ |
|
24
|
|
|
public function createFromResponse() |
|
25
|
|
|
{ |
|
26
|
|
|
$json = file_get_contents(dirname(__FILE__) . '/json-files/library.json'); |
|
27
|
|
|
$data = json_decode($json, true); |
|
28
|
|
|
|
|
29
|
|
|
$productBuilderMock = Mockery::mock(ProductBuilderInterface::class); |
|
30
|
|
|
$productBuilderMock->shouldReceive('buildFromArray')->with($data['products']) |
|
31
|
|
|
->once()->andReturn(new ProductCollection()); |
|
32
|
|
|
$productBuilderMock->shouldReceive('buildFromArray')->with($data['deletedProducts']) |
|
33
|
|
|
->once()->andReturn(new ProductCollection()); |
|
34
|
|
|
|
|
35
|
|
|
$discountBuilderMock = Mockery::mock(DiscountBuilderInterface::class); |
|
36
|
|
|
$discountBuilderMock->shouldReceive('buildFromArray')->with($data['discounts']) |
|
37
|
|
|
->once()->andReturn(new DiscountCollection()); |
|
38
|
|
|
$discountBuilderMock->shouldReceive('buildFromArray')->with($data['deletedDiscounts']) |
|
39
|
|
|
->once()->andReturn(new DiscountCollection()); |
|
40
|
|
|
|
|
41
|
|
|
$builder = new LibraryBuilder($productBuilderMock, $discountBuilderMock); |
|
42
|
|
|
|
|
43
|
|
|
$library = $builder->buildFromJson($json); |
|
44
|
|
|
|
|
45
|
|
|
self::assertInstanceOf(Uuid::class, $library->getFromEventLogUuid()); |
|
46
|
|
|
self::assertInstanceOf(Uuid::class, $library->getUntilEventLogUuid()); |
|
47
|
|
|
|
|
48
|
|
|
self::assertInstanceOf(ProductCollection::class, $library->getProducts()); |
|
49
|
|
|
self::assertInstanceOf(DiscountCollection::class, $library->getDiscounts()); |
|
50
|
|
|
self::assertInstanceOf(ProductCollection::class, $library->getDeletedProducts()); |
|
51
|
|
|
self::assertInstanceOf(DiscountCollection::class, $library->getDeletedDiscounts()); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|