|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NStack\Tests; |
| 4 | + |
| 5 | +use NStack\Clients\CollectionsClient; |
| 6 | +use NStack\Tests\objects\CollectionItem; |
| 7 | +use NStack\Tests\objects\CollectionShow1; |
| 8 | +use NStack\Tests\objects\CollectionShow2; |
| 9 | + |
| 10 | +class CollectionsTest extends TestCase |
| 11 | +{ |
| 12 | + public function testView() |
| 13 | + { |
| 14 | + $client = $this->getClientWithMockedGet('collection-show-1.json'); |
| 15 | + $client = new CollectionsClient($this->getConfig(), $client); |
| 16 | + $entry = $client->view(10); |
| 17 | + foreach ($entry as $item) { |
| 18 | + $this->assertInstanceOf(CollectionShow1::class, new CollectionShow1($item)); |
| 19 | + } |
| 20 | + |
| 21 | + $client = $this->getClientWithMockedGet('collection-show-2.json'); |
| 22 | + $client = new CollectionsClient($this->getConfig(), $client); |
| 23 | + $entry = $client->view(10); |
| 24 | + foreach ($entry as $item) { |
| 25 | + $this->assertInstanceOf(CollectionShow2::class, new CollectionShow2($item)); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + public function testCreateItem() |
| 30 | + { |
| 31 | + $client = $this->getClientWithMockedPost('collection-create-item.json'); |
| 32 | + $client = new CollectionsClient($this->getConfig(), $client); |
| 33 | + $entry = $client->createItem(10, ["id" => 39, "key" => "41"]); |
| 34 | + $this->assertInstanceOf(CollectionItem::class, new CollectionItem($entry)); |
| 35 | + } |
| 36 | + |
| 37 | + public function testDeleteItem() |
| 38 | + { |
| 39 | + $mock = $this->getMockBuilder('CollectionsClient') |
| 40 | + ->setMethods(array('delete')) |
| 41 | + ->getMock(); |
| 42 | + |
| 43 | + $mock->expects($this->once()) |
| 44 | + ->method('delete'); |
| 45 | + |
| 46 | + $mock->delete(10, 15); |
| 47 | + } |
| 48 | + |
| 49 | + public function testUpdateItem() |
| 50 | + { |
| 51 | + $client = $this->getClientWithMockedPost('collection-update-item.json'); |
| 52 | + $client = new CollectionsClient($this->getConfig(), $client); |
| 53 | + $entry = $client->updateItem(10, 315, ["id" => 39, "key" => "50"]); |
| 54 | + $this->assertInstanceOf(CollectionItem::class, new CollectionItem($entry)); |
| 55 | + } |
| 56 | + |
| 57 | + public function testViewItem() |
| 58 | + { |
| 59 | + $client = $this->getClientWithMockedGet('collection-show-item.json'); |
| 60 | + $client = new CollectionsClient($this->getConfig(), $client); |
| 61 | + $entry = $client->viewItem(39, 315); |
| 62 | + $this->assertInstanceOf(CollectionItem::class, new CollectionItem($entry)); |
| 63 | + } |
| 64 | +} |
0 commit comments