Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

doctrine - How can I load fixtures from functional test in Symfony 2

My DoctrineFixturesBundle is installed and I can load fixture trough the command-line but , how can I load fixtures from my functional test ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you use symfony's WebTestCase, there's actually a very easy way to load your fixtures. Your fixture has to implement the FixtureInterface; thus, you can call it's load() method directly in your test's setUp() method. You just have to pass an EntityManager to the load() method, which can be aquired from the symfony container:

public function setUp() {
    $client = static::createClient();
    $container = $client->getContainer();
    $doctrine = $container->get('doctrine');
    $entityManager = $doctrine->getManager();

    $fixture = new YourFixture();
    $fixture->load($entityManager);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...