Commit 675bb863 authored by Jens Segers's avatar Jens Segers

Fixed issue #42 and tweaked tests

parent 1e533493
......@@ -4,7 +4,7 @@ branches:
only:
- master
php:
php:
- 5.3
- 5.4
- 5.5
......@@ -16,4 +16,4 @@ before_script:
- composer self-update
- composer install --dev --no-interaction
script: phpunit tests
\ No newline at end of file
script: phpunit
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Laravel MongoDB Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
......@@ -89,7 +89,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
}
else
{
// If we don't use grouping, set the _id to null to prepare the pipeline for
// If we don't use grouping, set the _id to null to prepare the pipeline for
// other aggregation functions
$group['_id'] = null;
}
......@@ -149,7 +149,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
$column = isset($this->columns[0]) ? $this->columns[0] : '_id';
return $this->collection->distinct($column, $wheres);
}
// Normal query
else
{
......@@ -282,7 +282,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
{
// As soon as we find a value that is not an array we assume the user is
// inserting a single document.
if (!is_array($value))
if (!is_array($value))
{
$batch = false; break;
}
......@@ -546,7 +546,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
/**
* Convert a key to MongoID if needed.
*
*
* @param mixed $id
* @return mixed
*/
......@@ -572,7 +572,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
// The new list of compiled wheres
$wheres = array();
foreach ($this->wheres as $i => &$where)
foreach ($this->wheres as $i => &$where)
{
// Convert id's
if (isset($where['column']) && $where['column'] == '_id')
......@@ -586,7 +586,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
}
}
// Single value
else
elseif (isset($where['value']))
{
$where['value'] = $this->convertKey($where['value']);
}
......@@ -715,4 +715,4 @@ class Builder extends \Illuminate\Database\Query\Builder {
return parent::__call($method, $parameters);
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
use Illuminate\Support\Facades\DB;
......@@ -38,4 +37,4 @@ class CacheTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(3, count($users));
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
use Illuminate\Support\Facades\DB;
use Jenssegers\Mongodb\Connection;
......@@ -63,4 +61,4 @@ class ConnectionTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($hosts));
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
class ModelTest extends PHPUnit_Framework_TestCase {
......@@ -305,4 +304,4 @@ class ModelTest extends PHPUnit_Framework_TestCase {
$this->assertFalse(isset($user2->note2));
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
use Illuminate\Support\Facades\DB;
......@@ -56,7 +55,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(is_array($user['tags']));
}
public function testInsertGetId()
public function testInsertGetId()
{
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));
......@@ -69,7 +68,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
DB::collection('users')->insert(array(
array(
'tags' => array('tag1', 'tag2'),
'name' => 'Jane Doe',
'name' => 'Jane Doe',
),
array(
'tags' => array('tag3'),
......@@ -93,6 +92,12 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('John Doe', $user['name']);
}
public function testFindNull()
{
$user = DB::collection('users')->find(null);
$this->assertEquals(null, $user);
}
public function testCount()
{
DB::collection('users')->insert(array(
......@@ -201,14 +206,14 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
));
DB::collection('users')->where('_id', $id)->push('tags', 'tag1');
$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['tags']));
$this->assertEquals(1, count($user['tags']));
$this->assertEquals('tag1', $user['tags'][0]);
DB::collection('users')->where('_id', $id)->push('tags', 'tag2');
$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['tags']));
$this->assertEquals(2, count($user['tags']));
......@@ -233,7 +238,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
));
DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['tags']));
$this->assertEquals(3, count($user['tags']));
......@@ -408,4 +413,4 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertFalse(isset($user2['note2']));
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
class QueryTest extends PHPUnit_Framework_TestCase {
......@@ -242,4 +241,4 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(6, count($users));
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
class RelationsTest extends PHPUnit_Framework_TestCase {
......@@ -103,4 +102,4 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('admin', $role->type);
}
}
\ No newline at end of file
}
<?php
require_once('tests/app.php');
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
......@@ -105,4 +104,4 @@ class SchemaTest extends PHPUnit_Framework_TestCase {
return false;
}
}
\ No newline at end of file
}
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