/**
  * test grabbing a FinishedProduct by rawMaterialId
  **/
 public function testGetValidFinishedProductByRawMaterialId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("finishedProduct");
     // create a new FinishedProduct and insert to into mySQL
     $finishedProduct = new FinishedProduct($this->finishedProduct->getProductId(), $this->rawMaterial->getProductId(), $this->VALID_rawQuantity);
     $finishedProduct->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoFinishedProduct = FinishedProduct::getFinishedProductByRawMaterialId($this->getPDO(), $this->rawMaterial->getProductId());
     foreach ($pdoFinishedProduct as $pdoFP) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("finishedProduct"));
         $this->assertSame($pdoFP->getFinishedProductId(), $this->finishedProduct->getProductId());
         $this->assertSame($pdoFP->getRawQuantity(), $this->VALID_rawQuantity);
     }
 }
Ejemplo n.º 2
0
 /**
  * Test grabbing Valid FinishedProduct by productId
  **/
 public function testGetValidFinishedProductByProductId()
 {
     // create a new product and insert to into mySQL
     $finishedProduct1 = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $finishedProduct1->insert($this->getPDO());
     $description = "Today is Thursday";
     $leadTime = 38;
     $sku = "302840779045";
     $title = "This is a title.";
     $rawMaterial = new Product(null, $this->vendor->getVendorId(), $description, $leadTime, $sku, $title);
     $rawMaterial->insert($this->getPDO());
     $finishedProductId = $finishedProduct1->getProductId();
     $rawMaterialId = $rawMaterial->getProductId();
     $rawQuantity = 56;
     $finishedProduct = new FinishedProduct($finishedProductId, $rawMaterialId, $rawQuantity);
     $finishedProduct->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?productId=' . $finishedProduct1->getProductId() . "&getFinishedProducts=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->status);
 }
Ejemplo n.º 3
0
 /**
  * test grabbing finished product by product
  **/
 public function testGetValidFinishedProductByProductId()
 {
     // create a new product and insert to into mySQL
     $finishedProduct1 = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $finishedProduct1->insert($this->getPDO());
     $description = "Today is Thursday";
     $leadTime = 38;
     $sku = "302840779045";
     $title = "This is a title.";
     $rawMaterial = new Product(null, $this->vendor->getVendorId(), $description, $leadTime, $sku, $title);
     $rawMaterial->insert($this->getPDO());
     $finishedProductId = $finishedProduct1->getProductId();
     $rawMaterialId = $rawMaterial->getProductId();
     $rawQuantity = 56;
     $finishedProduct = new FinishedProduct($finishedProductId, $rawMaterialId, $rawQuantity);
     $finishedProduct->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoFinishedProductArray = Product::getFinishedProductByProductId($this->getPDO(), $finishedProduct1->getProductId());
     for ($i = 0; $i < count($pdoFinishedProductArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoFinishedProductArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoFinishedProductArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoFinishedProductArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoFinishedProductArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoFinishedProductArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoFinishedProductArray[$i]->getFinishedProductId(), $finishedProduct->getFinishedProductId());
             $this->assertSame($pdoFinishedProductArray[$i]->getRawMaterialId(), $finishedProduct->getRawMaterialId());
             $this->assertSame($pdoFinishedProductArray[$i]->getRawQuantity(), $finishedProduct->getRawQuantity());
         }
     }
 }