/** * Test grabbing Valid Product by LocationId **/ public function testGetValidProductByLocationId() { // create a new location and insert to into mySQL $newLocation = new Location(null, $this->VALID_storageCode, $this->VALID_description); $newLocation->insert($this->getPDO()); $quantity = 5.9; // create a new location and insert to into mySQL $productLocation = new productLocation($newLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from guzzle $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/location/?locationId=' . $newLocation->getLocationId() . "&getProducts=true"); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $location = json_decode($body); echo $body . PHP_EOL; $this->assertSame(200, $location->status); }
/** * test grabbing location by productId **/ public function testGetValidProductByLocationId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("location"); // create a new location and insert to into mySQL $location = new Location(null, $this->VALID_storageCode, $this->VALID_description); $location->insert($this->getPDO()); $quantity = 5.9; // create a new location and insert to into mySQL $productLocation = new productLocation($location->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductArray = Location::getProductByLocationId($this->getPDO(), $location->getLocationId()); for ($i = 0; $i < count($pdoProductArray); $i++) { if ($i === 0) { $this->assertSame($pdoProductArray[$i]->getStorageCode(), $this->VALID_storageCode); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->VALID_description); } else { $this->assertSame($pdoProductArray[$i]->getProductId(), $this->product->getProductId()); $this->assertSame($pdoProductArray[$i]->getVendorId(), $this->product->getVendorId()); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->product->getDescription()); $this->assertSame($pdoProductArray[$i]->getSku(), $this->product->getSku()); $this->assertSame($pdoProductArray[$i]->getTitle(), $this->product->getTitle()); } } }