Skip to content

Commit 1278ebf

Browse files
committed
Adding seeder tests for #52
1 parent 55c57e7 commit 1278ebf

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Supported operations are:
102102
- create and drop
103103
- collection
104104
- hasCollection
105-
- index and dropIndex
105+
- index and dropIndex (compound indexes supported as well)
106106
- unique
107107
- background, sparse, expire (MongoDB specific)
108108

src/Jenssegers/Mongodb/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getFresh($columns = array('*'))
129129

130130
// Build pipeline
131131
$pipeline = array();
132-
if ($wheres) $pipeline[] = array('$match' => $wheres);
132+
if ($wheres) $pipeline[] = array('$match' => $wheres);
133133
$pipeline[] = array('$group' => $group);
134134

135135
// Apply order and limit

src/Jenssegers/Mongodb/Model.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function dropColumn($columns)
228228
{
229229
$this->__unset($column);
230230
}
231-
231+
232232
// Perform unset only on current document
233233
return $query = $this->newQuery()->where($this->getKeyName(), $this->getKey())->unset($columns);
234234
}
@@ -242,6 +242,7 @@ public function dropColumn($columns)
242242
*/
243243
public function __call($method, $parameters)
244244
{
245+
// Unset method
245246
if ($method == 'unset')
246247
{
247248
return call_user_func_array(array($this, 'dropColumn'), $parameters);
@@ -250,4 +251,4 @@ public function __call($method, $parameters)
250251
return parent::__call($method, $parameters);
251252
}
252253

253-
}
254+
}

tests/SeederTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\DB;
4+
5+
class SeederTest extends PHPUnit_Framework_TestCase {
6+
7+
public function setUp() {}
8+
9+
public function tearDown()
10+
{
11+
User::truncate();
12+
}
13+
14+
public function testSeed()
15+
{
16+
$seeder = new UserTableSeeder;
17+
$seeder->run();
18+
19+
$user = User::where('name', 'John Doe')->first();
20+
$this->assertTrue($user->seed);
21+
}
22+
23+
}

tests/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
$loader = require 'vendor/autoload.php';
33
$loader->add('', 'tests/models');
4+
$loader->add('', 'tests/seeds');
45

56
use Jenssegers\Mongodb\Model;
67
use Illuminate\Support\Facades\DB;
@@ -42,4 +43,4 @@ function bound() {}
4243

4344
# Static setup
4445
Model::setConnectionResolver($app['db']);
45-
DB::setFacadeApplication($app);
46+
DB::setFacadeApplication($app);

tests/seeds/DatabaseSeeder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
5+
class DatabaseSeeder extends Seeder {
6+
7+
/**
8+
* Run the database seeds.
9+
*
10+
* @return void
11+
*/
12+
public function run()
13+
{
14+
$this->call('UserTableSeeder');
15+
}
16+
}

tests/seeds/UserTableSeeder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
use Illuminate\Support\Facades\DB;
5+
6+
class UserTableSeeder extends Seeder {
7+
8+
public function run()
9+
{
10+
DB::collection('users')->delete();
11+
12+
DB::collection('users')->insert(array('name' => 'John Doe', 'seed' => true));
13+
}
14+
}

0 commit comments

Comments
 (0)