tl;dr: Will this potentially keep my tests from working properly?
I'm trying to write functional tests for my Symfony project, and working from examples in The Symfony Book. So far, each method of the test class starts out with the same line of code:
namespace Tests\AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SomeControllerTest extends WebTestCase
{
public function testSomethingOnRouteX()
{
$client = static::createClient();
// set up and assert
}
public function testSomethingElseOnRouteX()
{
$client = static::createClient();
// different set up and assert
}
}
I would like to remove this redundant code, but I am not sure if I should do this.
I added a constructor where I created the client.
public function __construct()
{
parent::__construct();
$this->client = static::createClient();
}
then in the various test methods I can just use $this->client
without needing to create it repeatedly. This seems to work so far (I don't have many tests yet.) But I'm new enough to this framework, and to this type of testing in general that I'm not sure if it will cause problems down the road.
Aucun commentaire:
Enregistrer un commentaire