I have followed the instructions here on how to link Magento up to PHPUnit and THAT works.

I have created some custom shipping methods that, based on the order weight, order total, and a couple of custom attributes, will dictate which shipping method is available.

How do I add products to the cart and go through the checkout process using PHPUnit so that I can see which shipping method(s) is(are) available?

The idea being I would change the combination of products in the cart as needed without having to do it manually.

My function so far is:

public function testFirstMethod()
        $this->_model = new Company_CustomShippingMethod_Model_Carrier;
        $request = new Mage_Shipping_Model_Rate_Request();
        $response = $this->_model->collectRates($request);
        $this->assertEquals(FALSE, $response);

which passes as at this point there is no order and the model returns false.

So, how do I add products to the cart and go through the checkout process using PHPUnit?


Using the answer from programmatically adding product to cart returns empty price, I can add products using:

$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->addProduct($product, $qty);


How do I programmatically perform a checkout to get the shipping methods being returned by Magento?

2 Answers 2


You could use EcomDev Framework to simulate those situations. http://www.ecomdev.org/ .

Just extend from a Ecomdev Test Case instead of PHPUnit and you are able to create Fixtures to fill your Database with your needs like getting a quote.


This is a very late response. The article you were following is wrong and taking you to the wrong path. The test the article is showing is actually an integration test and not unit test.

Unit testing do and donts are well explained on this article http://www.rosenborgsolutions.com/phpunit-best-practice.php

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.