-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathEndpointAfterSaveCallbackTest.php
More file actions
72 lines (63 loc) · 1.81 KB
/
EndpointAfterSaveCallbackTest.php
File metadata and controls
72 lines (63 loc) · 1.81 KB
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
<?php
namespace Muffin\Webservice\Test\TestCase\Model;
use Cake\TestSuite\TestCase;
use Muffin\Webservice\Connection;
use Muffin\Webservice\Model\Resource;
use Muffin\Webservice\Test\test_app\Model\Endpoint\CallbackEndpoint;
class EndpointAfterSaveCallbackTest extends TestCase
{
/**
* @var \Muffin\Webservice\Connection
*/
public $connection;
/**
* @var Endpoint
*/
public $endpoint;
/**
* @inheritDoc
*/
public function setUp()
{
parent::setUp();
$this->connection = new Connection([
'name' => 'test',
'service' => 'Test'
]);
$this->endpoint = new CallbackEndpoint([
'connection' => $this->connection,
'primaryKey' => 'id',
'displayField' => 'title',
'schema' => [
'id' => ['type' => 'int'],
'title' => ['type' => 'string'],
'body' => ['type' => 'string'],
]
]);
}
/**
* Test afterSave return altered data
*/
public function testAfterSave()
{
$resource = new Resource([
'id' => 4,
'title' => 'Loads of fun',
'body' => 'Woot'
]);
$savedResource = $this->endpoint->save($resource);
$this->assertInstanceOf('\Muffin\Webservice\Model\Resource', $savedResource);
$this->assertEquals([
'id' => 4,
'title' => 'Loads of sun',
'body' => 'Woot'
], $savedResource->toArray());
$newResource = $this->endpoint->get(4);
$this->assertInstanceOf('\Muffin\Webservice\Model\Resource', $newResource);
$this->assertEquals([
'id' => 4,
'title' => 'Loads of fun',
'body' => 'Woot'
], $newResource->toArray());
}
}