# vi src/Hoge/UserBundle/DataFixtures/ORM/LoadUser2Data.php<?php
namespace Hoge\UserBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Hoge\UserBundle\Entity\User;
class LoadUser2Data extends AbstractFixture implements OrderedFixtureInterface
{
public function load($manager){$user= new User();$user->setEmail('user1');$user->setPassword('test1');$user->setSalt('hoge1');$manager->persist($user);$manager->flush();$this->addReference('user1', $user);}
public function getOrder(){return1; // the order in which fixtures will be loaded
}}

ApiTokenテーブルではUserテーブルのプライマリーキーをuser_idカラムに保持する構造になってます。

# vi src/Hoge/UserBundle/DataFixtures/ORM/LoadApiTokenData.php<?php
namespace Hoge\UserBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Hoge\UserBundle\Entity\ApiToken;
class LoadApiTokenData extends AbstractFixture implements OrderedFixtureInterface
{
public function load($manager){$apiToken= new ApiToken();$apiToken->setUserId($manager->merge($this->getReference('user1'))->getId());$apiToken->setToken('hoge');$apiToken->setExpired(new \DateTime());$manager->persist($apiToken);$manager->flush();}
public function getOrder(){return2; // the order in which fixtures will be loaded
}}

use Symfony\Bundle\DoctrineFixturesBundle\Common\DataFixtures\Loader;
use Hoge\UserBundle\DataFixtures\ORM\LoadUser2Data;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
public function setUp() {$kernel= static::createKernel();$kernel->boot();$loader= new Loader($kernel->getContainer());$loader->addFixture(new LoadUser2Data);$fixtures=$loader->getFixtures();$em=$kernel->getContainer()->get('doctrine.orm.entity_manager');$purger= new ORMPurger($em);$purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);$executor= new ORMExecutor($em, $purger);$executor->execute($fixtures);