I'm learning phpunit tests implementation, my problem, is that I don't know how to test the case where the if condition is not true, so it doesn't define the $view->somethingSemantic array, then, how can I mock this PHPUNIT test to make it pass?
Should I test both scenarios in one test? or should I split in two... The documentation is so simple but can't find any reference to a case alike.
Now I get a error - Undefined property for #case 2 Test #2 fails, all the time, or it shows the Love semantics value compared vs the first array Love semantics as if they were supposed to match to pass the test?
// this is the function I'm creating the UT.
protected function _doSomeMagicPlease( $view ) {
if($this->config->DoSomeMagicPlease){
$view->somethingSemantic = array(
"Something else semantic" => $this->lsd(),
"Love semantics" => $this->magic()
);
}
}
// assertion - the view->somethingSemantic does not exist in case 2.
$this->assertEquals($expected , $view->somethingSemantic);
it seems it is comparing both arrays of the data provider:
// this is my data provider:
public function checkDoSomeMagicPleaseDataProvider()
{
return [
[
'message' => 'Case 1',
'configObject' => (object) array(
'values' => (object) array(
'DoSomeMagicPlease'=> 'true'
)
),
'expected' => array(
"Something else semantic" => "12345",
"Love semantics" => "https://www.someurl.com"
),
],
[
'message' => 'Case 2',
'configObject' => (object) array(
'values' => (object) array(
'DoSomeMagicPlease'=> "false"
)
),
'expected' => array(
"Something else semantic" => "12345",
"Love semantics" => "false"
)
]
];
}
Should I change my assertion? any hint is appreciated !!