jeudi 22 janvier 2015

PHP Unit testing with mockery in symfony 1.4

I'm trying to do unit testing in symfony 1.4 (actually it's 1.5.3 (http://ift.tt/1CTDta7)) with phpunit and mockery. Is there a way to load all files of symfony and then, if needed, create mock object from a loaded class? The error message is: "Could not load mock {ClassName}, class already exists", which is pretty self explanatory, but I would like to use some of the original methods, not just the ones I've mocked. Is there a way to do that?


For example:



public funtion testTest() {
$mock = Mockery::mock("alias:Site")->shouldReceive('getCurrent')->shouldReturn(3);
$this->assertEquals(3, Project::test());
}

public static function test() {
return Site::getCurrent();
}


If I include only the Project class, it works, but if all project files are included I get the error message. But what if the test() function uses other methods of the Site object, which I don't want to mock?


Aucun commentaire:

Enregistrer un commentaire