Exemplo n.º 1
0
 public function testDelete()
 {
     // test delete()
     $phone = Phone::find(1);
     $this->assertNotNull($phone);
     $phone = Phone::find(1);
     $phone->delete();
     $phone = Phone::find(1);
     $this->assertNull($phone);
     // test delete() with query builder
     // Post is soft delete model
     $posts = Post::where('id', '<', 3)->get();
     $this->assertFalse($posts->isEmpty());
     Post::where('id', '<', 3)->delete();
     $posts = Post::where('id', '<', 3)->get();
     $this->assertTrue($posts->isEmpty());
     // test destroy()
     $phone = Phone::find(2);
     $this->assertNotNull($phone);
     Phone::destroy(2);
     $phone = Phone::find(2);
     $this->assertNull($phone);
     $photos = Photo::all();
     $this->assertFalse($photos->isEmpty());
     Photo::destroy([1, 2, 3]);
     $photos = Photo::all();
     $this->assertTrue($photos->isEmpty());
     // test destopy with non-existing primary key
     // expect no exception
     Photo::destroy([1, 2, 3]);
     $photos = Photo::all();
     $this->assertTrue($photos->isEmpty());
 }