Пример #1
0
 public function setUp()
 {
     parent::setUp();
     // Workaround for model event firing.
     // The package Bosnadev\Database used for automatic UUID creation relies
     // on model events (creating) to generate the UUID.
     //
     // Laravel/Lumen currently doesn't fire repeated model events during
     // unit testing, see: https://github.com/laravel/framework/issues/1181
     App\Models\TestEntity::flushEventListeners();
     App\Models\TestEntity::boot();
 }
Пример #2
0
 public function testDeleteManyInvalidId()
 {
     $entities = factory(App\Models\TestEntity::class, 5)->create();
     $rowCount = TestEntity::count();
     $entities->first()->entity_id = (string) Uuid::uuid4();
     $entities->last()->entity_id = (string) Uuid::uuid4();
     $this->delete('/test/entities', ['data' => $entities]);
     $object = json_decode($this->response->getContent());
     $this->assertTrue(is_array($object->invalid));
     $this->assertObjectHasAttribute('entityId', $object->invalid[0]);
     $this->assertNull($object->invalid[1]);
     $this->assertObjectHasAttribute('entityId', $object->invalid[4]);
     $this->assertEquals('The selected entity id is invalid.', $object->invalid[0]->entityId[0]->message);
     $this->assertEquals($rowCount, TestEntity::count());
 }
Пример #3
0
 public function testDeleteManyInvalidId()
 {
     $entity = factory(App\Models\TestEntity::class)->create();
     $this->addRelatedEntities($entity);
     $childCount = TestEntity::find($entity->entity_id)->testMany->count();
     $childEntities = $entity->testMany;
     $childEntities->first()->entity_id = (string) Uuid::uuid4();
     $childEntities->last()->entity_id = (string) Uuid::uuid4();
     $data = array_map(function ($entity) {
         return ['entityId' => $entity->entity_id, 'value' => 'foobar'];
     }, $childEntities->all());
     $this->delete('/test/entities/' . $entity->entity_id . '/children', ['data' => $data]);
     $object = json_decode($this->response->getContent());
     $this->assertTrue(is_array($object->invalid));
     $this->assertObjectHasAttribute('entityId', $object->invalid[0]);
     $this->assertNull($object->invalid[1]);
     $this->assertObjectHasAttribute('entityId', $object->invalid[4]);
     $this->assertEquals('The selected entity id is invalid.', $object->invalid[0]->entityId[0]->message);
     $this->assertEquals($childCount, TestEntity::find($entity->entity_id)->testMany->count());
 }