For some reason when I try to test abstract class I get PHPUnit_Framework_MockObject_RuntimeException: Class "AbstractClass" does not exist.
Here's the code
AbstractClass.php
<?php
namespace SD\Project;
abstract class AbstractClass
{
public function handle()
{
}
}
AbstractClassTest.php
<?php
require_once 'AbstractClass.php';
use SD\Project\AbstractClass;
class AbstractClassTest extends PHPUnit_Framework_TestCase
{
public function testHandle()
{
$stub = $this->getMockForAbstractClass('AbstractClass');
}
}
When I get rid off the namespace and use statements the code is executed successfully. What I'm doing wrong?
You are not using the fully qualified path of the class.
$stub = $this->getMockForAbstractClass('\SD\Project\AbstractClass');
Read Similar: PHPUnit, Interfaces and Namespaces (Symfony2)
Examples: http://theaveragedev.com/testing-abstract-classes-with-phpunit/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With