title: Writing PHPUnit Test for a function returning an array
body: <p>now a days I am playing with <a href="http://www.phpunit.de/manual/current/en/" rel="nofollow">PHPUnit</a>. I have gone through its documentation but I am unable to understand it well. Let me explain my case.</p>
  
  <p>I have a function in a class which takes three parameters <code>1 array, 2 some string, 3 a class object</code>.
  This function returns the array by putting second parameter as an index of the array and result as object of that index. My function is as below</p>
  
  <pre><code> public function construct($testArray, $test,$analysisResult) {
      $postedTest = explode('_', $test);
      $testName = end($postedTest);
      $postedTest = implode("_", array_slice($postedTest, 0, -1));
      if (in_array($postedTest, array_keys($testArray))) {
          $testArray[$postedTest][$testName] = $analysisResult;
      } else {
          $testArray[$postedTest] = array($testName =&gt; $analysisResult);
      }
      return $testArray;
  }
  </code></pre>
  
  <p>If I call this function like </p>
  
  <pre><code>    $constructObj = new Application_Model_ConstructTree();
      $test=$this-&gt;getMockForAbstractClass('Abstract_Result');
      $test-&gt;level = "Error";
      $test-&gt;infoText = "Not Immplemented";
      $testArray = Array('databaseschema' =&gt; Array('Database' =&gt; $test));
  
      $result = $constructObj-&gt;construct($testArray,"Database",$test);
  </code></pre>
  
  <p>The function returns the array like</p>
  
  <pre><code>Array
  (
   [databaseschema] =&gt; Array
      (
          [Database] =&gt; AnalysisResult Object
              (
                  [isRepairable] =&gt; 1
                  [level] =&gt; Error
                  [infoText] =&gt; Not Implemented
              )
  
      )
  )
  </code></pre>
  
  <p>Now I want to write a PHPUnit Test to check that the attributes of object like <code>isRepairable, level and infoText</code> exists and not empty. I have gone an idea that <code>assertNotEmpty</code> and <code>assertAttributeEmpty</code> can do some thing But I am unable to understand how to do it.</p>
  
  <p>My test looks like</p>
  
  <pre><code>public function testcontruct() {
      $constructObj = new Application_Model_ConstructTree();
      $test=$this-&gt;getMockForAbstractClass('Abstract_Result');
      $test-&gt;level = "Error";
      $test-&gt;infoText = "Not Immplemented";
      $testArray = Array('databaseschema' =&gt; Array('Database' =&gt; $test));
  
      $result = $constructObj-&gt;construct($testArray,"Database",$test);
  
      $this-&gt;assertNotCount(0, $result);
      $this-&gt;assertNotContains('databaseschema', $result);
  }
  </code></pre>
  
  <p>Can anyone please guide :-)</p>