GetNextCustomerId(); $this->assertEquals(3, $id, 'next customer id'); } public function testGetNextOrderId() { $p = new Persister(); $id = $p->GetNextOrderId(); $this->assertEquals(4, $id, 'next order id'); } public function testGetNextOrderLineId() { $p = new Persister(); $id = $p->GetNextOrderLineId(); $this->assertEquals(5, $id, 'next orderline id'); } public function testGetCustomers() { $p = new Persister(); $lst = $p->getCustomers(); $this->assertEquals(2, count($lst), "number customers"); } public function testGetProducts() { $p = new Persister(); $lst = $p->getProducts(); $this->assertEquals(4, count($lst), "number products"); } public function testSaveCustomer() { $p = new Persister(); $c = new Customer(999, 'XXX', 'X X X', '123456789', 'boss@xxx.com'); $p->SaveCustomer($c); $temp = $p->GetCustomers(); $c2 = $temp[count($temp) - 1]; $this->assertEquals(999, $c2->id, "customer id"); // cleanup: $con = new PDO('mysql:host=localhost;dbname=devproc', 'root', ''); $con->query('DELETE FROM customers WHERE id = 999'); } public function testSaveOrder() { $p = new Persister(); $o = new Order(999, new Customer(1, 'ABC', '123 Somewhere Rd', '123456789', 'boss@abc.com'), date('Y-m-d'), 'Open'); $o->lines[] = new OrderLine(999, new Product(1, 'Something', 'Just something', 10.00), 1); $p->SaveOrder($o); $o2 = $p->LookupOrder(999); $this->assertEquals(999, $o2->id, "order id"); $this->assertEquals(1, count($o2->lines), "number order lines"); $this->assertEquals(999, $o2->lines[0]->id, "order line id"); // cleanup: $con = new PDO('mysql:host=localhost;dbname=devproc', 'root', ''); $con->query('DELETE FROM orderlines WHERE id = 999'); $con->query('DELETE FROM orders WHERE id = 999'); } public function testLookupOrder() { $p = new Persister(); $o = $p->lookupOrder(3); $this->assertEquals(3, $o->id, "order id"); $this->assertEquals(2, count($o->lines), "number order lines"); } public function testGetSalesStats() { $p = new Persister(); $stats = $p->getSalesStats(); $this->assertEquals(2, count($stats), "number stats"); $this->assertGreaterThan(0, $stats[0]->norders, "customer 1 number orders"); $this->assertGreaterThan(0, $stats[1]->norders, "customer 2 number orders"); } } ?>