I'm in the process of refactoring a project and have decided to use Symfony2 as my framework. I'm using the same database schema as I was previously but I'm having difficulty creating some test data using DataFixtures and Doctrine2.
The database field in question will hold an encrypted email field, which is being stored as VARBINARY and defined as:
/**
* @ORM\Column(type="string", columnDefinition="VARBINARY(254) NOT NULL")
*/
protected $email;
Note - I know this isn't portable but binary fields aren't yet available in a stable DBAL version.
In my data fixture I'm doing:
$user1 = new User();
$user1->setName('Joe Bloggs');
$user1->setEmail('test@test.com');
...
$manager->persist($user1);
...
$manager->flush();
Which understandably is generating the following error (I've substitued the class path etc for readability):
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to {MyClass}::setEmail() must be an instance of binary, string given
I've tried to encrypt the string (using the same process I did previously) but that's still just returning a string:
$encEmail=\mcrypt_encrypt(MCRYPT_RIJNDAEL_128, ENCKEY, 'test@test.com', MCRYPT_MODE_ECB);
$user1->setEmail($encEmail);
I've tried to pack the output into a binary string and I've tried casting it to a binary string but neither have worked.
I know I can manually create the test data directly into the database but in the interests of learning, I would like to get the data fixtures wokring.
Thanks.