我正在尝试对带有一些遗留代码的应用程序进行一些集成测试。我要测试的是在应用程序中发生的某些事件链(由用户在前端触发,例如下订单、支付订单)之后,存在某些数据库条目。
目前,我建立了一个空数据库,然后为事件放入应用程序逻辑,然后查看 db.
有一个更好的方法吗?维护起来似乎很痛苦。
这是一些伪代码:
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
}
}