功能測試類依賴于夾具中創建的對象引用。但是,引用的 id 與實體管理器返回的對象的 id 屬性不同。下面的測試演示了這個問題。筆記:$this->setReference(...)使用 時的錯誤與使用public const ...和 時的錯誤相同$this->addReference(...)。測試中使用的對象引用似乎是非營利實體的下一個可用 ID。在更一般的測試類中觀察到錯誤后創建測試類。無論在運行測試類之前是否加載了裝置,錯誤都是相同的。該應用程序使用 Symfony 5.1.2,并更新了所有依賴項。測試類: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'); } }測試結果:Reference incorrectFailed asserting that 4 matches expected 1.
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消