1
我正在尝试使用一些旧代码对应用程序进行一些集成测试。我期望测试的是在应用程序中发生的某些事件链(在用户的前端触发,例如投入订单,支付订单)发生的某些事件链之后,存在某些数据库条目。使用PHPUnit进行集成测试(检查数据库值)
目前,我建立了一个空的数据库,然后放入事件的应用程序逻辑,然后看看数据库。
有没有更好的方法来做到这一点?看起来这可能是一个痛苦要维护。
下面是一些伪代码:
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
}
}