/**
  * A basic test example.
  *
  * @return void
  */
 public function testSamplingCreationWithPost()
 {
     $product = App\Product::with('sensors')->get()->random();
     $generic_sensors = App\GenericSensor::all();
     $generic_sensor_with_random_function = array();
     foreach ($generic_sensors as $generic_sensor) {
         // Humidity, Pressure, Temperature
         switch ($generic_sensor->alias) {
             case "Humidity":
                 $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomHumidityValue';
                 break;
             case "Temperature":
                 $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomTemperatureValue';
                 break;
             case "Pressure":
                 $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomPressureValue';
                 break;
         }
     }
     $newSamplings = array();
     foreach ($product->sensors as $sensor) {
         $gs_id = $sensor->generic_sensor_id;
         if (!array_has($generic_sensor_with_random_function, $gs_id)) {
             continue;
         }
         $sensor_random_value = call_user_func(array($this, $generic_sensor_with_random_function[$gs_id]));
         array_push($newSamplings, array('generic_sensor_id' => $gs_id, 'value' => $sensor_random_value));
     }
     $request_body = array('product_id' => App\Product::all()->random()->getkey(), 'samplings' => $newSamplings);
     $this->post('api/samplings/create', $request_body)->see('Created ' . count($newSamplings) . ' sampling(s)');
 }
 /**
  * Test the product creating by sending a post to the product creation route
  *
  * @return void
  */
 public function testProductCreationWithPost()
 {
     $newProduct = factory(App\Product::class)->make();
     $genericSensorIdsCollection = App\GenericSensor::all("id");
     $genericSensorIds = array();
     foreach ($genericSensorIdsCollection->all() as $genericSensor) {
         $genericSensorIds[] = $genericSensor->id;
     }
     $this->post("api/products/create", array("id" => $newProduct->id, "version" => $newProduct->version, "sensors" => $genericSensorIds));
     $this->assertNotNull(App\Product::find($newProduct->id));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $allGenericSensors = App\GenericSensor::all("id");
     factory(App\Product::class, 5)->create()->each(function (App\Product $newProduct) use($allGenericSensors) {
         $newSensorsForEachGeneric = array();
         foreach ($allGenericSensors as $genericSensor) {
             $newSensorsForEachGeneric[] = new App\Sensor(['generic_sensor_id' => $genericSensor->getKey()]);
         }
         $newProduct->sensors()->saveMany($newSensorsForEachGeneric);
     });
 }