now a days I am playing with PHPUnit. I have gone through its documentation but I am unable to understand it well. Let me explain my case.
I have a function in a class which takes three parameters 1 array, 2 some string, 3 a class object.
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
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 => $analysisResult);
}
return $testArray;
}
If I call this function like
$constructObj = new Application_Model_ConstructTree();
$test=$this->getMockForAbstractClass('Abstract_Result');
$test->level = "Error";
$test->infoText = "Not Immplemented";
$testArray = Array('databaseschema' => Array('Database' => $test));
$result = $constructObj->construct($testArray,"Database",$test);
The function returns the array like
Array
(
[databaseschema] => Array
(
[Database] => AnalysisResult Object
(
[isRepairable] => 1
[level] => Error
[infoText] => Not Implemented
)
)
)
Now I want to write a PHPUnit Test to check that the attributes of object like isRepairable, level and infoText exists and not empty. I have gone an idea that assertNotEmpty and assertAttributeEmpty can do some thing But I am unable to understand how to do it.
My test looks like
public function testcontruct() {
$constructObj = new Application_Model_ConstructTree();
$test=$this->getMockForAbstractClass('Abstract_Result');
$test->level = "Error";
$test->infoText = "Not Immplemented";
$testArray = Array('databaseschema' => Array('Database' => $test));
$result = $constructObj->construct($testArray,"Database",$test);
$this->assertNotCount(0, $result);
$this->assertNotContains('databaseschema', $result);
}
Can anyone please guide :-)