通过扩展WebTestCase使Symfony2单元测试更多DRY

Jas*_*ett 5 unit-testing symfony

我的很多测试都有很多相同setUp()/ tearDown()正在进行的事情.将相同的代码复制并粘贴到我的每个单元测试中似乎都很愚蠢.我想我想创建一个新的测试类,扩展WebTestCase我的其他测试可以扩展.

我的问题是我真的不知道怎么做.首先,这个新课程最合适的地方在哪里?我尝试在我的Tests文件夹中制作一个,但是我的测试中没有一个能够真正找到该类.也许我只是不了解命名空间.

有没有人WebTestCase以我正在谈论的方式扩展?如果是这样,你是怎么做到的?

Pet*_*ley 4

我没有这样做过,但我可能会这样做

src/你的/Bundle/Test/WebTestCase.php

<?php

namespace Your\Bundle\Test

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as WTC;

class WebTestCase extends WTC
{
  // Your implementation of WebTestCase
}
Run Code Online (Sandbox Code Playgroud)