Commit 1278ebf0 authored by Jens Segers's avatar Jens Segers

Adding seeder tests for #52

parent 55c57e77
...@@ -102,7 +102,7 @@ Supported operations are: ...@@ -102,7 +102,7 @@ Supported operations are:
- create and drop - create and drop
- collection - collection
- hasCollection - hasCollection
- index and dropIndex - index and dropIndex (compound indexes supported as well)
- unique - unique
- background, sparse, expire (MongoDB specific) - background, sparse, expire (MongoDB specific)
......
...@@ -129,7 +129,7 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -129,7 +129,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
// Build pipeline // Build pipeline
$pipeline = array(); $pipeline = array();
if ($wheres) $pipeline[] = array('$match' => $wheres); if ($wheres) $pipeline[] = array('$match' => $wheres);
$pipeline[] = array('$group' => $group); $pipeline[] = array('$group' => $group);
// Apply order and limit // Apply order and limit
......
...@@ -228,7 +228,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -228,7 +228,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
{ {
$this->__unset($column); $this->__unset($column);
} }
// Perform unset only on current document // Perform unset only on current document
return $query = $this->newQuery()->where($this->getKeyName(), $this->getKey())->unset($columns); return $query = $this->newQuery()->where($this->getKeyName(), $this->getKey())->unset($columns);
} }
...@@ -242,6 +242,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -242,6 +242,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
// Unset method
if ($method == 'unset') if ($method == 'unset')
{ {
return call_user_func_array(array($this, 'dropColumn'), $parameters); return call_user_func_array(array($this, 'dropColumn'), $parameters);
...@@ -250,4 +251,4 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -250,4 +251,4 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
return parent::__call($method, $parameters); return parent::__call($method, $parameters);
} }
} }
\ No newline at end of file
<?php
use Illuminate\Support\Facades\DB;
class SeederTest extends PHPUnit_Framework_TestCase {
public function setUp() {}
public function tearDown()
{
User::truncate();
}
public function testSeed()
{
$seeder = new UserTableSeeder;
$seeder->run();
$user = User::where('name', 'John Doe')->first();
$this->assertTrue($user->seed);
}
}
<?php <?php
$loader = require 'vendor/autoload.php'; $loader = require 'vendor/autoload.php';
$loader->add('', 'tests/models'); $loader->add('', 'tests/models');
$loader->add('', 'tests/seeds');
use Jenssegers\Mongodb\Model; use Jenssegers\Mongodb\Model;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -42,4 +43,4 @@ $app['db']->extend('mongodb', array($reflection, 'newInstance')); ...@@ -42,4 +43,4 @@ $app['db']->extend('mongodb', array($reflection, 'newInstance'));
# Static setup # Static setup
Model::setConnectionResolver($app['db']); Model::setConnectionResolver($app['db']);
DB::setFacadeApplication($app); DB::setFacadeApplication($app);
\ No newline at end of file
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call('UserTableSeeder');
}
}
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UserTableSeeder extends Seeder {
public function run()
{
DB::collection('users')->delete();
DB::collection('users')->insert(array('name' => 'John Doe', 'seed' => true));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment