/** * Test Getting Valid Movement By MovementType **/ public function testGetValidMovementByMovementType() { // create a new Movement $newMovement = new Movement(null, $this->fromLocation->getLocationId(), $this->toLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->user->getUserId(), $this->VALID_cost, $this->VALID_movementDate, $this->VALID_movementType, $this->VALID_price); $newMovement->insert($this->getPDO()); // grab the data from guzzle and enforce the status' match our expectations $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/movement/?movementType=' . $newMovement->getMovementType()); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $movement = json_decode($body); $this->assertSame(200, $movement->status); }
} } } // 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");
/** * test grabbing a Movement by movementType **/ public function testGetValidAllMovements() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("movement"); // create a new Movement and insert to into mySQL $movement = new Movement(null, $this->fromLocation->getLocationId(), $this->toLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->user->getUserId(), $this->VALID_cost, $this->VALID_movementDate, $this->VALID_movementType, $this->VALID_price); $movement->insert($this->getPDO()); $page = 1; // grab the data from mySQL and enforce the fields match our expectations $pdoMovement = Movement::getAllMovements($this->getPDO(), $page); foreach ($pdoMovement as $pdoM) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("movement")); $this->assertSame($pdoM->getFromLocationId(), $this->fromLocation->getLocationId()); $this->assertSame($pdoM->getToLocationId(), $this->toLocation->getLocationId()); $this->assertSame($pdoM->getProductId(), $this->product->getProductId()); $this->assertSame($pdoM->getUnitId(), $this->unitOfMeasure->getUnitId()); $this->assertSame($pdoM->getUserId(), $this->user->getUserId()); $this->assertSame($pdoM->getCost(), $this->VALID_cost); $this->assertEquals($pdoM->getMovementDate(), $this->VALID_movementDate); $this->assertSame($pdoM->getMovementType(), $this->VALID_movementType); $this->assertSame($pdoM->getPrice(), $this->VALID_price); } }