【发布时间】:2015-11-22 20:53:03
【问题描述】:
我对嘲弄和 phpunit 测试很陌生。
我创建了一个测试来检查是否将某些内容写入数据库。我使用了学说,并创建了我的学说连接和学说管理器的模拟对象。
一切正常,但我想获取给定的参数以使用 assertEqual 进行检查。
现在我正在做以下事情:
require_once "AbstractEFlyerPhpUnitTestCase.php";
class test2 extends AbstractEFlyerPhpUnitTestCase {
public function getCodeUnderTest() {
return "../php/ajax/presentations/add_presentation.php";
}
public function testingPresentationObject()
{
// prepare
$_REQUEST["caption"] = "Testpräsentation";
$_SESSION["currentUserId"] = 1337;
$this->mockedUnitOfWork->shouldReceive('saveGraph')->with(\Mockery::type('EFPresentation'));
$this->mockedUnitOfWork->shouldReceive('saveGraph')->with(\Mockery::type('EFSharedPresentation'));
$this->mockedDoctrineConnection->shouldReceive('commit');
//run
$this->runCodeUnderTest();
global $newPresentation;
global $newSharedPresentation;
// verify
$this -> assertEquals($newPresentation->caption,$_REQUEST["caption"]);
$this -> assertEquals($newSharedPresentation->userId,$_SESSION["currentUserId"]);
}
}
saveGraph 正在获取一个 EFPresentation 对象。我想要的是对象。
我想 assertEqual EFPresentation->caption 但来自给定对象的参数。现在我正在使用在 add_presentation 中创建的 EFPresentation->caption。
【问题讨论】: