1: <?php
2: namespace tests\integration\barebones\models\encounters;
3:
4: use tests\integration\barebones\BarebonesTestCase;
5: use tests\integration\barebones\BarebonesConstants;
6:
7: use barebones\models\examples\ExampleModel;
8: use Session;
9:
10: class ConcurrentCollectionTest extends BarebonesTestCase
11: {
12: public function testConcurrentCollectionAccess()
13: {
14: Session::set('usr_cur_customer_id', 8);
15:
16: $ids = array();
17: for($i = 0; $i < 3; $i++){
18: $model = new ExampleModel();
19: $model->exa_string = 'test';
20: $model->save();
21: $ids[] = $model->exa_id;
22: }
23: $collectionConcurrent = ExampleModel::where('exa_id', 'IN', $ids)->fetch();
24: $collectionDestroy = ExampleModel::where('exa_id', 'IN', $ids)->fetch();
25:
26: $this->assertNotNull($collectionConcurrent->nextModelConcurrentSafe(), "Pulls first model");
27: $collectionDestroy->nextModel();
28: $destroyMe = $collectionDestroy->nextModel();
29: $destroyedID = $destroyMe->id;
30: $destroyMe->destroy();
31:
32: $nextConcurrent = $collectionConcurrent->nextModelConcurrentSafe();
33: $this->assertNotNull($nextConcurrent, "Pulls next model");
34: $this->assertNotEquals($nextConcurrent->id, $destroyedID, "Next model is NOT second model");
35: $this->assertNull($collectionConcurrent->nextModelConcurrentSafe(), "There should be no more models");
36: }
37: }
38:
39: