/** * Test Getting Valid Movement By UserId **/ public function testGetValidMovementByUserId() { // 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/?userId=' . $newMovement->getUserId()); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $movement = json_decode($body); $this->assertSame(200, $movement->status); }
/** * test grabbing a Movement by userId **/ public function testGetValidMovementByUserId() { // 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()); // grab the data from mySQL and enforce the fields match our expectations $pdoMovement = Movement::getMovementByUserId($this->getPDO(), $movement->getUserId()); 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); } }