我有一个用于向我的数据库添加语言的控制器。在控制器的测试类的早期,添加新语言的测试添加了一种称为“测试语言”的新语言。我还对编辑操作进行了测试,代码如下:
public function testCanEditLanguageAction()
{
$language = $this->em->getRepository('\Entities\Languages')
->findOneByEnglishName($this->testLanguage);
$languageId = $language->getId();
unset($language);
$replacementName = 'Esttay Anguagelay';
// get the form in order to get the hash
$form = new Application_Model_FormLanguage([
'action' => '/langauges/edit',
'id' => $languageId
]);
$this->dispatch("/languages/edit/$languageId");
$form->render();
$this->request
->setMethod('POST')
->setPost([
'id' => $languageId,
'englishName' => $replacementName,
'japaneseName' => '仮の言葉',
'kanaName' => 'カリノコトバ',
'languageHash' => $form->languageHash->getValue()
]);
$this->dispatch("/languages/edit");
$this->assertRedirectTo('/');
// make sure the data got edited properly
$editedLanguage = $this->em
->getRepository('\Entities\Languages')
->findOneById($languageId);
$this->assertEquals($replacementName, $editedLanguage->getEnglishName());
}
该测试在大多数情况下运行良好:它正确获取语言,对其进行编辑,并将值从“测试语言”更新为“Esttay Anguagelay”。如果我在测试完成后查看数据库,测试语言甚至具有该值。
问题是,根据 PHPUnit,测试失败。我得到以下输出:
There was 1 failure:
1) LanguagesControllerTest::testCanEditLanguageAction
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-Esttay Anguagelay
+Test Language
换句话说,它认为语言的价值没有改变,当它明显改变时。(就像我说的,检查数据库的值确认它实际上已经改变了)。我在这里错过了什么吗?我对 PHPUnit 很陌生,所以可能有些事情我忘了做或者我做错了。