public function setUp()
 {
     parent::setUp();
     Artisan::call('migrate');
     Product::boot();
     $this->eloquent_product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product');
 }
 public function setUp()
 {
     parent::setUp();
     Artisan::call('migrate');
     Product::boot();
     Description::boot();
     SubProduct::boot();
     Image::boot();
     Feature::boot();
     Variation::boot();
     KeywordProfile::boot();
     Add::boot();
     //es client and index repo for testing integration with index
     $this->es_client = $this->app->make('Elasticsearch\\Client');
     $this->index_repo = $this->app->make('Giftertipster\\Repository\\ProductsIndex\\Product\\ESProductsIndexProductRepository');
     $this->config = \Config::get('index.index_products_type_product');
     $this->index = $this->config['setup']['index'];
     $this->type = $this->config['setup']['type'];
     //seed user id 1 & 2 for tests
     Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]);
     Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]);
     //seed add type id 1 for tests
     Factory::create('Giftertipster\\Entity\\Eloquent\\AddType');
     $this->createStubCategories();
     //mock prod suite validator (validates suite attributes keys)
     //may be overriden in individual tests
     $suite_validator = \Mockery::mock('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface');
     $suite_validator->shouldReceive('validateSuiteAttributesForCreate')->andReturn(true);
     $suite_validator->shouldReceive('validateSuiteAttributesForUpdate')->andReturn(true);
     $this->app->instance('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface', $suite_validator);
 }
 public function testDeleteDeletesProductAndRelationsAndProductRequestReturnsTrue()
 {
     $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();
     //connect product to product request
     Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]);
     $prod_request = $this->app->make('Giftertipster\\Entity\\Eloquent\\ProductRequest');
     $prod_request->fill(['vendor' => 'test', 'vendor_id' => 100, 'user_id' => 1, 'product_id' => null]);
     $this->product->productRequest()->save($prod_request);
     $prod_request_check = $prod_request->where('product_id', '=', 1)->get();
     assertThat($prod_request_check, not(nullValue()));
     //add "add" to product
     $add_type = Factory::create('Giftertipster\\Entity\\Eloquent\\AddType');
     $add = Factory::create('Giftertipster\\Entity\\Eloquent\\Add', ['product_id' => 1, 'add_type_id' => 1]);
     assertThat($add->exists, identicalTo(true));
     $add->occasionCategories()->attach($this->occasion);
     assertThat($add->occasionCategories()->get()->count(), atLeast(1));
     //ACTION
     $response = $data_repo->delete(1);
     assertThat($response, identicalTo(true));
     //get product check data
     $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product');
     $product_check = $product->find(1);
     //get product request check data
     $prod_request_check = $prod_request->where('product_id', '=', 1)->get()->toArray();
     //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_check = $add->newInstance()->get()->toArray();
     $add_category_pivot_check = \DB::table('add_categories')->get();
     assertThat($product_check, nullValue());
     assertThat($prod_request_check, emptyArray());
     assertThat($keyword_profile_check, emptyArray());
     assertThat($occasion_category_count, greaterThan(0));
     assertThat($add_check, emptyArray());
     assertThat($add_category_pivot_check, emptyArray());
     assertThat(Product::get()->toArray(), 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());
 }
 public function testDisableProductOfferingCreatesNewDocIfUpdateDocFails()
 {
     Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $delete_op_mock = Mockery::mock('Giftertipster\\Repository\\ProductSuite\\Operations\\EloquentDeleteOperations');
     $delete_op_mock->shouldReceive('deleteSubProducts')->with(anInstanceOf('Giftertipster\\Entity\\Eloquent\\Product'))->andReturn(true);
     $this->app->instance('Giftertipster\\Repository\\ProductSuite\\Operations\\EloquentDeleteOperations', $delete_op_mock);
     $expected_product_suite = ['is_refreshed' => 0];
     $indexer_mock = Mockery::mock('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface');
     $indexer_mock->shouldReceive('queueUpdateIndex')->with(Mockery::on(function ($product_suite) use($expected_product_suite) {
         if (!empty($this->arrayRecursiveDiff($expected_product_suite, $product_suite))) {
             return false;
         }
         return true;
     }), true, false)->once()->andThrow(new \RuntimeException());
     $indexer_mock->shouldReceive('queueIndex')->with(Mockery::on(function ($product_suite) use($expected_product_suite) {
         if (!empty($this->arrayRecursiveDiff($expected_product_suite, $product_suite))) {
             return false;
         }
         return true;
     }), true, false)->once()->andReturn(true);
     $this->app->instance('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface', $indexer_mock);
     \DB::shouldReceive('beginTransaction')->once();
     \DB::shouldReceive('commit')->once();
     \DB::shouldReceive('rollback')->never();
     $repo = $this->app->make('Giftertipster\\Repository\\ProductSuite\\EloquentProductSuiteRepository');
     $repo->disableProductOffering(1);
     $updated_product = \Giftertipster\Entity\Eloquent\Product::find(1);
     assertThat($updated_product->is_refreshed, equalTo(0));
 }