phpunit 功能测试错误调用未定义的方法



我有一个问题,

我在symfony 3.4中使用phpunit WebTestCase

但我无法选择任何数据

我得到

1( 测试\银行捆绑\控制器

\银行控制器测试::测试货币在 断言空匹配项预期为 1 失败。

我遵循本教程

这是我的控制器测试

<?php
namespace TestsBankBundleController;
use BankBundleEntityentry;
use SymfonyBundleFrameworkBundleTestWebTestCase;
class BankControllerTest extends WebTestCase
{
/**
* @var DoctrineORMEntityManager
*/
private $em;
/**
* {@inheritDoc}
*/
public function setUp(): void
{
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager();
}
public function testmoneyIn()
{
$client = static::createClient();
$client->request('POST', '/bank/moneyin', array('amount' => 50));
$bank = $this->em
->getRepository('BankBundle:entry')
->getId(1);
$this->assertEquals(1, $bank);
} 
/**
* {@inheritDoc}
*/
protected function tearDown(): void
{
parent::tearDown();
$this->em->close();
} 
}

您正在尝试断言该$bank = 1.但$bank是空的。您的测试失败。 对于测试用途,应始终使用可预测的数据。这意味着,无论何时运行测试,您都知道预期的结果。因此,您确信,如果您的断言失败,这意味着您的代码是错误的。

最新更新