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