I hope someone can help me with this. My problem is, that i'm trying to mock globals in phpunit or something like that. Just trying to get the d**m globals running.
This is my construct
$this->testclass = $this->getMockBuilder('myClass')
->disableOriginalConstructor()
->setMethods(array(
'test' //<==== just setting it here for fun
))
->getMock();
This is my unit test
public function testCheckuniqueName() {
$this->testclass->ixtools = new GlobalModx(); //<---- trying to get the global
$this->testclass->checkuniqueName('empty', ' Back_test', 'testitem', true);
}
new GlobalModx()
is a class i created to set globals and other functions i want to mock
class GlobalModx {
public $confDB;
public function __construct() {
$this->confDB = new \stdClass();
$this->confDB->attributes = array();
}
}
My php function i try to test
public function checkuniqueName(){
global $ixTools; //<--- this is the bastard
$dbAttributes = $ixTools->confDB->attributes['attributes'][$company];
//somecode i can't show
return true;
}
As you can see i try to reset the global and give it data. But all i get is
testCheckuniqueName() Trying to get property of non-object
I need to get data in the global. But phpunit won't let me
Aucun commentaire:
Enregistrer un commentaire