public function testDeleteDeletesProductAndIdeaRelationAndReturnsTrue() { $index_repo = Mockery::mock('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface'); $index_repo->shouldReceive('deleteProductAndAdds')->with(1, true)->once()->andReturn(true); $this->app->instance('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface', $index_repo); $data_repo = $this->dataRepoSetup(); $this->getDataRepoData(); //make second product $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $product->fill(['user_id' => 1, 'vendor' => 'amazon', 'vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'test title', 'department' => 'test department', 'min_price_amount' => 4000, 'min_price_currency' => 'USD', 'min_price_formatted' => '$40.00', 'max_price_amount' => 4000, 'max_price_currency' => 'USD', 'max_price_formatted' => '$40.00', 'reviews_url' => 'reviewsurl.com', 'detail_url' => 'detailurl.com'])->save(); //connect products to idea Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $idea = $this->app->make('Giftertipster\\Entity\\Eloquent\\Idea'); $idea->fill(['user_id' => 1, 'vendor' => 'test', 'vendor_id' => 100, 'description' => 'test', 'add_profile' => '', 'is_fulfilled' => 0]); $this->product->ideas()->save($idea); //product id 1 $product->ideas()->save($idea); //product id 2 $idea_check = $idea->where('product_id', '=', 1)->get(); assertThat($idea_check, not(nullValue())); $idea_check = $idea->where('product_id', '=', 2)->get(); assertThat($idea_check, not(nullValue())); //ACTION $response = $data_repo->delete(1); assertThat($response, identicalTo(true)); $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $product_check = $product->find(1); $idea_check = $idea->has('products')->get()->toArray(); assertThat($product_check, nullValue()); assertThat($idea_check, arrayWithSize(1)); assertThat($idea->exists(), equalTo(true)); //get keyword profile check data $keyword_profile = $this->app->make('Giftertipster\\Entity\\Eloquent\\KeywordProfile'); $keyword_profile_check = $keyword_profile->get()->toArray(); $occasion_category = $this->app->make('Giftertipster\\Entity\\Eloquent\\Category\\OccasionCategory'); $occasion_category_count = $occasion_category->get()->count(); //get "add" check data $add = $this->app->make('Giftertipster\\Entity\\Eloquent\\Add'); $add_check = $add->get()->toArray(); $add_category_pivot_check = \DB::table('add_categories')->get(); assertThat($keyword_profile_check, emptyArray()); assertThat($occasion_category_count, greaterThan(0)); assertThat($add_check, emptyArray()); assertThat($add_category_pivot_check, emptyArray()); assertThat(Image::get()->toArray(), emptyArray()); assertThat(Description::get()->toArray(), emptyArray()); assertThat(Feature::get()->toArray(), emptyArray()); assertThat(SubProduct::get()->toArray(), emptyArray()); assertThat(Variation::get()->toArray(), emptyArray()); }