Error: Argument 1 passed to screenFake::__construct() must be an instance of databaseInterfaseFake, instance of Mock_databaseInterfaceFake_b36397fd
| From: | Ramiro Barrantes | Date: | Sat, 22 Aug 2015 20:34:42 +0000 |
| Subject: | Error: Argument 1 passed to screenFake::__construct() must be an instance of databaseInterfaseFake, instance of Mock_databaseInterfaceFake_b36397fd | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325052@lists.php.net to get a copy of this message | ||
Hello,
I am trying to write a unit test for a dependency injection situation and I have a reproducible
example at the end. I am getting this error:
1) testFake::test_fake
Argument 1 passed to screenFake::__construct() must be an instance of databaseInterfaseFake,
instance of Mock_databaseInterfaceFake_b36397fd given, called in fakeTest.php on line 25 and de...
I have run across similar issues on the web, but they all point me to not mocking the correct
object, which I do not think is the case here. This is probably very obvious but I am brand new in
using mocks and stubs so any help appreciated.
Thanks in advance,
<?php
class databaseInterfaceFake
{
private $a;
function __construct()
{
$a="a";
}
}
class screenFake {
private $db;
function __construct(databaseInterfaseFake $dbFake) {
$db = $dbFake;
}
function m() {
return TRUE;
}
}
class testFake extends PHPUnit_Framework_TestCase {
public function test_fake() {
$db = $this->getMock('databaseInterfaceFake');
$screen = new screenFake($db);
$this->assertTrue($screen->m());
}
}
?>