forked from picqer/exact-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelTest.php
120 lines (90 loc) · 3.87 KB
/
ModelTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Picqer\Tests;
use Generator;
use PHPUnit\Framework\TestCase;
use Picqer\Financials\Exact\Item;
use Picqer\Financials\Exact\Query\Resultset;
use Picqer\Tests\Support\MocksExactConnection;
class ModelTest extends TestCase
{
use MocksExactConnection;
public function testCanFindModel()
{
$handler = $this->createMockHandlerUsingFixture('item.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->find('00000000-0000-0000-0000-000000000000');
$this->assertInstanceOf(Item::class, $response);
$this->assertEquals('00000000-0000-0000-0000-000000000000', $response->primaryKeyContent());
}
public function testCanGetFirstModel()
{
$handler = $this->createMockHandlerUsingFixture('item.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->first();
$this->assertInstanceOf(Item::class, $response);
$this->assertEquals('00000000-0000-0000-0000-000000000000', $response->primaryKeyContent());
}
public function testCanGetModels()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->get();
$this->assertIsArray($response);
$this->assertInstanceOf(Item::class, $response[0]);
$this->assertCount(2, $response);
}
public function testCanGetModelsAsGenerator()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->getAsGenerator();
$this->assertInstanceOf(Generator::class, $response);
$this->assertCount(2, $response);
}
public function testCanFilterModels()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->filter('IsWebshopItem eq 0');
$this->assertIsArray($response);
$this->assertInstanceOf(Item::class, $response[0]);
$this->assertCount(2, $response);
}
public function testCanFilterModelsAsGenerator()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$response = (new Item($connection))->filterAsGenerator('IsWebshopItem eq 0');
$this->assertInstanceOf(Generator::class, $response);
$this->assertCount(2, $response);
}
public function testCanGetCollectionFromResult()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$item = new Item($connection);
$result = $connection->get($item->url(), []);
$collection = $item->collectionFromResult($result);
$this->assertIsArray($collection);
$this->assertInstanceOf(Item::class, $collection[0]);
$this->assertCount(2, $collection);
}
public function testCanGetCollectionFromResultAsGenerator()
{
$handler = $this->createMockHandlerUsingFixture('items.json');
$connection = $this->createMockConnection($handler);
$item = new Item($connection);
$result = $connection->get($item->url(), []);
$collection = $item->collectionFromResultAsGenerator($result);
$this->assertInstanceOf(Generator::class, $collection);
$this->assertCount(2, $collection);
}
public function testCanGetResultSet()
{
$handler = $this->createMockHandler();
$connection = $this->createMockConnection($handler);
$item = new Item($connection);
$resultset = (new Item($connection))->getResultSet();
$this->assertInstanceOf(Resultset::class, $resultset);
}
}