I am trying to do some integration testing for an application with some legacy code. What I am looking to test is after certain chains of events that happen in the application (triggered on the front end by the user, such as put in an order, pay for the order), certain database entries exist.
Currently, I set up an empty database, then put in application logic for the event, then look at the db.
Is there a better way to do this? It seems like it could be a pain to maintain.
Here's some pseudo code:
class someTests extends PHPUnit_Framework_TestCase {
function setupScenario1(){
//create a new database, put in initial values
}
//test that an order is created properly
function testScenario1(){
$this->setupScenario1();
$this->loadOtherConfigs();
//now do some application logic
//setup an object to pass into a factory
$OrderInfo->ID = 5;
$OrderInfo->ProductID = 1;
$Order = new OrderFactory->Create($OrderInfo);
$PostOrderProcessor = new $PostOrderProcessor();
$PostOrderProcessor->Process($Order);
//assert that certain database entries were made
}
//test that an order is created properly, and then the payment is processed properly
function testScenario12(){
$this->testScenario1();
//hard coded from testScenario1
$OrderID = 5;
//setup payment stuff
$PaymentInfoObj->Amount = 500;
$PaymentInfoObj->Type = PaymentType::CREDIT_CARD;
//now do some application logic
$MockPaymentResult->Status = PaymentResult::APPROVED;
$MockPaymentProcessor = $this->getMockBuilder('PaymentProcessor')->disableOriginalConstructor()->getMock();
$MockPaymentProcessor->expects($this->once())
->method('process')
->will($this->returnValue($MockPaymentResult));
$PaymentProcessingWrapper = new PaymentProcessingWrapper($AppraisalsDAO,$MockPaymentProcessor);
$Result = $PaymentProcessingWrapper->TryToProcessPayment($OrderID,$PaymentInfoObj);
//assert that certain database entries were made
}
}