Jason Swett
Jason Swett

Reputation: 45134

Can't include Phactory in Symfony2/PHPUnit test

I'm trying to get Phactory working with a Symfony2 project. Here's what I have in one of my unit tests:

<?php
namespace VNN\PressboxBundle\Tests\Entity;
namespace VNN\PressboxBundle\Entity;
use VNN\PressboxBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Phactory\Sql\Phactory;

class UserTest extends EntityTest
{
    public function testCreate()
    {   
        Phactory::define('user', array(
            'username' => 'jasonswett',
        )); 
    }   
}

The error I'm getting when I try to run that test is this:

PHP Fatal error:  Class 'Phactory\Sql\Phactory' not found in /Users/jason/Web/pressbox/src/VNN/PressboxBundle/Tests/Entity/UserTest.php on line 12

Fair enough. How do I get this file to talk to Phactory? If it helps, I know that the Phactory class is defined in vendor/chriskite/phactory/lib/Phactory/Sql/Phactory.php and the first few lines of it look like this:

<?php

namespace Phactory\Sql;

class Phactory {

Upvotes: 0

Views: 171

Answers (1)

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44841

Just add the Phactory namespace to autoload.php.

Also, I prefer to set PHPUnit's bootstrap argument to autoload.php in phpunit.xml.dist:

<phpunit
    ...
    bootstrap = "autoload.php"
>

This works great for Symfony 2.1 projects based on Composer, but I'm not sure about the 2.0 ones.

Upvotes: 0

Related Questions