public function setUp()
 {
     parent::setUp();
     $this->app['artisan']->call('migrate');
     $this->seedTestData();
     Cost::flushEventListeners();
     Cost::boot();
 }
 public function testCorrectlyUpdateProductInventoryAfterCostDeletion()
 {
     $this->assertEquals(0, Product::find(1)->inventory);
     Cost::create(array('unit_cost' => 10.1, 'inventory' => 10, 'product_id' => 1));
     $this->assertEquals(10, Product::find(1)->inventory);
     Cost::find(1)->delete();
     $this->assertEquals(0, Product::find(1)->inventory);
     Cost::create(array('unit_cost' => 10.1, 'inventory' => 10, 'product_id' => 1));
     Cost::create(array('unit_cost' => 7.33, 'inventory' => 10, 'product_id' => 1));
     Cost::find(2)->delete();
     $this->assertEquals(10, Product::find(1)->inventory);
 }
예제 #3
0
 public function run()
 {
     /**
      * Truncate Product Tables before seed faker data
      */
     DB::table('products')->truncate();
     DB::table('product_costs')->truncate();
     $faker = Faker::create();
     for ($i = 0; $i < 10; $i++) {
         $product = Product::create(array('name' => $faker->name, 'driver_id' => $faker->numberBetween(1, 10), 'description' => $faker->text(), 'photos' => array(array('order' => 1, 'url' => $faker->imageUrl(250, 250))), 'tax_amount' => 0.02 + $i * 0.001, 'unit_price' => $faker->randomFloat(1, 2, 10), 'category_id' => $faker->numberBetween(1, 3), 'inventory' => 0, 'average_cost' => 0));
         for ($j = 0; $j < 5; $j++) {
             Cost::create(array('unit_cost' => (5 + $j) / 2, 'inventory' => 10, 'product_id' => $product->id));
         }
     }
 }