Commit 13859bb5 authored by Jens Segers's avatar Jens Segers

Add styleci

parent 52145b0c
preset: psr2
enabled:
- duplicate_semicolon
- empty_return
- extra_empty_lines
- operators_spaces
- phpdoc_indent
- remove_leading_slash_use
- spaces_cast
- ternary_spaces
- unused_use
disabled:
- braces
- parenthesis
...@@ -13,13 +13,13 @@ use Jenssegers\Mongodb\Query\Builder as QueryBuilder; ...@@ -13,13 +13,13 @@ use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
abstract class Model extends \Illuminate\Database\Eloquent\Model { abstract class Model extends \Illuminate\Database\Eloquent\Model {
/** /**
* Define a one-to-one relationship. * Define a one-to-one relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne * @return \Illuminate\Database\Eloquent\Relations\HasOne
*/ */
public function hasOne($related, $foreignKey = null, $localKey = null) public function hasOne($related, $foreignKey = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
...@@ -67,13 +67,13 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -67,13 +67,13 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
} }
/** /**
* Define a one-to-many relationship. * Define a one-to-many relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany * @return \Illuminate\Database\Eloquent\Relations\HasMany
*/ */
public function hasMany($related, $foreignKey = null, $localKey = null) public function hasMany($related, $foreignKey = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
...@@ -124,14 +124,14 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -124,14 +124,14 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
} }
/** /**
* Define an inverse one-to-one or many relationship. * Define an inverse one-to-one or many relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $otherKey * @param string $otherKey
* @param string $relation * @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/ */
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{ {
// If no relation name was given, we will use this debug backtrace to extract // If no relation name was given, we will use this debug backtrace to extract
......
...@@ -5,37 +5,37 @@ use MongoDate; ...@@ -5,37 +5,37 @@ use MongoDate;
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository { class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository {
/** /**
* Build the record payload for the table. * Build the record payload for the table.
* *
* @param string $email * @param string $email
* @param string $token * @param string $token
* @return array * @return array
*/ */
protected function getPayload($email, $token) protected function getPayload($email, $token)
{ {
return ['email' => $email, 'token' => $token, 'created_at' => new MongoDate]; return ['email' => $email, 'token' => $token, 'created_at' => new MongoDate];
} }
/** /**
* Determine if the token has expired. * Determine if the token has expired.
* *
* @param array $token * @param array $token
* @return bool * @return bool
*/ */
protected function tokenExpired($token) protected function tokenExpired($token)
{ {
// Convert MongoDate to a date string. // Convert MongoDate to a date string.
if ($token['created_at'] instanceof MongoDate) if ($token['created_at'] instanceof MongoDate)
{ {
$date = new DateTime; $date = new DateTime;
$date->setTimestamp($token['created_at']->sec); $date->setTimestamp($token['created_at']->sec);
$token['created_at'] = $date->format('Y-m-d H:i:s'); $token['created_at'] = $date->format('Y-m-d H:i:s');
} }
return parent::tokenExpired($token); return parent::tokenExpired($token);
} }
} }
...@@ -4,26 +4,26 @@ use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository; ...@@ -4,26 +4,26 @@ use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider { class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider {
/** /**
* Register the token repository implementation. * Register the token repository implementation.
* *
* @return void * @return void
*/ */
protected function registerTokenRepository() protected function registerTokenRepository()
{ {
$this->app->singleton('auth.password.tokens', function($app) $this->app->singleton('auth.password.tokens', function ($app)
{ {
$connection = $app['db']->connection(); $connection = $app['db']->connection();
// The database token repository is an implementation of the token repository // The database token repository is an implementation of the token repository
// interface, and is responsible for the actual storing of auth tokens and // interface, and is responsible for the actual storing of auth tokens and
// their e-mail addresses. We will inject this table and hash key to it. // their e-mail addresses. We will inject this table and hash key to it.
$table = $app['config']['auth.password.table']; $table = $app['config']['auth.password.table'];
$key = $app['config']['app.key']; $key = $app['config']['app.key'];
$expire = $app['config']->get('auth.password.expire', 60); $expire = $app['config']->get('auth.password.expire', 60);
return new DbRepository($connection, $table, $key, $expire); return new DbRepository($connection, $table, $key, $expire);
}); });
} }
} }
<?php namespace Jenssegers\Mongodb; <?php namespace Jenssegers\Mongodb;
use Exception, MongoCollection; use Exception;
use Jenssegers\Mongodb\Connection; use MongoCollection;
class Collection { class Collection {
...@@ -63,7 +63,7 @@ class Collection { ...@@ -63,7 +63,7 @@ class Collection {
} }
} }
$queryString = $this->collection->getName() . '.' . $method . '(' . join(',', $query) . ')'; $queryString = $this->collection->getName() . '.' . $method . '(' . implode(',', $query) . ')';
$this->connection->logQuery($queryString, [], $time); $this->connection->logQuery($queryString, [], $time);
} }
......
...@@ -111,7 +111,7 @@ class Connection extends \Illuminate\Database\Connection { ...@@ -111,7 +111,7 @@ class Connection extends \Illuminate\Database\Connection {
} }
/** /**
* return MongoClient object * return MongoClient object.
* *
* @return MongoClient * @return MongoClient
*/ */
...@@ -211,10 +211,10 @@ class Connection extends \Illuminate\Database\Connection { ...@@ -211,10 +211,10 @@ class Connection extends \Illuminate\Database\Connection {
} }
/** /**
* Get the PDO driver name. * Get the PDO driver name.
* *
* @return string * @return string
*/ */
public function getDriverName() public function getDriverName()
{ {
return 'mongodb'; return 'mongodb';
......
...@@ -13,7 +13,7 @@ class Builder extends EloquentBuilder { ...@@ -13,7 +13,7 @@ class Builder extends EloquentBuilder {
*/ */
protected $passthru = array( protected $passthru = array(
'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'toSql', 'lists', 'insert', 'insertGetId', 'pluck',
'count', 'min', 'max', 'avg', 'sum', 'exists', 'push', 'pull' 'count', 'min', 'max', 'avg', 'sum', 'exists', 'push', 'pull',
); );
/** /**
...@@ -174,7 +174,7 @@ class Builder extends EloquentBuilder { ...@@ -174,7 +174,7 @@ class Builder extends EloquentBuilder {
$relationCount = array_count_values($query->lists($relation->getHasCompareKey())); $relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
// Remove unwanted related objects based on the operator and count. // Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function($counted) use ($count, $operator) $relationCount = array_filter($relationCount, function ($counted) use ($count, $operator)
{ {
// If we are comparing to 0, we always need all results. // If we are comparing to 0, we always need all results.
if ($count == 0) return true; if ($count == 0) return true;
...@@ -213,29 +213,29 @@ class Builder extends EloquentBuilder { ...@@ -213,29 +213,29 @@ class Builder extends EloquentBuilder {
* @return mixed * @return mixed
*/ */
public function raw($expression = null) public function raw($expression = null)
{ {
// Get raw results from the query builder. // Get raw results from the query builder.
$results = $this->query->raw($expression); $results = $this->query->raw($expression);
// Convert MongoCursor results to a collection of models. // Convert MongoCursor results to a collection of models.
if ($results instanceof MongoCursor) if ($results instanceof MongoCursor)
{ {
$results = iterator_to_array($results, false); $results = iterator_to_array($results, false);
return $this->model->hydrate($results); return $this->model->hydrate($results);
} }
// The result is a single object. // The result is a single object.
else if (is_array($results) and array_key_exists('_id', $results)) elseif (is_array($results) and array_key_exists('_id', $results))
{ {
$model = $this->model->newFromBuilder($results); $model = $this->model->newFromBuilder($results);
$model->setConnection($this->model->getConnection()); $model->setConnection($this->model->getConnection());
return $model; return $model;
} }
return $results; return $results;
} }
} }
...@@ -40,7 +40,7 @@ class Collection extends EloquentCollection { ...@@ -40,7 +40,7 @@ class Collection extends EloquentCollection {
list($value, $operator) = array($operator, '='); list($value, $operator) = array($operator, '=');
} }
return $this->filter(function($item) use ($key, $operator, $value) return $this->filter(function ($item) use ($key, $operator, $value)
{ {
$actual = $item->{$key}; $actual = $item->{$key};
......
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
trait SoftDeletes { trait SoftDeletes {
use \Illuminate\Database\Eloquent\SoftDeletes; use \Illuminate\Database\Eloquent\SoftDeletes;
/** /**
* Get the fully qualified "deleted at" column. * Get the fully qualified "deleted at" column.
* *
* @return string * @return string
*/ */
public function getQualifiedDeletedAtColumn() public function getQualifiedDeletedAtColumn()
{ {
return $this->getDeletedAtColumn(); return $this->getDeletedAtColumn();
} }
} }
<?php namespace Jenssegers\Mongodb; <?php namespace Jenssegers\Mongodb;
use DateTime, MongoId, MongoDate, Carbon\Carbon; use DateTime;
use MongoId;
use MongoDate;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\DatabaseManager as Resolver;
use Jenssegers\Mongodb\Eloquent\Builder; use Jenssegers\Mongodb\Eloquent\Builder;
use Jenssegers\Mongodb\Relations\EmbedsOneOrMany; use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
use Jenssegers\Mongodb\Relations\EmbedsMany; use Jenssegers\Mongodb\Relations\EmbedsMany;
...@@ -63,10 +65,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model { ...@@ -63,10 +65,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/ */
public function getQualifiedKeyName() public function getQualifiedKeyName()
{ {
return $this->getKeyName(); return $this->getKeyName();
} }
/** /**
* Define an embedded one-to-many relationship. * Define an embedded one-to-many relationship.
* *
...@@ -306,7 +307,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model { ...@@ -306,7 +307,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
$value = $this->fromDateTime($value); $value = $this->fromDateTime($value);
} }
array_set($this->attributes, $key, $value); return; array_set($this->attributes, $key, $value);
return;
} }
parent::setAttribute($key, $value); parent::setAttribute($key, $value);
......
<?php namespace Jenssegers\Mongodb; <?php namespace Jenssegers\Mongodb;
use Jenssegers\Mongodb\Model; use Illuminate\Support\ServiceProvider;
use Jenssegers\Mongodb\DatabaseManager;
use Illuminate\Support\ServiceProvider; class MongodbServiceProvider extends ServiceProvider {
class MongodbServiceProvider extends ServiceProvider { /**
* Bootstrap the application events.
/** *
* Bootstrap the application events. * @return void
* */
* @return void public function boot()
*/ {
public function boot() Model::setConnectionResolver($this->app['db']);
{
Model::setConnectionResolver($this->app['db']); Model::setEventDispatcher($this->app['events']);
}
Model::setEventDispatcher($this->app['events']);
} /**
* Register the service provider.
/** *
* Register the service provider. * @return void
* */
* @return void public function register()
*/ {
public function register() $this->app->resolving('db', function ($db)
{ {
$this->app->resolving('db', function($db) $db->extend('mongodb', function ($config)
{ {
$db->extend('mongodb', function($config) return new Connection($config);
{ });
return new Connection($config); });
}); }
});
} }
}
<?php namespace Jenssegers\Mongodb\Query; <?php namespace Jenssegers\Mongodb\Query;
use MongoId, MongoRegex, MongoDate, DateTime, Closure; use MongoId;
use MongoRegex;
use MongoDate;
use DateTime;
use Closure;
use Illuminate\Database\Query\Builder as BaseBuilder; use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
...@@ -9,7 +13,7 @@ use Jenssegers\Mongodb\Connection; ...@@ -9,7 +13,7 @@ use Jenssegers\Mongodb\Connection;
class Builder extends BaseBuilder { class Builder extends BaseBuilder {
/** /**
* The database collection * The database collection.
* *
* @var MongoCollection * @var MongoCollection
*/ */
...@@ -28,7 +32,7 @@ class Builder extends BaseBuilder { ...@@ -28,7 +32,7 @@ class Builder extends BaseBuilder {
* @var int * @var int
*/ */
public $timeout; public $timeout;
/** /**
* The cursor hint value. * The cursor hint value.
* *
...@@ -110,7 +114,7 @@ class Builder extends BaseBuilder { ...@@ -110,7 +114,7 @@ class Builder extends BaseBuilder {
return $this; return $this;
} }
/** /**
* Set the cursor hint. * Set the cursor hint.
* *
...@@ -248,7 +252,7 @@ class Builder extends BaseBuilder { ...@@ -248,7 +252,7 @@ class Builder extends BaseBuilder {
} }
// Distinct query // Distinct query
else if ($this->distinct) elseif ($this->distinct)
{ {
// Return distinct results directly // Return distinct results directly
$column = isset($this->columns[0]) ? $this->columns[0] : '_id'; $column = isset($this->columns[0]) ? $this->columns[0] : '_id';
...@@ -507,7 +511,7 @@ class Builder extends BaseBuilder { ...@@ -507,7 +511,7 @@ class Builder extends BaseBuilder {
} }
// Protect // Protect
$this->where(function($query) use ($column) $this->where(function ($query) use ($column)
{ {
$query->where($column, 'exists', false); $query->where($column, 'exists', false);
...@@ -612,7 +616,7 @@ class Builder extends BaseBuilder { ...@@ -612,7 +616,7 @@ class Builder extends BaseBuilder {
$results = new Collection($this->get([$column, $key])); $results = new Collection($this->get([$column, $key]));
// Convert MongoId's to strings so that lists can do its work. // Convert MongoId's to strings so that lists can do its work.
$results = $results->map(function($item) $results = $results->map(function ($item)
{ {
$item['_id'] = (string) $item['_id']; $item['_id'] = (string) $item['_id'];
...@@ -640,7 +644,7 @@ class Builder extends BaseBuilder { ...@@ -640,7 +644,7 @@ class Builder extends BaseBuilder {
} }
// Create an expression for the given value // Create an expression for the given value
else if ( ! is_null($expression)) elseif ( ! is_null($expression))
{ {
return new Expression($expression); return new Expression($expression);
} }
...@@ -668,7 +672,7 @@ class Builder extends BaseBuilder { ...@@ -668,7 +672,7 @@ class Builder extends BaseBuilder {
{ {
$query = array($operator => $column); $query = array($operator => $column);
} }
else if ($batch) elseif ($batch)
{ {
$query = array($operator => array($column => array('$each' => $value))); $query = array($operator => array($column => array('$each' => $value)));
} }
...@@ -833,14 +837,14 @@ class Builder extends BaseBuilder { ...@@ -833,14 +837,14 @@ class Builder extends BaseBuilder {
// Operator conversions // Operator conversions
$convert = array( $convert = array(
'regexp' => 'regex', 'regexp' => 'regex',
'elemmatch' => 'elemMatch', 'elemmatch' => 'elemMatch',
'geointersects' => 'geoIntersects', 'geointersects' => 'geoIntersects',
'geowithin' => 'geoWithin', 'geowithin' => 'geoWithin',
'nearsphere' => 'nearSphere', 'nearsphere' => 'nearSphere',
'maxdistance' => 'maxDistance', 'maxdistance' => 'maxDistance',
'centersphere' => 'centerSphere', 'centersphere' => 'centerSphere',
'uniquedocs' => 'uniqueDocs', 'uniquedocs' => 'uniqueDocs',
); );
if (array_key_exists($where['operator'], $convert)) if (array_key_exists($where['operator'], $convert))
...@@ -862,7 +866,7 @@ class Builder extends BaseBuilder { ...@@ -862,7 +866,7 @@ class Builder extends BaseBuilder {
} }
// Single value. // Single value.
else if (isset($where['value'])) elseif (isset($where['value']))
{ {
$where['value'] = $this->convertKey($where['value']); $where['value'] = $this->convertKey($where['value']);
} }
...@@ -879,7 +883,7 @@ class Builder extends BaseBuilder { ...@@ -879,7 +883,7 @@ class Builder extends BaseBuilder {
// use the operator of the next where. // use the operator of the next where.
if ($i == 0 and count($wheres) > 1 and $where['boolean'] == 'and') if ($i == 0 and count($wheres) > 1 and $where['boolean'] == 'and')
{ {
$where['boolean'] = $wheres[$i+1]['boolean']; $where['boolean'] = $wheres[$i + 1]['boolean'];
} }
// We use different methods to compile different wheres. // We use different methods to compile different wheres.
...@@ -894,7 +898,7 @@ class Builder extends BaseBuilder { ...@@ -894,7 +898,7 @@ class Builder extends BaseBuilder {
// If there are multiple wheres, we will wrap it with $and. This is needed // If there are multiple wheres, we will wrap it with $and. This is needed
// to make nested wheres work. // to make nested wheres work.
else if (count($wheres) > 1) elseif (count($wheres) > 1)
{ {
$result = array('$and' => array($result)); $result = array('$and' => array($result));
} }
...@@ -944,7 +948,7 @@ class Builder extends BaseBuilder { ...@@ -944,7 +948,7 @@ class Builder extends BaseBuilder {
{ {
$query = array($column => $value); $query = array($column => $value);
} }
else if (array_key_exists($operator, $this->conversion)) elseif (array_key_exists($operator, $this->conversion))
{ {
$query = array($column => array($this->conversion[$operator] => $value)); $query = array($column => array($this->conversion[$operator] => $value));
} }
...@@ -1003,15 +1007,15 @@ class Builder extends BaseBuilder { ...@@ -1003,15 +1007,15 @@ class Builder extends BaseBuilder {
'$or' => array( '$or' => array(
array( array(
$column => array( $column => array(
'$lte' => $values[0] '$lte' => $values[0],
) ),
), ),
array( array(
$column => array( $column => array(
'$gte' => $values[1] '$gte' => $values[1],
) ),
) ),
) ),
); );
} }
else else
...@@ -1019,8 +1023,8 @@ class Builder extends BaseBuilder { ...@@ -1019,8 +1023,8 @@ class Builder extends BaseBuilder {
return array( return array(
$column => array( $column => array(
'$gte' => $values[0], '$gte' => $values[0],
'$lte' => $values[1] '$lte' => $values[1],
) ),
); );
} }
} }
......
...@@ -4,5 +4,4 @@ use Illuminate\Database\Query\Processors\Processor as BaseProcessor; ...@@ -4,5 +4,4 @@ use Illuminate\Database\Query\Processors\Processor as BaseProcessor;
class Processor extends BaseProcessor { class Processor extends BaseProcessor {
} }
...@@ -2,36 +2,36 @@ ...@@ -2,36 +2,36 @@
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo { class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
/** /**
* Set the base constraints on the relation query. * Set the base constraints on the relation query.
* *
* @return void * @return void
*/ */
public function addConstraints() public function addConstraints()
{ {
if (static::$constraints) if (static::$constraints)
{ {
// For belongs to relationships, which are essentially the inverse of has one // For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key // or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent. // of the related models matching on the foreign key that's on a parent.
$this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey}); $this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey});
} }
} }
/** /**
* Set the constraints for an eager load of the relation. * Set the constraints for an eager load of the relation.
* *
* @param array $models * @param array $models
* @return void * @return void
*/ */
public function addEagerConstraints(array $models) public function addEagerConstraints(array $models)
{ {
// We'll grab the primary key name of the related models since it could be set to // We'll grab the primary key name of the related models since it could be set to
// a non-standard name and not "id". We will then construct the constraint for // a non-standard name and not "id". We will then construct the constraint for
// our eagerly loading query so it returns the proper models from execution. // our eagerly loading query so it returns the proper models from execution.
$key = $this->otherKey; $key = $this->otherKey;
$this->query->whereIn($key, $this->getEagerModelKeys($models)); $this->query->whereIn($key, $this->getEagerModelKeys($models));
} }
} }
...@@ -286,7 +286,7 @@ class EmbedsMany extends EmbedsOneOrMany { ...@@ -286,7 +286,7 @@ class EmbedsMany extends EmbedsOneOrMany {
$sliced = array_slice($results, $start, $perPage); $sliced = array_slice($results, $start, $perPage);
return new LengthAwarePaginator($sliced, $total, $perPage, $page, [ return new LengthAwarePaginator($sliced, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath() 'path' => Paginator::resolveCurrentPath(),
]); ]);
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
use MongoId; use MongoId;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
class EmbedsOne extends EmbedsOneOrMany { class EmbedsOne extends EmbedsOneOrMany {
......
...@@ -124,10 +124,10 @@ abstract class EmbedsOneOrMany extends Relation { ...@@ -124,10 +124,10 @@ abstract class EmbedsOneOrMany extends Relation {
} }
/** /**
* Shorthand to get the results of the relationship. * Shorthand to get the results of the relationship.
* *
* @return Jenssegers\Mongodb\Eloquent\Collection * @return Jenssegers\Mongodb\Eloquent\Collection
*/ */
public function get() public function get()
{ {
return $this->getResults(); return $this->getResults();
...@@ -208,7 +208,7 @@ abstract class EmbedsOneOrMany extends Relation { ...@@ -208,7 +208,7 @@ abstract class EmbedsOneOrMany extends Relation {
} }
/** /**
* Transform single ID, single Model or array of Models into an array of IDs * Transform single ID, single Model or array of Models into an array of IDs.
* *
* @param mixed $ids * @param mixed $ids
* @return array * @return array
...@@ -305,7 +305,7 @@ abstract class EmbedsOneOrMany extends Relation { ...@@ -305,7 +305,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/ */
protected function toModel($attributes = array()) protected function toModel($attributes = array())
{ {
if (is_null($attributes)) return null; if (is_null($attributes)) return;
$model = $this->related->newFromBuilder((array) $attributes); $model = $this->related->newFromBuilder((array) $attributes);
......
<?php namespace Jenssegers\Mongodb\Relations; <?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany; use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
class HasMany extends EloquentHasMany { class HasMany extends EloquentHasMany {
......
<?php namespace Jenssegers\Mongodb\Relations; <?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne; use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
class HasOne extends EloquentHasOne { class HasOne extends EloquentHasOne {
......
<?php namespace Jenssegers\Mongodb\Relations; <?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo; use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
class MorphTo extends EloquentMorphTo { class MorphTo extends EloquentMorphTo {
/** /**
* Set the base constraints on the relation query. * Set the base constraints on the relation query.
* *
* @return void * @return void
*/ */
public function addConstraints() public function addConstraints()
{ {
if (static::$constraints) if (static::$constraints)
{ {
// For belongs to relationships, which are essentially the inverse of has one // For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key // or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent. // of the related models matching on the foreign key that's on a parent.
$this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey}); $this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey});
} }
} }
} }
...@@ -5,232 +5,232 @@ use Illuminate\Database\Connection; ...@@ -5,232 +5,232 @@ use Illuminate\Database\Connection;
class Blueprint extends \Illuminate\Database\Schema\Blueprint { class Blueprint extends \Illuminate\Database\Schema\Blueprint {
/** /**
* The MongoConnection object for this blueprint. * The MongoConnection object for this blueprint.
* *
* @var MongoConnection * @var MongoConnection
*/ */
protected $connection; protected $connection;
/** /**
* The MongoCollection object for this blueprint. * The MongoCollection object for this blueprint.
* *
* @var MongoCollection * @var MongoCollection
*/ */
protected $collection; protected $collection;
/** /**
* Fluent columns * Fluent columns.
* *
* @var array * @var array
*/ */
protected $columns = array(); protected $columns = array();
/** /**
* Create a new schema blueprint. * Create a new schema blueprint.
* *
* @param string $table * @param string $table
* @param Closure $callback * @param Closure $callback
* @return void * @return void
*/ */
public function __construct(Connection $connection, $collection) public function __construct(Connection $connection, $collection)
{ {
$this->connection = $connection; $this->connection = $connection;
$this->collection = $connection->getCollection($collection); $this->collection = $connection->getCollection($collection);
} }
/** /**
* Specify an index for the collection. * Specify an index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function index($columns = null, $options = array()) public function index($columns = null, $options = array())
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
// Columns are passed as a default array. // Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns))) if (is_array($columns) && is_int(key($columns)))
{ {
// Transform the columns to the required array format. // Transform the columns to the required array format.
$transform = array(); $transform = array();
foreach ($columns as $column) foreach ($columns as $column)
{ {
$transform[$column] = 1; $transform[$column] = 1;
} }
$columns = $transform; $columns = $transform;
} }
$this->collection->ensureIndex($columns, $options); $this->collection->ensureIndex($columns, $options);
return $this; return $this;
} }
/** /**
* Indicate that the given index should be dropped. * Indicate that the given index should be dropped.
* *
* @param string|array $columns * @param string|array $columns
* @return Blueprint * @return Blueprint
*/ */
public function dropIndex($columns = null) public function dropIndex($columns = null)
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
// Columns are passed as a default array. // Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns))) if (is_array($columns) && is_int(key($columns)))
{ {
// Transform the columns to the required array format. // Transform the columns to the required array format.
$transform = array(); $transform = array();
foreach ($columns as $column) foreach ($columns as $column)
{ {
$transform[$column] = 1; $transform[$column] = 1;
} }
$columns = $transform; $columns = $transform;
} }
$this->collection->deleteIndex($columns); $this->collection->deleteIndex($columns);
return $this; return $this;
} }
/** /**
* Specify a unique index for the collection. * Specify a unique index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @return Blueprint * @return Blueprint
*/ */
public function unique($columns = null, $name = null) public function unique($columns = null, $name = null)
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
$this->index($columns, array('unique' => true)); $this->index($columns, array('unique' => true));
return $this; return $this;
} }
/** /**
* Specify a non blocking index for the collection. * Specify a non blocking index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @return Blueprint * @return Blueprint
*/ */
public function background($columns = null) public function background($columns = null)
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
$this->index($columns, array('background' => true)); $this->index($columns, array('background' => true));
return $this; return $this;
} }
/** /**
* Specify a sparse index for the collection. * Specify a sparse index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @return Blueprint * @return Blueprint
*/ */
public function sparse($columns = null) public function sparse($columns = null)
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
$this->index($columns, array('sparse' => true)); $this->index($columns, array('sparse' => true));
return $this; return $this;
} }
/** /**
* Specify the number of seconds after wich a document should be considered expired based, * Specify the number of seconds after wich a document should be considered expired based,
* on the given single-field index containing a date. * on the given single-field index containing a date.
* *
* @param string|array $columns * @param string|array $columns
* @param int $seconds * @param int $seconds
* @return Blueprint * @return Blueprint
*/ */
public function expire($columns, $seconds) public function expire($columns, $seconds)
{ {
$columns = $this->fluent($columns); $columns = $this->fluent($columns);
$this->index($columns, array('expireAfterSeconds' => $seconds)); $this->index($columns, array('expireAfterSeconds' => $seconds));
return $this; return $this;
} }
/** /**
* Indicate that the table needs to be created. * Indicate that the table needs to be created.
* *
* @return bool * @return bool
*/ */
public function create() public function create()
{ {
$collection = $this->collection->getName(); $collection = $this->collection->getName();
$db = $this->connection->getMongoDB(); $db = $this->connection->getMongoDB();
// Ensure the collection is created. // Ensure the collection is created.
$db->createCollection($collection); $db->createCollection($collection);
} }
/** /**
* Indicate that the collection should be dropped. * Indicate that the collection should be dropped.
* *
* @return bool * @return bool
*/ */
public function drop() public function drop()
{ {
$this->collection->drop(); $this->collection->drop();
} }
/** /**
* Add a new column to the blueprint. * Add a new column to the blueprint.
* *
* @param string $type * @param string $type
* @param string $name * @param string $name
* @param array $parameters * @param array $parameters
* @return Blueprint * @return Blueprint
*/ */
protected function addColumn($type, $name, array $parameters = array()) protected function addColumn($type, $name, array $parameters = array())
{ {
$this->fluent($name); $this->fluent($name);
return $this; return $this;
} }
/** /**
* Allow fluent columns * Allow fluent columns.
* *
* @param string|array $columns * @param string|array $columns
* @return string|array * @return string|array
*/ */
protected function fluent($columns = null) protected function fluent($columns = null)
{ {
if (is_null($columns)) if (is_null($columns))
{ {
return $this->columns; return $this->columns;
} }
else if (is_string($columns)) elseif (is_string($columns))
{ {
return $this->columns = array($columns); return $this->columns = array($columns);
} }
else else
{ {
return $this->columns = $columns; return $this->columns = $columns;
} }
} }
/** /**
* Allows the use of unsupported schema methods. * Allows the use of unsupported schema methods.
* *
* @return Blueprint * @return Blueprint
*/ */
public function __call($method, $args) public function __call($method, $args)
{ {
// Dummy. // Dummy.
return $this; return $this;
} }
} }
...@@ -2,114 +2,113 @@ ...@@ -2,114 +2,113 @@
use Closure; use Closure;
use Jenssegers\Mongodb\Connection; use Jenssegers\Mongodb\Connection;
use Jenssegers\Mongodb\Schema\Blueprint;
class Builder extends \Illuminate\Database\Schema\Builder { class Builder extends \Illuminate\Database\Schema\Builder {
/** /**
* Create a new database Schema manager. * Create a new database Schema manager.
* *
* @param Connection $connection * @param Connection $connection
*/ */
public function __construct(Connection $connection) public function __construct(Connection $connection)
{ {
$this->connection = $connection; $this->connection = $connection;
} }
/** /**
* Determine if the given collection exists. * Determine if the given collection exists.
* *
* @param string $collection * @param string $collection
* @return bool * @return bool
*/ */
public function hasCollection($collection) public function hasCollection($collection)
{ {
$db = $this->connection->getMongoDB(); $db = $this->connection->getMongoDB();
return in_array($collection, $db->getCollectionNames()); return in_array($collection, $db->getCollectionNames());
} }
/** /**
* Determine if the given collection exists. * Determine if the given collection exists.
* *
* @param string $collection * @param string $collection
* @return bool * @return bool
*/ */
public function hasTable($collection) public function hasTable($collection)
{ {
return $this->hasCollection($collection); return $this->hasCollection($collection);
} }
/** /**
* Modify a collection on the schema. * Modify a collection on the schema.
* *
* @param string $collection * @param string $collection
* @param Closure $callback * @param Closure $callback
* @return bool * @return bool
*/ */
public function collection($collection, Closure $callback) public function collection($collection, Closure $callback)
{ {
$blueprint = $this->createBlueprint($collection); $blueprint = $this->createBlueprint($collection);
if ($callback) if ($callback)
{ {
$callback($blueprint); $callback($blueprint);
} }
} }
/** /**
* Modify a collection on the schema. * Modify a collection on the schema.
* *
* @param string $collection * @param string $collection
* @param Closure $callback * @param Closure $callback
* @return bool * @return bool
*/ */
public function table($collection, Closure $callback) public function table($collection, Closure $callback)
{ {
return $this->collection($collection, $callback); return $this->collection($collection, $callback);
} }
/** /**
* Create a new collection on the schema. * Create a new collection on the schema.
* *
* @param string $collection * @param string $collection
* @param Closure $callback * @param Closure $callback
* @return bool * @return bool
*/ */
public function create($collection, Closure $callback = null) public function create($collection, Closure $callback = null)
{ {
$blueprint = $this->createBlueprint($collection); $blueprint = $this->createBlueprint($collection);
$blueprint->create(); $blueprint->create();
if ($callback) if ($callback)
{ {
$callback($blueprint); $callback($blueprint);
} }
} }
/** /**
* Drop a collection from the schema. * Drop a collection from the schema.
* *
* @param string $collection * @param string $collection
* @return bool * @return bool
*/ */
public function drop($collection) public function drop($collection)
{ {
$blueprint = $this->createBlueprint($collection); $blueprint = $this->createBlueprint($collection);
return $blueprint->drop(); return $blueprint->drop();
} }
/** /**
* Create a new Blueprint. * Create a new Blueprint.
* *
* @param string $collection * @param string $collection
* @return Schema\Blueprint * @return Schema\Blueprint
*/ */
protected function createBlueprint($collection, Closure $callback = null) protected function createBlueprint($collection, Closure $callback = null)
{ {
return new Blueprint($this->connection, $collection); return new Blueprint($this->connection, $collection);
} }
} }
...@@ -13,9 +13,9 @@ class AuthTest extends TestCase { ...@@ -13,9 +13,9 @@ class AuthTest extends TestCase {
public function testAuthAttempt() public function testAuthAttempt()
{ {
$user = User::create([ $user = User::create([
'name' => 'John Doe', 'name' => 'John Doe',
'email' => 'john@doe.com', 'email' => 'john@doe.com',
'password' => Hash::make('foobar') 'password' => Hash::make('foobar'),
]); ]);
$this->assertTrue(Auth::attempt(['email' => 'john@doe.com', 'password' => 'foobar'], true)); $this->assertTrue(Auth::attempt(['email' => 'john@doe.com', 'password' => 'foobar'], true));
...@@ -31,9 +31,9 @@ class AuthTest extends TestCase { ...@@ -31,9 +31,9 @@ class AuthTest extends TestCase {
$broker = new PasswordBroker($tokens, $users, $mailer, ''); $broker = new PasswordBroker($tokens, $users, $mailer, '');
$user = User::create([ $user = User::create([
'name' => 'John Doe', 'name' => 'John Doe',
'email' => 'john@doe.com', 'email' => 'john@doe.com',
'password' => Hash::make('foobar') 'password' => Hash::make('foobar'),
]); ]);
$mailer->shouldReceive('send')->once(); $mailer->shouldReceive('send')->once();
...@@ -46,13 +46,13 @@ class AuthTest extends TestCase { ...@@ -46,13 +46,13 @@ class AuthTest extends TestCase {
$this->assertInstanceOf('MongoDate', $reminder['created_at']); $this->assertInstanceOf('MongoDate', $reminder['created_at']);
$credentials = [ $credentials = [
'email' => 'john@doe.com', 'email' => 'john@doe.com',
'password' => 'foobar', 'password' => 'foobar',
'password_confirmation' => 'foobar', 'password_confirmation' => 'foobar',
'token' => $reminder['token'] 'token' => $reminder['token'],
]; ];
$response = $broker->reset($credentials, function($user, $password) $response = $broker->reset($credentials, function ($user, $password)
{ {
$user->password = bcrypt($password); $user->password = bcrypt($password);
$user->save(); $user->save();
......
...@@ -2,132 +2,132 @@ ...@@ -2,132 +2,132 @@
class ConnectionTest extends TestCase { class ConnectionTest extends TestCase {
public function testConnection() public function testConnection()
{ {
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
$this->assertInstanceOf('Jenssegers\Mongodb\Connection', $connection); $this->assertInstanceOf('Jenssegers\Mongodb\Connection', $connection);
} }
public function testReconnect() public function testReconnect()
{ {
$c1 = DB::connection('mongodb'); $c1 = DB::connection('mongodb');
$c2 = DB::connection('mongodb'); $c2 = DB::connection('mongodb');
$this->assertEquals(spl_object_hash($c1), spl_object_hash($c2)); $this->assertEquals(spl_object_hash($c1), spl_object_hash($c2));
$c1 = DB::connection('mongodb'); $c1 = DB::connection('mongodb');
DB::purge('mongodb'); DB::purge('mongodb');
$c2 = DB::connection('mongodb'); $c2 = DB::connection('mongodb');
$this->assertNotEquals(spl_object_hash($c1), spl_object_hash($c2)); $this->assertNotEquals(spl_object_hash($c1), spl_object_hash($c2));
} }
public function testDb() public function testDb()
{ {
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
$this->assertInstanceOf('MongoDB', $connection->getMongoDB()); $this->assertInstanceOf('MongoDB', $connection->getMongoDB());
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
$this->assertInstanceOf('MongoClient', $connection->getMongoClient()); $this->assertInstanceOf('MongoClient', $connection->getMongoClient());
} }
public function testCollection() public function testCollection()
{ {
$collection = DB::connection('mongodb')->getCollection('unittest'); $collection = DB::connection('mongodb')->getCollection('unittest');
$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection); $this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
$collection = DB::connection('mongodb')->collection('unittests'); $collection = DB::connection('mongodb')->collection('unittests');
$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection); $this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
$collection = DB::connection('mongodb')->table('unittests'); $collection = DB::connection('mongodb')->table('unittests');
$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection); $this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
} }
public function testDynamic() public function testDynamic()
{ {
$dbs = DB::connection('mongodb')->listCollections(); $dbs = DB::connection('mongodb')->listCollections();
$this->assertTrue(is_array($dbs)); $this->assertTrue(is_array($dbs));
} }
/*public function testMultipleConnections() /*public function testMultipleConnections()
{ {
global $app; global $app;
# Add fake host # Add fake host
$db = $app['config']['database.connections']['mongodb']; $db = $app['config']['database.connections']['mongodb'];
$db['host'] = array($db['host'], '1.2.3.4'); $db['host'] = array($db['host'], '1.2.3.4');
$connection = new Connection($db); $connection = new Connection($db);
$mongoclient = $connection->getMongoClient(); $mongoclient = $connection->getMongoClient();
$hosts = $mongoclient->getHosts(); $hosts = $mongoclient->getHosts();
$this->assertEquals(1, count($hosts)); $this->assertEquals(1, count($hosts));
}*/ }*/
public function testQueryLog() public function testQueryLog()
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$this->assertEquals(0, count(DB::getQueryLog())); $this->assertEquals(0, count(DB::getQueryLog()));
DB::collection('items')->get(); DB::collection('items')->get();
$this->assertEquals(1, count(DB::getQueryLog())); $this->assertEquals(1, count(DB::getQueryLog()));
DB::collection('items')->insert(['name' => 'test']); DB::collection('items')->insert(['name' => 'test']);
$this->assertEquals(2, count(DB::getQueryLog())); $this->assertEquals(2, count(DB::getQueryLog()));
DB::collection('items')->count(); DB::collection('items')->count();
$this->assertEquals(3, count(DB::getQueryLog())); $this->assertEquals(3, count(DB::getQueryLog()));
DB::collection('items')->where('name', 'test')->update(['name' => 'test']); DB::collection('items')->where('name', 'test')->update(['name' => 'test']);
$this->assertEquals(4, count(DB::getQueryLog())); $this->assertEquals(4, count(DB::getQueryLog()));
DB::collection('items')->where('name', 'test')->delete(); DB::collection('items')->where('name', 'test')->delete();
$this->assertEquals(5, count(DB::getQueryLog())); $this->assertEquals(5, count(DB::getQueryLog()));
} }
public function testSchemaBuilder() public function testSchemaBuilder()
{ {
$schema = DB::connection('mongodb')->getSchemaBuilder(); $schema = DB::connection('mongodb')->getSchemaBuilder();
$this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema); $this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema);
} }
public function testDriverName() public function testDriverName()
{ {
$driver = DB::connection('mongodb')->getDriverName(); $driver = DB::connection('mongodb')->getDriverName();
$this->assertEquals('mongodb', $driver); $this->assertEquals('mongodb', $driver);
} }
public function testAuth() public function testAuth()
{ {
Config::set('database.connections.mongodb.username', 'foo'); Config::set('database.connections.mongodb.username', 'foo');
Config::set('database.connections.mongodb.password', 'bar'); Config::set('database.connections.mongodb.password', 'bar');
$host = Config::get('database.connections.mongodb.host'); $host = Config::get('database.connections.mongodb.host');
$port = Config::get('database.connections.mongodb.port', 27017); $port = Config::get('database.connections.mongodb.port', 27017);
$database = Config::get('database.connections.mongodb.database'); $database = Config::get('database.connections.mongodb.database');
$this->setExpectedExceptionRegExp('MongoConnectionException', "/Failed to connect to: $host:$port: Authentication failed on database '$database' with username 'foo': auth fail/"); $this->setExpectedExceptionRegExp('MongoConnectionException', "/Failed to connect to: $host:$port: Authentication failed on database '$database' with username 'foo': auth fail/");
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
} }
public function testCustomPort() public function testCustomPort()
{ {
$port = 27000; $port = 27000;
Config::set('database.connections.mongodb.port', $port); Config::set('database.connections.mongodb.port', $port);
$host = Config::get('database.connections.mongodb.host'); $host = Config::get('database.connections.mongodb.host');
$database = Config::get('database.connections.mongodb.database'); $database = Config::get('database.connections.mongodb.database');
$this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Connection refused"); $this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Connection refused");
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
} }
public function testHostWithPorts() public function testHostWithPorts()
{ {
$hosts = ['localhost:27001', 'localhost:27002']; $hosts = ['localhost:27001', 'localhost:27002'];
Config::set('database.connections.mongodb.port', 27000); Config::set('database.connections.mongodb.port', 27000);
Config::set('database.connections.mongodb.host', ['localhost:27001', 'localhost:27002']); Config::set('database.connections.mongodb.host', ['localhost:27001', 'localhost:27002']);
$database = Config::get('database.connections.mongodb.database'); $database = Config::get('database.connections.mongodb.database');
$this->setExpectedException('MongoConnectionException', "Failed to connect to: " . $hosts[0] . ": Connection refused; Failed to connect to: " . $hosts[1] . ": Connection refused"); $this->setExpectedException('MongoConnectionException', "Failed to connect to: " . $hosts[0] . ": Connection refused; Failed to connect to: " . $hosts[1] . ": Connection refused");
$connection = DB::connection('mongodb'); $connection = DB::connection('mongodb');
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -228,12 +228,12 @@ class RelationsTest extends TestCase { ...@@ -228,12 +228,12 @@ class RelationsTest extends TestCase {
$clients = [ $clients = [
Client::create(['name' => 'Pork Pies Ltd.'])->_id, Client::create(['name' => 'Pork Pies Ltd.'])->_id,
Client::create(['name' => 'Buffet Bar Inc.'])->_id Client::create(['name' => 'Buffet Bar Inc.'])->_id,
]; ];
$moreClients = [ $moreClients = [
Client::create(['name' => 'synced Boloni Ltd.'])->_id, Client::create(['name' => 'synced Boloni Ltd.'])->_id,
Client::create(['name' => 'synced Meatballs Inc.'])->_id Client::create(['name' => 'synced Meatballs Inc.'])->_id,
]; ];
// Sync multiple records // Sync multiple records
...@@ -410,14 +410,14 @@ class RelationsTest extends TestCase { ...@@ -410,14 +410,14 @@ class RelationsTest extends TestCase {
$authors = User::has('books', '!=', 0)->get(); $authors = User::has('books', '!=', 0)->get();
$this->assertCount(2, $authors); $this->assertCount(2, $authors);
$authors = User::whereHas('books', function($query) $authors = User::whereHas('books', function ($query)
{ {
$query->where('rating', 5); $query->where('rating', 5);
})->get(); })->get();
$this->assertCount(1, $authors); $this->assertCount(1, $authors);
$authors = User::whereHas('books', function($query) $authors = User::whereHas('books', function ($query)
{ {
$query->where('rating', '<', 5); $query->where('rating', '<', 5);
...@@ -451,15 +451,15 @@ class RelationsTest extends TestCase { ...@@ -451,15 +451,15 @@ class RelationsTest extends TestCase {
$client = Client::create([ $client = Client::create([
'data' => [ 'data' => [
'client_id' => 35298, 'client_id' => 35298,
'name' => 'John Doe' 'name' => 'John Doe',
] ],
]); ]);
$address = $client->addresses()->create([ $address = $client->addresses()->create([
'data' => [ 'data' => [
'address_id' => 1432, 'address_id' => 1432,
'city' => 'Paris' 'city' => 'Paris',
] ],
]); ]);
$client = Client::where('data.client_id', 35298)->first(); $client = Client::where('data.client_id', 35298)->first();
......
...@@ -2,187 +2,187 @@ ...@@ -2,187 +2,187 @@
class SchemaTest extends TestCase { class SchemaTest extends TestCase {
public function tearDown() public function tearDown()
{ {
Schema::drop('newcollection'); Schema::drop('newcollection');
} }
public function testCreate() public function testCreate()
{ {
Schema::create('newcollection'); Schema::create('newcollection');
$this->assertTrue(Schema::hasCollection('newcollection')); $this->assertTrue(Schema::hasCollection('newcollection'));
$this->assertTrue(Schema::hasTable('newcollection')); $this->assertTrue(Schema::hasTable('newcollection'));
} }
public function testCreateWithCallback() public function testCreateWithCallback()
{ {
$instance = $this; $instance = $this;
Schema::create('newcollection', function($collection) use ($instance) Schema::create('newcollection', function ($collection) use ($instance)
{ {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection); $instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
}); });
$this->assertTrue(Schema::hasCollection('newcollection')); $this->assertTrue(Schema::hasCollection('newcollection'));
} }
public function testDrop() public function testDrop()
{ {
Schema::create('newcollection'); Schema::create('newcollection');
Schema::drop('newcollection'); Schema::drop('newcollection');
$this->assertFalse(Schema::hasCollection('newcollection')); $this->assertFalse(Schema::hasCollection('newcollection'));
} }
public function testBluePrint() public function testBluePrint()
{ {
$instance = $this; $instance = $this;
Schema::collection('newcollection', function($collection) use ($instance) Schema::collection('newcollection', function ($collection) use ($instance)
{ {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection); $instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
}); });
Schema::table('newcollection', function($collection) use ($instance) Schema::table('newcollection', function ($collection) use ($instance)
{ {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection); $instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
}); });
} }
public function testIndex() public function testIndex()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->index('mykey'); $collection->index('mykey');
}); });
$index = $this->getIndex('newcollection', 'mykey'); $index = $this->getIndex('newcollection', 'mykey');
$this->assertEquals(1, $index['key']['mykey']); $this->assertEquals(1, $index['key']['mykey']);
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->index(['mykey']); $collection->index(['mykey']);
}); });
$index = $this->getIndex('newcollection', 'mykey'); $index = $this->getIndex('newcollection', 'mykey');
$this->assertEquals(1, $index['key']['mykey']); $this->assertEquals(1, $index['key']['mykey']);
} }
public function testUnique() public function testUnique()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->unique('uniquekey'); $collection->unique('uniquekey');
}); });
$index = $this->getIndex('newcollection', 'uniquekey'); $index = $this->getIndex('newcollection', 'uniquekey');
$this->assertEquals(1, $index['unique']); $this->assertEquals(1, $index['unique']);
} }
public function testDropIndex() public function testDropIndex()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->unique('uniquekey'); $collection->unique('uniquekey');
$collection->dropIndex('uniquekey'); $collection->dropIndex('uniquekey');
}); });
$index = $this->getIndex('newcollection', 'uniquekey'); $index = $this->getIndex('newcollection', 'uniquekey');
$this->assertEquals(null, $index); $this->assertEquals(null, $index);
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->unique('uniquekey'); $collection->unique('uniquekey');
$collection->dropIndex(['uniquekey']); $collection->dropIndex(['uniquekey']);
}); });
$index = $this->getIndex('newcollection', 'uniquekey'); $index = $this->getIndex('newcollection', 'uniquekey');
$this->assertEquals(null, $index); $this->assertEquals(null, $index);
} }
public function testBackground() public function testBackground()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->background('backgroundkey'); $collection->background('backgroundkey');
}); });
$index = $this->getIndex('newcollection', 'backgroundkey'); $index = $this->getIndex('newcollection', 'backgroundkey');
$this->assertEquals(1, $index['background']); $this->assertEquals(1, $index['background']);
} }
public function testSparse() public function testSparse()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->sparse('sparsekey'); $collection->sparse('sparsekey');
}); });
$index = $this->getIndex('newcollection', 'sparsekey'); $index = $this->getIndex('newcollection', 'sparsekey');
$this->assertEquals(1, $index['sparse']); $this->assertEquals(1, $index['sparse']);
} }
public function testExpire() public function testExpire()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->expire('expirekey', 60); $collection->expire('expirekey', 60);
}); });
$index = $this->getIndex('newcollection', 'expirekey'); $index = $this->getIndex('newcollection', 'expirekey');
$this->assertEquals(60, $index['expireAfterSeconds']); $this->assertEquals(60, $index['expireAfterSeconds']);
} }
public function testSoftDeletes() public function testSoftDeletes()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->softDeletes(); $collection->softDeletes();
}); });
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->string('email')->nullable()->index(); $collection->string('email')->nullable()->index();
}); });
$index = $this->getIndex('newcollection', 'email'); $index = $this->getIndex('newcollection', 'email');
$this->assertEquals(1, $index['key']['email']); $this->assertEquals(1, $index['key']['email']);
} }
public function testFluent() public function testFluent()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->string('email')->index(); $collection->string('email')->index();
$collection->string('token')->index(); $collection->string('token')->index();
$collection->timestamp('created_at'); $collection->timestamp('created_at');
}); });
$index = $this->getIndex('newcollection', 'email'); $index = $this->getIndex('newcollection', 'email');
$this->assertEquals(1, $index['key']['email']); $this->assertEquals(1, $index['key']['email']);
$index = $this->getIndex('newcollection', 'token'); $index = $this->getIndex('newcollection', 'token');
$this->assertEquals(1, $index['key']['token']); $this->assertEquals(1, $index['key']['token']);
} }
public function testDummies() public function testDummies()
{ {
Schema::collection('newcollection', function($collection) Schema::collection('newcollection', function ($collection)
{ {
$collection->boolean('activated')->default(0); $collection->boolean('activated')->default(0);
$collection->integer('user_id')->unsigned(); $collection->integer('user_id')->unsigned();
}); });
} }
protected function getIndex($collection, $name) protected function getIndex($collection, $name)
{ {
$collection = DB::getCollection($collection); $collection = DB::getCollection($collection);
foreach ($collection->getIndexInfo() as $index) foreach ($collection->getIndexInfo() as $index)
{ {
if (isset($index['key'][$name])) return $index; if (isset($index['key'][$name])) return $index;
} }
return false; return false;
} }
} }
This diff is collapsed.
This diff is collapsed.
...@@ -4,9 +4,9 @@ use Jenssegers\Mongodb\Model as Eloquent; ...@@ -4,9 +4,9 @@ use Jenssegers\Mongodb\Model as Eloquent;
class Book extends Eloquent { class Book extends Eloquent {
protected $collection = 'books'; protected $collection = 'books';
protected static $unguarded = true; protected static $unguarded = true;
protected $primaryKey = 'title'; protected $primaryKey = 'title';
public function author() public function author()
{ {
......
This diff is collapsed.
...@@ -4,11 +4,11 @@ use Jenssegers\Mongodb\Model as Eloquent; ...@@ -4,11 +4,11 @@ use Jenssegers\Mongodb\Model as Eloquent;
class Group extends Eloquent { class Group extends Eloquent {
protected $collection = 'groups'; protected $collection = 'groups';
protected static $unguarded = true; protected static $unguarded = true;
public function users() public function users()
{ {
return $this->belongsToMany('User', null, 'groups', 'users'); return $this->belongsToMany('User', null, 'groups', 'users');
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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