1

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
}

}

1 Answer 1

1

Most problems on database assertions were solved by Codeception testing framework. It's a solid wrapper on top of PHPUnit. Checkout it's Db module .

Also it has integration with popular ORMs and different DBMS.

The only limitation is that using DB module requires writing tests in special format. It's briefly described here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.