我最近通过 Composer 在 PHPStorm 中设置了 PHPUnit。
我正在尝试测试一些需要我引导 Processwire(CMS)的功能。
尽管应用了我研究的以下条件是解决此问题的正确方法,但我不断收到消息“您无法序列化或反序列化 PDO 实例”。
* @backupGlobals disabled
* @backupStaticAttributes disabled
* @runTestsInSeparateProcesses
* @runInSeparateProcess
* @preserveGlobalState disabled
我还有什么遗漏或需要做的事情吗?
这些是我到目前为止参考的资源。
https://phpunit.de/manual/current/en/phpunit-book.html#appendixes.annotations.preserveGlobalState
http://edmondscommerce.github.io/php/phpunit-and-pdoexception-solution.html
我看到这篇文章将我的文章标记为重复,但我不相信它是相同的: PDOException: You cannot serialize or unserialize PDO instances
那篇文章中的测试直接引用了 PDO 对象,而我只是想让我的测试通过对 Processwire 的引导引用来运行。这是我正在尝试运行的测试:
namespace Test;
include_once(__DIR__."/../../../../index.php"); //Bootstrap to Processwire CMS
class ImageTest extends \PHPUnit_Framework_TestCase {
/**
* @backupGlobals disabled
* @backupStaticAttributes disabled
* @runTestsInSeparateProcesses
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
protected function setUp()
{
//$this->testpages = wire(pages)->find("template=fingergames|template=songs|template=poems");
}
public function testImageEmptyLinks()
{
//$testpages = wire(pages)->find("template=fingergames|template=songs|template=poems");
$blanks = wire(pages)->find("image=''");
$this->assertEquals($blanks->count(),0);
}
public function testImageMismatchedLinks()
{
//$this->assertTrue(true);
$this->assertEquals(0,0);
}
public function testImageMissingSiblings()
{
$this->assertEquals(0,0);
}
protected function tearDown()
{
}
}