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