【发布时间】:2020-04-12 06:39:54
【问题描述】:
我尝试使用两种方法对特征进行单元测试。我想断言 foo 的结果,它在 trait 中调用另一个方法:
<?php
trait Foo {
public function foo() {
return $this->anotherFoo();
}
public function anotherFoo() {
return 'my value';
}
}
/** @var MockInterface|Foo */
$mock = Mockery::mock(Foo::class);
$mock
->makePartial()
->shouldReceive('anotherFoo')
->once()
->andReturns('another value');
$this->assertEquals('another value', $mock->foo());
我在运行phpunit 时得到以下结果:
There was 1 failure:
1) XXX::testFoo
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'another value'
+'my value'
这样一般可以吗?
【问题讨论】:
标签: php unit-testing testing mockery