1
|
|
|
<?php |
2
|
|
|
namespace Fathomminds\Rest\Tests\Integration\Clusterpoint; |
3
|
|
|
|
4
|
|
|
use Fathomminds\Rest\Exceptions\RestException; |
5
|
|
|
use Fathomminds\Rest\Examples\Clusterpoint\Models\FooModel; |
6
|
|
|
|
7
|
|
|
class IntegrationTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
public function testOnRealData() |
10
|
|
|
{ |
11
|
|
|
$model = new FooModel; |
12
|
|
|
$resource = new \StdClass; |
13
|
|
|
$resource->title = 'CREATED'; |
14
|
|
|
$model->createFromObject($resource); |
15
|
|
|
|
16
|
|
|
$model->create(); |
17
|
|
|
$id = $model->getProperty('_id'); |
18
|
|
|
$this->assertTrue(!empty($id)); |
19
|
|
|
|
20
|
|
|
try { |
21
|
|
|
$model->create(); |
22
|
|
|
$this->assertEquals(1, 0); //Shouldn't reach this line |
23
|
|
|
} catch (RestException $ex) { |
24
|
|
|
$this->assertEquals('Primary key collision', $ex->getMessage()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$model = new FooModel; |
28
|
|
|
$list = $model->all(); |
29
|
|
|
$this->assertCount(1, $list); |
30
|
|
|
$this->assertEquals($id, $list[0]->_id); |
31
|
|
|
$this->assertEquals('CREATED', $list[0]->title); |
32
|
|
|
|
33
|
|
|
$model = new FooModel; |
34
|
|
|
$model->one($id); |
35
|
|
|
$this->assertEquals($id, $model->getProperty('_id')); |
36
|
|
|
$this->assertEquals('CREATED', $model->getProperty('title')); |
37
|
|
|
|
38
|
|
|
$model->setProperty('title', 'UPDATED'); |
39
|
|
|
$model->update(); |
40
|
|
|
|
41
|
|
|
$model = new FooModel; |
42
|
|
|
$model->one($id); |
43
|
|
|
$this->assertEquals($id, $model->getProperty('_id')); |
44
|
|
|
$this->assertEquals('UPDATED', $model->getProperty('title')); |
45
|
|
|
|
46
|
|
|
$model->delete(); |
47
|
|
|
$this->assertTrue(empty(get_object_vars($model->getResource()))); |
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
$model = new FooModel; |
51
|
|
|
$model->one($id); |
52
|
|
|
} catch (RestException $ex) { |
53
|
|
|
$this->assertEquals('Resource does not exist', $ex->getMessage()); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|