Php Can';t在另一个文件中创建抽象类mock
我在我的项目中定义了一个抽象类,我想对它运行测试Php Can';t在另一个文件中创建抽象类mock,php,Php,我在我的项目中定义了一个抽象类,我想对它运行测试 <?php use PHPUnit\Framework\TestCase; use phpDM\Connections\Adapters\ConnectionAdapterInterface; include(__DIR__ . '/../../../src/Connections/Adapters/ConnectionAdapterInterface.php'); class TestConnection { } class Co
<?php
use PHPUnit\Framework\TestCase;
use phpDM\Connections\Adapters\ConnectionAdapterInterface;
include(__DIR__ . '/../../../src/Connections/Adapters/ConnectionAdapterInterface.php');
class TestConnection { }
class ConnectionAdapterInterfaceTest extends TestCase
{
function testCreateConnection() {
$interface = $this->getMockForAbstractClass('ConnectionAdapterInterface');
$interface->method('createConnection')
->willReturn(new TestConnection());
$connection = $interface::createConnection();
$this->assertInstanceOf(TestConnection, $connection);
}
}
然而,无论我做什么,我总是得到错误
类“ConnectionAdapterInterface”不存在。
。在上面的示例中,我有一个使用
和包含
,尽管我也一次测试了每一个。对不起,我会澄清。它的名称不好,但ConnectionAdapterInterface
是一个抽象类。它是行为中的接口,而不是函数中的接口。请在使用前包含。并尝试使用全名或ConnectionAdapterInterface::类
abstract class ConnectionAdapterInterface {
abstract public static function createConnection(array $config);
}