功能測(cè)試類依賴于夾具中創(chuàng)建的對(duì)象引用。但是,引用的 id 與實(shí)體管理器返回的對(duì)象的 id 屬性不同。下面的測(cè)試演示了這個(gè)問題。筆記:$this->setReference(...)使用 時(shí)的錯(cuò)誤與使用public const ...和 時(shí)的錯(cuò)誤相同$this->addReference(...)。測(cè)試中使用的對(duì)象引用似乎是非營(yíng)利實(shí)體的下一個(gè)可用 ID。在更一般的測(cè)試類中觀察到錯(cuò)誤后創(chuàng)建測(cè)試類。無(wú)論在運(yùn)行測(cè)試類之前是否加載了裝置,錯(cuò)誤都是相同的。該應(yīng)用程序使用 Symfony 5.1.2,并更新了所有依賴項(xiàng)。測(cè)試類:namespace App\Tests\Controller;use Liip\TestFixturesBundle\Test\FixturesTrait;use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;class ReferenceTest extends WebTestCase{ use FixturesTrait; public function setup(): void { $this->client = $this->createClient(); $this->fixtures = $this->loadFixtures([ 'App\DataFixtures\Test\OptionsFixture', 'App\DataFixtures\Test\NonprofitFixture', 'App\DataFixtures\Test\OpportunityFixture', 'App\DataFixtures\Test\UserFixture', ]) ->getReferenceRepository(); $this->client->followRedirects(); $kernel = self::bootKernel(); $this->entityManager = $kernel->getContainer() ->get('doctrine') ->getManager('test'); } public function testNonprofitReference() { $npo = $this->entityManager->getRepository(\App\Entity\Nonprofit::class) ->findOneBy(['orgname' => 'Marmot Fund']); $nId = $npo->getId(); $id = $this->fixtures->getReference('npo')->getId(); $this->assertEquals($nId, $id, 'Reference incorrect'); } }測(cè)試結(jié)果:Reference incorrectFailed asserting that 4 matches expected 1.
1 回答
ABOUTYOU
TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
答案是,引用在功能測(cè)試中沒有地位。它們的使用實(shí)際上是單擊鏈接或執(zhí)行其他操作的快捷方式。更好的測(cè)試是使用爬蟲來(lái)模仿動(dòng)作。
- 1 回答
- 0 關(guān)注
- 168 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
