Skip to content

Instantly share code, notes, and snippets.

@ctrlaltdylan
Created May 26, 2016 17:21
Show Gist options
  • Save ctrlaltdylan/046032d82b8c6b8c07f5c53ca0382042 to your computer and use it in GitHub Desktop.
Save ctrlaltdylan/046032d82b8c6b8c07f5c53ca0382042 to your computer and use it in GitHub Desktop.
This is an example of integrating MuffinFactory 3.0 into a Symfony 2 functional test
<?php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use League\FactoryMuffin\FactoryMuffin;
use League\FactoryMuffin\Stores\RepositoryStore;
class ExampleControllerTest extends WebTestCase
{
/**
* @var FactoryMuffin
*/
protected static $fm;
/**
* The static setup method before the tests are executed
* Great for setting up the model factories
*
*/
public static function setupBeforeClass()
{
$client = static::createClient();
$container = $client->getContainer();
$em = $container->get('doctrine.orm.entity_manager');
// overriding the default "store" which is an eloquent interpretation with a repository one
$store = new RepositoryStore($em);
// create a new factory muffin instance
static::$fm = new FactoryMuffin($store);
// load your model definitions
static::$fm->loadFactories(__DIR__.'/../factories');
}
/**
* The actual test
*/
public function testIndexAction()
{
$client = static::createClient();
$something = static::$fm->create('Acme\DemoBundle\Entity\Something');
$this->assertInstanceOf('Acme\DemoBundle\Entity\Something', $something);
}
/**
* Deleting the persisted models after the test is over
*/
public static function tearDownAfterClass()
{
static::$fm->deleteSaved();
}
}
@3amprogrammer
Copy link

Does your Acme\DemoBundle\Entity\Something have setters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment