public function run()
 {
     // Uncomment the below to wipe the table clean before populating
     DB::table('wp_postmeta')->truncate();
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         PostMeta::create(['post_id' => $index, 'meta_key' => 'pal_user_id', 'meta_value' => min($index, 5)]);
     }
 }
コード例 #2
0
 public function testDeleteRelatedMetaWhenRemovesAUser()
 {
     $user = Factory::create('User', ['id' => 1]);
     Factory::times(2)->create('PostMeta', ['meta_key' => 'pal_user_id', 'meta_value' => 1]);
     $metaBeforeDelete = $user->meta;
     $user->delete();
     $metaAfterDelete = PostMeta::where('meta_key', '=', 'pal_user_id')->where('meta_value', '=', $user->id)->get();
     assertThat($metaBeforeDelete, is(nonEmptyTraversable()));
     assertThat($metaAfterDelete, is(emptyTraversable()));
 }
コード例 #3
0
 public function testDeleteRelatedMetaModelsWhenRemovesAGallery()
 {
     $gallery = Factory::create('Gallery');
     Factory::create('PostMeta', ['post_id' => 1]);
     $metaBeforeDelete = $gallery->meta;
     $gallery->delete();
     $metaAfterDelete = PostMeta::where('post_id', '=', 1)->get();
     assertThat($metaBeforeDelete, is(nonEmptyTraversable()));
     assertThat($metaAfterDelete, is(emptyTraversable()));
 }