示例#1
0
            }
        }
        // post to a new Movement
    } else {
        if ($method === "POST") {
            // convert POSTed JSON to an object
            verifyXsrf();
            $requestContent = file_get_contents("php://input");
            $requestObject = json_decode($requestContent);
            $movementDate = new DateTime();
            if (empty($requestObject->movementDate) === false) {
                $movementDate->setTimestamp($requestObject->movementDate / 1000);
            }
            $movement = new Movement(null, $requestObject->fromLocationId, $requestObject->toLocationId, $requestObject->productId, $requestObject->unitId, $requestObject->userId, $requestObject->cost, $movementDate, $requestObject->movementType, $requestObject->price);
            $movement->insert($pdo);
            $reply->data = "Movement created OK";
            if ($requestObject->quantity !== null) {
                $productLocation = new ProductLocation($requestObject->toLocationId, $requestObject->productId, $requestObject->unitId, $requestObject->quantity);
                $productLocation->insert($pdo);
                $reply->data = "ProductLocation created OK";
            }
        }
    }
    // create an exception to pass back to the RESTful caller
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
    unset($reply->data);
}
header("Content-type: application/json");
echo json_encode($reply);
 /**
  * test grabbing a ProductLocation by productId
  **/
 public function testGetValidProductLocationByProductId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("productLocation");
     // create a new ProductLocation and insert to into mySQL
     $productLocation = new ProductLocation($this->location->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->VALID_quantity);
     $productLocation->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoProductLocation = ProductLocation::getProductLocationByProductId($this->getPDO(), $this->product->getProductId());
     foreach ($pdoProductLocation as $pdoPL) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("productLocation"));
         $this->assertSame($pdoPL->getLocationId(), $this->location->getLocationId());
         $this->assertSame($pdoPL->getUnitId(), $this->unitOfMeasure->getUnitId());
         $this->assertSame($pdoPL->getQuantity(), $this->VALID_quantity);
     }
 }
 /**
  * Test grabbing Valid UnitOfMeasure by productId
  **/
 public function testGetValidUnitOfMeasureByProductId()
 {
     // create a new Product
     $newProduct = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $newProduct->insert($this->getPDO());
     // create a new ProductLocation
     $quantity = 1.5;
     $newProductLocation = new ProductLocation($this->location->getLocationId(), $newProduct->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity);
     $newProductLocation->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?productId=' . $newProduct->getProductId() . "&getUnitOfMeasure=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->status);
 }
示例#4
0
 /**
  * test grabbing unit of measure by the product id
  **/
 public function testGetValidUnitOfMeasurementByProductId()
 {
     // create a new product and insert to into mySQL
     $product = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $product->insert($this->getPDO());
     $quantity = 5.9;
     // create a new product and insert to into mySQL
     $productLocation = new ProductLocation($this->location->getLocationId(), $product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity);
     $productLocation->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoUnitOfMeasureArray = Product::getUnitOfMeasureByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoUnitOfMeasureArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitId(), $this->unitOfMeasure->getUnitId());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitCode(), $this->unitOfMeasure->getUnitCode());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getQuantity(), $this->unitOfMeasure->getQuantity());
         }
     }
 }