|
2 | 2 |
|
3 | 3 | namespace BaoPham\DynamoDb\Tests;
|
4 | 4 |
|
| 5 | +use BaoPham\DynamoDb\NotSupportedException; |
| 6 | +use \Illuminate\Database\Eloquent\ModelNotFoundException; |
| 7 | + |
5 | 8 | /**
|
6 | 9 | * Class DynamoDbCompositeModelTest
|
7 | 10 | *
|
@@ -52,6 +55,66 @@ public function testFindRecord()
|
52 | 55 | $this->assertEquals($seedName, $item->name);
|
53 | 56 | }
|
54 | 57 |
|
| 58 | + public function testFindMultiple() |
| 59 | + { |
| 60 | + $this->expectException(NotSupportedException::class); |
| 61 | + $this->testModel->find([['id1' => 'bar', 'id2' => 'foo']]); |
| 62 | + } |
| 63 | + |
| 64 | + public function testFindOrFailRecordPass() |
| 65 | + { |
| 66 | + $seed = $this->seed(); |
| 67 | + $seedId = array_get($seed, 'id.S'); |
| 68 | + $seedId2 = array_get($seed, 'id2.S'); |
| 69 | + $seedName = array_get($seed, 'name.S'); |
| 70 | + |
| 71 | + $item = $this->testModel->findOrFail(['id' => $seedId, 'id2' => $seedId2]); |
| 72 | + |
| 73 | + $this->assertNotEmpty($item); |
| 74 | + $this->assertEquals($seedId, $item->id); |
| 75 | + $this->assertEquals($seedId2, $item->id2); |
| 76 | + $this->assertEquals($seedName, $item->name); |
| 77 | + } |
| 78 | + |
| 79 | + public function testFindOrFailMultiple() |
| 80 | + { |
| 81 | + $this->expectException(NotSupportedException::class); |
| 82 | + $this->testModel->findOrFail([['id' => 'bar', 'id2' => 'foo']]); |
| 83 | + } |
| 84 | + |
| 85 | + public function testFirstOrFailRecordPass() |
| 86 | + { |
| 87 | + $seed = $this->seed(); |
| 88 | + $seedId = array_get($seed, 'id.S'); |
| 89 | + $seedId2 = array_get($seed, 'id2.S'); |
| 90 | + $seedName = array_get($seed, 'name.S'); |
| 91 | + |
| 92 | + $first = $this->testModel |
| 93 | + ->where('id', $seedId) |
| 94 | + ->where('id2', $seedId2) |
| 95 | + ->firstOrFail(); |
| 96 | + |
| 97 | + $this->assertNotEmpty($first); |
| 98 | + $this->assertEquals($seedId, $first->id); |
| 99 | + $this->assertEquals($seedId2, $first->id2); |
| 100 | + $this->assertEquals($seedName, $first->name); |
| 101 | + } |
| 102 | + |
| 103 | + public function testFindOrFailRecordFail() |
| 104 | + { |
| 105 | + $this->expectException(ModelNotFoundException::class); |
| 106 | + $this->testModel->findOrFail(['id' => 'failure-expected', 'id2' => 'expected-to-fail']); |
| 107 | + } |
| 108 | + |
| 109 | + public function testFirstOrFailRecordFail() |
| 110 | + { |
| 111 | + $this->expectException(ModelNotFoundException::class); |
| 112 | + $this->testModel |
| 113 | + ->where('id', 'failure-expected') |
| 114 | + ->where('id2', 'expected-to-fail') |
| 115 | + ->firstOrFail(); |
| 116 | + } |
| 117 | + |
55 | 118 | public function testUpdateRecord()
|
56 | 119 | {
|
57 | 120 | $seed = $this->seed();
|
|
0 commit comments