Magento API V2 Soap unit testing

In previous article, I wrote about setting up environment for Magento unit testing. Let’s expand our tests to test some Magento’s API calls with soap.

Let’s add first tests in our Tests/customerCustomerTest.php


require_once 'PHPUnit/Autoload.php';
require_once '../app/Mage.php';

class customerCustomerTest extends PHPUnit_Framework_TestCase {

private $local_url_v1 = "";
private $local_url_v2 = "";
private $api_url_v1;
private $api_url_v2;

public function setUp() {

public function getApiUrlV2() {
    return $this->api_url_v2;

public function setApiUrlV2($api_url_v2) {
    $this->api_url_v2 = $api_url_v2;

public function testLogin() {

   $cli = new SoapClient($this->api_url_v2);

   $username = 'mobile';
   $password = 'mobile123';

   $result = $cli->login($username, $password);
   $session_id = isset($result) ? $result : null;

   return $session_id;

public function testCoreCustomerList_V2() {

   $session_id = $this->testLogin();
   $cli = new SoapClient($this->api_url_v2);
   $result = $cli->customerCustomerList($session_id);

   foreach ($result as $res) {
      $this->assertObjectHasAttribute('customer_id', $res);


Here we added two test methods: first one id login and it’s neccesary to return session Id for using in other API calls. Also it is neccesary to add mobile user with appropiate roles in administration of your Magento installation.

Hope that this article was useful to you.


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>