我有一个包含四个单元测试的课程。这门课看起来如下:
class TestWorkflowService extends TestCase
{
private $containerMock;
private $workflowEntityMock;
private $workflowService;
public function setup()
{
$this->containerMock = $this->createMock(ContainerInterface::class);
$this->workflowService = new WorkflowService($this->containerMock);
$this->workflowEntityMock = $this->createMock(WorkflowInterface::class);
}
public function testGetWorkflowProcessByEntityNullResult()
{
self::assertNull($this->workflowService->getWorkflowProcessByEntity($this->workflowEntityMock));
}
public function testGetProcessHandlerByEntityNullResult()
{
self::assertNull($this->workflowService->getProcessHandlerByEntity($this->workflowEntityMock));
}
public function testRestartWorkflow()
{
$modelStateMock = $this->createMock(ModelState::class);
$processHandlerMock = $this->createMock(ProcessHandler::class);
$processHandlerMock->method('start')->willReturn($modelStateMock);
$this->containerMock->method('get')->willReturn($processHandlerMock);
self::assertNull($this->workflowService->restartWorkflow($this->workflowEntityMock));
}
public function setEntityToNextWorkflowState()
{
$modelStateMock = $this->createMock(ModelState::class);
$processHandlerMock = $this->createMock(ProcessHandler::class);
$processHandlerMock->method('start')->willReturn($modelStateMock);
$this->containerMock->method('get')->willReturn($processHandlerMock);
self::assertNull($this->workflowService->setEntityToNextWorkflowState($this->workflowEntityMock));
}
}..。但是当我运行PHPUnit时,我得到了这样的结果:
3/3 (100%) 时间: 2.17秒,内存: 5.75MB 确定(3次测试,3次断言)
为什么我的第四次考试不被认可?
发布于 2018-09-26 14:52:35
PHPUnit使用下列规则标识测试方法。
这些测试是名为test*的公共方法。 或者,您可以使用方法文档块中的@test注释将其标记为测试方法。
这样您就可以在测试类中使用其他公共方法,而不必将它们解释为测试(虽然我不知道为什么要这样做)。
将您的方法名更改为testSetEntityToNextWorkflowState,或者用@test注释标记它。
https://stackoverflow.com/questions/52520572
复制相似问题