Hello I'm pretty new to PHPUnit and Laravel 4.
I've created an REST API and I'm trying to add a new User using laravel (PHPUnit) unit tests, to my test DB. The problem is, that it completely disregards the Object array that I'm trying to add with the user doc creation.
A typical User Doc would look as follows:
{
_id": ObjectId("53021089b4d15220118b4568"),
"oArr": {
"something": {
"somewhere": "5th Avenue",
"ip": "192.168.0.20"
},
"something2": {
"somewhere": "6th Avenue",
"ip": "192.168.0.21"
}
}
"email": "jessica@example.com",
"name": "Jessica Alba",
"password": "$2y$10$RAVzUGLAG.81IOOUum0k0u5vrcY98H.L42FeSJekEywUCV.ycttn6"
}
Now Laravel has it's own Testing class TestCase
which your Unit tests extend.
Typical example would be the following:
class AddUserTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testCreateUsers()
{
$post_data = array(
'email' => 'emma@example.com',
'name' => 'Emma Watson',
'password' => 'password',
'oArr' => array(
'something' => array(
'somewhere' => '7th Avenue',
'ip' : => '192.168.0.31'
),
),
);
}
}
Once the user test has run (successfully), the new Emma Watson user (Mongo Doc) look as follows:
{
_id": ObjectId("53021089b4d15220118b4568"),
"email": "emma@example.com",
"name": "Emma Watson",
"password": "$2y$10$asdAzUGLAG.8asvWQOUum0k0u5vrcY98H.LEDeSJekEywUCV.ycttn6"
}
I have no idea how, and couldn't find anyone else with the same problem.
My assumption: The ORM I'm using (https://github.com/jenssegers/Laravel-MongoDB), doesn't cater for Object arrays in Unit Tests.
I have yet to look into how the ORM is handling unit tests, I'm just hoping someone else has had the same problem, and has a more basic solution.