Commit aa2ef6f6 authored by Will's avatar Will

Updating to work with php7, laravel 5.2 and the new php mongodb driver.

parent 1b32d02d
......@@ -3,7 +3,7 @@ language: php
php:
- 5.5
- 5.6
- 7.0
- 7
- hhvm
matrix:
......@@ -13,7 +13,16 @@ matrix:
sudo: false
services: mongodb
services:
- mongodb
- mysql
addons:
apt:
sources:
- mongodb-3.0-precise
packages:
- mongodb-org-server
before_script:
- pecl install mongodb
......@@ -23,7 +32,7 @@ before_script:
script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_success:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;'
......@@ -15,12 +15,12 @@
"illuminate/container": "^5.1",
"illuminate/database": "^5.1",
"illuminate/events": "^5.1",
"mongodb/mongodb": "^1.0.0@beta"
"mongodb/mongodb": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"orchestra/testbench": "^3.2",
"orchestra/testbench": "^3.1",
"mockery/mockery": "^0.9",
"satooshi/php-coveralls": "^0.6"
},
......
......@@ -9,6 +9,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<testsuites>
<testsuite name="all">
......
......@@ -39,7 +39,7 @@ class Collection {
{
$start = microtime(true);
$result = call_user_func_array([$this->collection, $method], $parameters);
if ($this->connection->logging())
{
// Once we have run the query we will calculate the time that it took to run and
......
......@@ -3,6 +3,7 @@
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use MongoDB\Driver\Cursor;
use MongoDB\Model\BSONDocument;
class Builder extends EloquentBuilder {
......@@ -221,18 +222,20 @@ class Builder extends EloquentBuilder {
if ($results instanceof Cursor)
{
$results = iterator_to_array($results, false);
return $this->model->hydrate($results);
}
// Convert Mongo BSONDocument to a single object.
elseif ($results instanceof BSONDocument)
{
$results = $results->getArrayCopy();
return $this->model->newFromBuilder((array) $results);
}
// The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results))
{
$model = $this->model->newFromBuilder((array) $results);
$model->setConnection($this->model->getConnection());
return $model;
return $this->model->newFromBuilder((array) $results);
}
return $results;
......
......@@ -360,7 +360,7 @@ abstract class Model extends BaseModel {
*
* @return array
*/
protected function getCasts()
public function getCasts()
{
return $this->casts;
}
......
......@@ -85,6 +85,7 @@ class Builder extends BaseBuilder {
*/
public function __construct(Connection $connection, Processor $processor)
{
$this->grammar = new Grammar;
$this->connection = $connection;
$this->processor = $processor;
}
......
<?php namespace Jenssegers\Mongodb\Query;
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
class Grammar extends BaseGrammar {
}
......@@ -19,6 +19,21 @@ class HasMany extends EloquentHasMany {
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
$query->select($columns);
$key = $this->wrap($this->getQualifiedParentKeyName());
return $query->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
......
......@@ -19,6 +19,21 @@ class HasOne extends EloquentHasOne {
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
$query->select($columns);
$key = $this->wrap($this->getQualifiedParentKeyName());
return $query->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
......
......@@ -99,13 +99,16 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
foreach ($columns as $column)
{
$transform[$column] = 1;
$transform[$column] = $column . '_1';
}
$columns = $transform;
}
$this->collection->deleteIndex($columns);
foreach ($columns as $column)
{
$this->collection->dropIndex($column);
}
return $this;
}
......
......@@ -38,6 +38,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
return true;
}
/**
* Determine if the given collection exists.
*
......@@ -48,9 +49,15 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
$db = $this->connection->getMongoDB();
return in_array($collection, $db->getCollectionNames());
}
foreach($db->listCollections() as $collectionFromMongo) {
if($collectionFromMongo->getName() == $collection) {
return true;
}
}
return false;
}
/**
* Determine if the given collection exists.
*
......
......@@ -460,6 +460,7 @@ class ModelTest extends TestCase {
{
return $collection->findOne(['age' => 35]);
});
$this->assertInstanceOf('Jenssegers\Mongodb\Model', $user);
$count = User::raw(function ($collection)
......
......@@ -187,8 +187,8 @@ class QueryBuilderTest extends TestCase {
return $collection->find(['age' => 20]);
});
$this->assertInstanceOf('MongoCursor', $cursor);
$this->assertEquals(1, $cursor->count());
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
$this->assertEquals(1, count($cursor->toArray()));
$collection = DB::collection('users')->raw();
$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
......@@ -540,11 +540,11 @@ class QueryBuilderTest extends TestCase {
$results = DB::collection('items')->where('tags', 'size', 4)->get();
$this->assertEquals(1, count($results));
$regex = new Regex("/.*doe/i");
$regex = new Regex(".*doe", "i");
$results = DB::collection('users')->where('name', 'regex', $regex)->get();
$this->assertEquals(2, count($results));
$regex = new Regex("/.*doe/i");
$regex = new Regex(".*doe", "i");
$results = DB::collection('users')->where('name', 'regexp', $regex)->get();
$this->assertEquals(2, count($results));
......
......@@ -196,7 +196,7 @@ class SchemaTest extends TestCase {
{
$collection = DB::getCollection($collection);
foreach ($collection->getIndexInfo() as $index)
foreach ($collection->listIndexes() as $index)
{
if (isset($index['key'][$name])) return $index;
}
......
......@@ -12,7 +12,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
{
return [
'Jenssegers\Mongodb\MongodbServiceProvider',
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider',
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider'
];
}
......
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