【发布时间】:2019-02-04 01:02:14
【问题描述】:
Silverstripe 4 单元测试出现“找不到对象”错误,如何解决?
使用 silverstripe 4 单元测试,我收到错误“找不到对象 'transaction1'”。 谁能建议这里发生了什么?谢谢。
class CustomerCreditTransactionTest extends SapphireTest
{
protected static $fixture_file = BASE_PATH.'/mysite/code/CustomerCreditTransactionTest.yml';
/**
* @var string
*/
protected $readingmode = null;
/**
* Default reading mode
*
* @var string
*/
protected $defaultMode = null;
public function setUp()
{
$this->readingmode = 'Original';
$this->defaultMode = 'Original';
}
public function tearDown()
{
MirroredData::SetCurrentReadingStage($this->readingmode);
MirroredData::SetDefaultWritingStage($this->defaultMode);
}
public function testCustomerName()
{
$obj = $this->objFromFixture(CustomerCreditTransaction::class, 'transaction1');
$this->assertEquals(
'John@gmail.com',
$obj->CustomerName(),
'customer name is : '.$obj->CustomerName()
);
}
}
【问题讨论】:
-
你有一个 transaction1 夹具吗?
-
是的,namespace\CustomerCreditTransaction: transaction1: Amount: 100 Comment: testing comment 1 Customer: => namespace\Customer.Jone
-
因为 silverstripe 4,我跟随这个指南,docs.silverstripe.org/en/4/developer_guides/testing/fixtures
标签: php silverstripe silverstripe-4 phpunit