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