From 8357dbadf1b2b67d768a5bfb9303b5ad0d0148f2 Mon Sep 17 00:00:00 2001 From: divine <48183131+divine@users.noreply.github.com> Date: Sun, 2 May 2021 23:13:02 +0300 Subject: [PATCH 1/2] Apply fixes produced by php-cs-fixer --- src/Collection.php | 2 +- src/Connection.php | 28 +++---- src/Eloquent/Builder.php | 6 +- src/Eloquent/EmbedsRelations.php | 4 +- src/Eloquent/HybridRelations.php | 30 +++---- src/Eloquent/Model.php | 24 +++--- src/Helpers/QueriesRelationships.php | 10 +-- src/MongodbServiceProvider.php | 1 + src/Query/Builder.php | 55 ++++++------ src/Queue/Failed/MongoFailedJobProvider.php | 3 +- src/Relations/BelongsToMany.php | 7 +- src/Relations/EmbedsMany.php | 15 ++-- src/Relations/EmbedsOne.php | 6 +- src/Relations/EmbedsOneOrMany.php | 10 +-- src/Schema/Blueprint.php | 5 +- src/Schema/Builder.php | 1 - src/Validation/DatabasePresenceVerifier.php | 4 +- tests/AuthTest.php | 1 + tests/CollectionTest.php | 1 + tests/ConnectionTest.php | 5 +- tests/DsnTest.php | 1 + tests/EmbeddedRelationsTest.php | 93 +++++++++++---------- tests/GeospatialTest.php | 1 + tests/HybridRelationsTest.php | 9 +- tests/ModelTest.php | 1 + tests/QueryBuilderTest.php | 39 ++++----- tests/QueryTest.php | 1 + tests/RelationsTest.php | 1 + tests/SchemaTest.php | 1 + tests/SeederTest.php | 1 + tests/TestCase.php | 1 + tests/ValidationTest.php | 13 +-- tests/config/database.php | 2 +- tests/models/Address.php | 1 + tests/models/Book.php | 3 +- tests/models/Client.php | 1 + tests/models/Group.php | 1 + tests/models/Guarded.php | 1 + tests/models/Item.php | 3 +- tests/models/Location.php | 1 + tests/models/MysqlBook.php | 3 +- tests/models/MysqlRole.php | 3 +- tests/models/MysqlUser.php | 3 +- tests/models/Photo.php | 1 + tests/models/Role.php | 1 + tests/models/Scoped.php | 1 + tests/models/Soft.php | 3 +- tests/models/User.php | 3 +- 48 files changed, 226 insertions(+), 185 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index a59a232a0..feaa6f55d 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -64,7 +64,7 @@ public function __call($method, $parameters) } } - $queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')'; + $queryString = $this->collection->getCollectionName().'.'.$method.'('.implode(',', $query).')'; $this->connection->logQuery($queryString, [], $time); diff --git a/src/Connection.php b/src/Connection.php index 9212bc2d6..c8e7b6bad 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -119,7 +119,7 @@ public function getDatabaseName() } /** - * Get the name of the default database based on db config or try to detect it from dsn + * Get the name of the default database based on db config or try to detect it from dsn. * @param string $dsn * @param array $config * @return string @@ -131,7 +131,7 @@ protected function getDefaultDatabaseName($dsn, $config) if (preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) { $config['database'] = $matches[1]; } else { - throw new InvalidArgumentException("Database is not properly configured."); + throw new InvalidArgumentException('Database is not properly configured.'); } } @@ -155,10 +155,10 @@ protected function createConnection($dsn, array $config, array $options) } // Check if the credentials are not already set in the options - if (!isset($options['username']) && !empty($config['username'])) { + if (! isset($options['username']) && ! empty($config['username'])) { $options['username'] = $config['username']; } - if (!isset($options['password']) && !empty($config['password'])) { + if (! isset($options['password']) && ! empty($config['password'])) { $options['password'] = $config['password']; } @@ -180,7 +180,7 @@ public function disconnect() */ protected function hasDsnString(array $config) { - return isset($config['dsn']) && !empty($config['dsn']); + return isset($config['dsn']) && ! empty($config['dsn']); } /** @@ -205,14 +205,15 @@ protected function getHostDsn(array $config) foreach ($hosts as &$host) { // Check if we need to add a port to the host - if (strpos($host, ':') === false && !empty($config['port'])) { - $host = $host . ':' . $config['port']; + if (strpos($host, ':') === false && ! empty($config['port'])) { + $host = $host.':'.$config['port']; } } // Check if we want to authenticate against a specific database. - $auth_database = isset($config['options']) && !empty($config['options']['database']) ? $config['options']['database'] : null; - return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : ''); + $auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null; + + return 'mongodb://'.implode(',', $hosts).($auth_database ? '/'.$auth_database : ''); } /** @@ -266,16 +267,15 @@ protected function getDefaultSchemaGrammar() { return new Schema\Grammar(); } - + /** * Set database. * @param \MongoDB\Database $db */ public function setDatabase(\MongoDB\Database $db) - { - $this->db = $db; - } - + { + $this->db = $db; + } /** * Dynamically pass methods to the connection. diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index df692444b..f77e87c2d 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -37,7 +37,7 @@ class Builder extends EloquentBuilder 'push', 'raw', 'sum', - 'toSql' + 'toSql', ]; /** @@ -190,13 +190,13 @@ public function raw($expression = null) * Add the "updated at" column to an array of values. * TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e * wiil be reverted - * Issue in laravel frawework https://github.com/laravel/framework/issues/27791 + * Issue in laravel frawework https://github.com/laravel/framework/issues/27791. * @param array $values * @return array */ protected function addUpdatedAtColumn(array $values) { - if (!$this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) { + if (! $this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) { return $values; } diff --git a/src/Eloquent/EmbedsRelations.php b/src/Eloquent/EmbedsRelations.php index caef0e693..f7cac6c53 100644 --- a/src/Eloquent/EmbedsRelations.php +++ b/src/Eloquent/EmbedsRelations.php @@ -22,7 +22,7 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r // the calling method's name and use that as the relationship name as most // of the time this will be what we desire to use for the relationships. if ($relation === null) { - list(, $caller) = debug_backtrace(false); + [, $caller] = debug_backtrace(false); $relation = $caller['function']; } @@ -56,7 +56,7 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re // the calling method's name and use that as the relationship name as most // of the time this will be what we desire to use for the relationships. if ($relation === null) { - list(, $caller) = debug_backtrace(false); + [, $caller] = debug_backtrace(false); $relation = $caller['function']; } diff --git a/src/Eloquent/HybridRelations.php b/src/Eloquent/HybridRelations.php index 3cfea00bf..e6c5d3352 100644 --- a/src/Eloquent/HybridRelations.php +++ b/src/Eloquent/HybridRelations.php @@ -9,8 +9,8 @@ use Jenssegers\Mongodb\Relations\BelongsToMany; use Jenssegers\Mongodb\Relations\HasMany; use Jenssegers\Mongodb\Relations\HasOne; -use Jenssegers\Mongodb\Relations\MorphTo; use Jenssegers\Mongodb\Relations\MorphMany; +use Jenssegers\Mongodb\Relations\MorphTo; trait HybridRelations { @@ -24,7 +24,7 @@ trait HybridRelations public function hasOne($related, $foreignKey = null, $localKey = null) { // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::hasOne($related, $foreignKey, $localKey); } @@ -49,13 +49,13 @@ public function hasOne($related, $foreignKey = null, $localKey = null) public function morphOne($related, $name, $type = null, $id = null, $localKey = null) { // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::morphOne($related, $name, $type, $id, $localKey); } $instance = new $related; - list($type, $id) = $this->getMorphs($name, $type, $id); + [$type, $id] = $this->getMorphs($name, $type, $id); $localKey = $localKey ?: $this->getKeyName(); @@ -72,7 +72,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey = public function hasMany($related, $foreignKey = null, $localKey = null) { // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::hasMany($related, $foreignKey, $localKey); } @@ -97,7 +97,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null) public function morphMany($related, $name, $type = null, $id = null, $localKey = null) { // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::morphMany($related, $name, $type, $id, $localKey); } @@ -106,7 +106,7 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey = // Here we will gather up the morph type and ID for the relationship so that we // can properly query the intermediate table of a relation. Finally, we will // get the table and create the relationship instances for the developers. - list($type, $id) = $this->getMorphs($name, $type, $id); + [$type, $id] = $this->getMorphs($name, $type, $id); $table = $instance->getTable(); @@ -129,13 +129,13 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat // the calling method's name and use that as the relationship name as most // of the time this will be what we desire to use for the relationships. if ($relation === null) { - list($current, $caller) = debug_backtrace(false, 2); + [$current, $caller] = debug_backtrace(false, 2); $relation = $caller['function']; } // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::belongsTo($related, $foreignKey, $otherKey, $relation); } @@ -143,7 +143,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. if ($foreignKey === null) { - $foreignKey = Str::snake($relation) . '_id'; + $foreignKey = Str::snake($relation).'_id'; } $instance = new $related; @@ -172,12 +172,12 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null // since that is most likely the name of the polymorphic interface. We can // use that to get both the class and foreign key that will be utilized. if ($name === null) { - list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + [$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $name = Str::snake($caller['function']); } - list($type, $id) = $this->getMorphs($name, $type, $id); + [$type, $id] = $this->getMorphs($name, $type, $id); // If the type value is null it is probably safe to assume we're eager loading // the relationship. When that is the case we will pass in a dummy query as @@ -230,7 +230,7 @@ public function belongsToMany( } // Check if it is a relation with an original model. - if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { + if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { return parent::belongsToMany( $related, $collection, @@ -245,11 +245,11 @@ public function belongsToMany( // First, we'll need to determine the foreign key and "other key" for the // relationship. Once we have determined the keys we'll make the query // instances as well as the relationship instances we need for this. - $foreignKey = $foreignKey ?: $this->getForeignKey() . 's'; + $foreignKey = $foreignKey ?: $this->getForeignKey().'s'; $instance = new $related; - $otherKey = $otherKey ?: $instance->getForeignKey() . 's'; + $otherKey = $otherKey ?: $instance->getForeignKey().'s'; // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 37514b614..3553e02ab 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -52,7 +52,7 @@ public function getIdAttribute($value = null) { // If we don't have a value for 'id', we will use the Mongo '_id' value. // This allows us to work with models in a more sql-like way. - if (!$value && array_key_exists('_id', $this->attributes)) { + if (! $value && array_key_exists('_id', $this->attributes)) { $value = $this->attributes['_id']; } @@ -85,7 +85,7 @@ public function fromDateTime($value) } // Let Eloquent convert the value to a DateTime instance. - if (!$value instanceof DateTimeInterface) { + if (! $value instanceof DateTimeInterface) { $value = parent::asDateTime($value); } @@ -140,7 +140,7 @@ public function getTable() */ public function getAttribute($key) { - if (!$key) { + if (! $key) { return; } @@ -150,7 +150,7 @@ public function getAttribute($key) } // This checks for embedded relation support. - if (method_exists($this, $key) && !method_exists(self::class, $key)) { + if (method_exists($this, $key) && ! method_exists(self::class, $key)) { return $this->getRelationValue($key); } @@ -236,7 +236,7 @@ public function getCasts() */ public function originalIsEquivalent($key) { - if (!array_key_exists($key, $this->original)) { + if (! array_key_exists($key, $this->original)) { return false; } @@ -294,9 +294,9 @@ public function push() $unique = false; if (count($parameters) === 3) { - list($column, $values, $unique) = $parameters; + [$column, $values, $unique] = $parameters; } else { - list($column, $values) = $parameters; + [$column, $values] = $parameters; } // Do batch push by default. @@ -342,7 +342,7 @@ protected function pushAttributeValues($column, array $values, $unique = false) foreach ($values as $value) { // Don't add duplicate values when we only want unique values. - if ($unique && (!is_array($current) || in_array($value, $current))) { + if ($unique && (! is_array($current) || in_array($value, $current))) { continue; } @@ -383,7 +383,7 @@ protected function pullAttributeValues($column, array $values) */ public function getForeignKey() { - return Str::snake(class_basename($this)) . '_' . ltrim($this->primaryKey, '_'); + return Str::snake(class_basename($this)).'_'.ltrim($this->primaryKey, '_'); } /** @@ -445,13 +445,13 @@ public function getQueueableRelations() if ($relation instanceof QueueableCollection) { foreach ($relation->getQueueableRelations() as $collectionValue) { - $relations[] = $key . '.' . $collectionValue; + $relations[] = $key.'.'.$collectionValue; } } if ($relation instanceof QueueableEntity) { foreach ($relation->getQueueableRelations() as $entityKey => $entityValue) { - $relations[] = $key . '.' . $entityValue; + $relations[] = $key.'.'.$entityValue; } } } @@ -476,7 +476,7 @@ protected function getRelationsWithoutParent() /** * Checks if column exists on a table. As this is a document model, just return true. This also - * prevents calls to non-existent function Grammar::compileColumnListing() + * prevents calls to non-existent function Grammar::compileColumnListing(). * @param string $key * @return bool */ diff --git a/src/Helpers/QueriesRelationships.php b/src/Helpers/QueriesRelationships.php index 151ead62d..ee130ce79 100644 --- a/src/Helpers/QueriesRelationships.php +++ b/src/Helpers/QueriesRelationships.php @@ -71,7 +71,7 @@ protected function isAcrossConnections(Relation $relation) } /** - * Compare across databases + * Compare across databases. * @param Relation $relation * @param string $operator * @param int $count @@ -91,7 +91,7 @@ public function addHybridHas(Relation $relation, $operator = '>=', $count = 1, $ $not = in_array($operator, ['<', '<=', '!=']); // If we are comparing to 0, we need an additional $not flip. if ($count == 0) { - $not = !$not; + $not = ! $not; } $relations = $hasQuery->pluck($this->getHasCompareKey($relation)); @@ -149,7 +149,7 @@ protected function getConstrainedRelatedIds($relations, $operator, $count) } /** - * Returns key we are constraining this parent model's query with + * Returns key we are constraining this parent model's query with. * @param Relation $relation * @return string * @throws Exception @@ -164,10 +164,10 @@ protected function getRelatedConstraintKey(Relation $relation) return $relation->getForeignKeyName(); } - if ($relation instanceof BelongsToMany && !$this->isAcrossConnections($relation)) { + if ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation)) { return $this->model->getKeyName(); } - throw new Exception(class_basename($relation) . ' is not supported for hybrid query constraints.'); + throw new Exception(class_basename($relation).' is not supported for hybrid query constraints.'); } } diff --git a/src/MongodbServiceProvider.php b/src/MongodbServiceProvider.php index 99ec5e553..3afb69cf0 100644 --- a/src/MongodbServiceProvider.php +++ b/src/MongodbServiceProvider.php @@ -27,6 +27,7 @@ public function register() $this->app->resolving('db', function ($db) { $db->extend('mongodb', function ($config, $name) { $config['name'] = $name; + return new Connection($config); }); }); diff --git a/src/Query/Builder.php b/src/Query/Builder.php index b611262cd..6eb910587 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -18,8 +18,7 @@ use RuntimeException; /** - * Class Builder - * @package Jenssegers\Mongodb\Query + * Class Builder. */ class Builder extends BaseBuilder { @@ -197,11 +196,11 @@ public function get($columns = []) */ public function cursor($columns = []) { - $result = $this->getFresh($columns, true); + $result = $this->getFresh($columns, true); if ($result instanceof LazyCollection) { return $result; } - throw new RuntimeException("Query not compatible with cursor"); + throw new RuntimeException('Query not compatible with cursor'); } /** @@ -235,18 +234,18 @@ public function getFresh($columns = [], $returnLazy = false) // Add grouping columns to the $group part of the aggregation pipeline. if ($this->groups) { foreach ($this->groups as $column) { - $group['_id'][$column] = '$' . $column; + $group['_id'][$column] = '$'.$column; // When grouping, also add the $last operator to each grouped field, // this mimics MySQL's behaviour a bit. - $group[$column] = ['$last' => '$' . $column]; + $group[$column] = ['$last' => '$'.$column]; } // Do the same for other columns that are selected. foreach ($this->columns as $column) { $key = str_replace('.', '_', $column); - $group[$key] = ['$last' => '$' . $column]; + $group[$key] = ['$last' => '$'.$column]; } } @@ -278,15 +277,16 @@ public function getFresh($columns = [], $returnLazy = false) $results = [ [ '_id' => null, - 'aggregate' => $totalResults - ] + 'aggregate' => $totalResults, + ], ]; + return new Collection($results); } elseif ($function == 'count') { // Translate count into sum. $group['aggregate'] = ['$sum' => 1]; } else { - $group['aggregate'] = ['$' . $function => '$' . $column]; + $group['aggregate'] = ['$'.$function => '$'.$column]; } } } @@ -304,7 +304,7 @@ public function getFresh($columns = [], $returnLazy = false) // apply unwinds for subdocument array aggregation foreach ($unwinds as $unwind) { - $pipeline[] = ['$unwind' => '$' . $unwind]; + $pipeline[] = ['$unwind' => '$'.$unwind]; } if ($group) { @@ -408,6 +408,7 @@ public function getFresh($columns = [], $returnLazy = false) // Return results as an array with numeric keys $results = iterator_to_array($cursor, false); + return new Collection($results); } } @@ -556,20 +557,20 @@ public function insert(array $values) foreach ($values as $value) { // As soon as we find a value that is not an array we assume the user is // inserting a single document. - if (!is_array($value)) { + if (! is_array($value)) { $batch = false; break; } } - if (!$batch) { + if (! $batch) { $values = [$values]; } // Batch insert $result = $this->collection->insertMany($values); - return (1 == (int) $result->isAcknowledged()); + return 1 == (int) $result->isAcknowledged(); } /** @@ -595,7 +596,7 @@ public function insertGetId(array $values, $sequence = null) public function update(array $values, array $options = []) { // Use $set as default operator. - if (!Str::startsWith(key($values), '$')) { + if (! Str::startsWith(key($values), '$')) { $values = ['$set' => $values]; } @@ -609,7 +610,7 @@ public function increment($column, $amount = 1, array $extra = [], array $option { $query = ['$inc' => [$column => $amount]]; - if (!empty($extra)) { + if (! empty($extra)) { $query['$set'] = $extra; } @@ -658,11 +659,13 @@ public function pluck($column, $key = null) if ($key == '_id') { $results = $results->map(function ($item) { $item['_id'] = (string) $item['_id']; + return $item; }); } $p = Arr::pluck($results, $column, $key); + return new Collection($p); } @@ -706,7 +709,7 @@ public function truncate(): bool { $result = $this->collection->deleteMany([]); - return (1 === (int) $result->isAcknowledged()); + return 1 === (int) $result->isAcknowledged(); } /** @@ -796,7 +799,7 @@ public function pull($column, $value = null) */ public function drop($columns) { - if (!is_array($columns)) { + if (! is_array($columns)) { $columns = [$columns]; } @@ -816,7 +819,7 @@ public function drop($columns) */ public function newQuery() { - return new Builder($this->connection, $this->processor); + return new self($this->connection, $this->processor); } /** @@ -828,7 +831,7 @@ public function newQuery() protected function performUpdate($query, array $options = []) { // Update multiple items by default. - if (!array_key_exists('multiple', $options)) { + if (! array_key_exists('multiple', $options)) { $options['multiple'] = true; } @@ -1006,10 +1009,10 @@ protected function compileWhereBasic(array $where) $regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value)); // Convert like to regular expression. - if (!Str::startsWith($value, '%')) { - $regex = '^' . $regex; + if (! Str::startsWith($value, '%')) { + $regex = '^'.$regex; } - if (!Str::endsWith($value, '%')) { + if (! Str::endsWith($value, '%')) { $regex .= '$'; } @@ -1017,7 +1020,7 @@ protected function compileWhereBasic(array $where) } // Manipulate regexp operations. elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) { // Automatically convert regular expression strings to Regex objects. - if (!$value instanceof Regex) { + if (! $value instanceof Regex) { $e = explode('/', $value); $flag = end($e); $regstr = substr($value, 1, -(strlen($flag) + 1)); @@ -1031,12 +1034,12 @@ protected function compileWhereBasic(array $where) } } - if (!isset($operator) || $operator == '=') { + if (! isset($operator) || $operator == '=') { $query = [$column => $value]; } elseif (array_key_exists($operator, $this->conversion)) { $query = [$column => [$this->conversion[$operator] => $value]]; } else { - $query = [$column => ['$' . $operator => $value]]; + $query = [$column => ['$'.$operator => $value]]; } return $query; diff --git a/src/Queue/Failed/MongoFailedJobProvider.php b/src/Queue/Failed/MongoFailedJobProvider.php index d350bb032..e130cbeab 100644 --- a/src/Queue/Failed/MongoFailedJobProvider.php +++ b/src/Queue/Failed/MongoFailedJobProvider.php @@ -34,6 +34,7 @@ public function all() $all = array_map(function ($job) { $job['id'] = (string) $job['_id']; + return (object) $job; }, $all); @@ -49,7 +50,7 @@ public function find($id) { $job = $this->getTable()->find($id); - if (!$job) { + if (! $job) { return; } diff --git a/src/Relations/BelongsToMany.php b/src/Relations/BelongsToMany.php index 36de393dc..915cc95e2 100644 --- a/src/Relations/BelongsToMany.php +++ b/src/Relations/BelongsToMany.php @@ -306,7 +306,7 @@ public function getQualifiedRelatedPivotKeyName() /** * Format the sync list so that it is keyed by ID. (Legacy Support) - * The original function has been renamed to formatRecordsList since Laravel 5.3 + * The original function has been renamed to formatRecordsList since Laravel 5.3. * @param array $records * @return array * @deprecated @@ -315,11 +315,12 @@ protected function formatSyncList(array $records) { $results = []; foreach ($records as $id => $attributes) { - if (!is_array($attributes)) { - list($id, $attributes) = [$attributes, []]; + if (! is_array($attributes)) { + [$id, $attributes] = [$attributes, []]; } $results[$id] = $attributes; } + return $results; } diff --git a/src/Relations/EmbedsMany.php b/src/Relations/EmbedsMany.php index eda777e8d..d5d8e0d48 100644 --- a/src/Relations/EmbedsMany.php +++ b/src/Relations/EmbedsMany.php @@ -39,13 +39,14 @@ public function getResults() public function performInsert(Model $model) { // Generate a new key if needed. - if ($model->getKeyName() == '_id' && !$model->getKey()) { + if ($model->getKeyName() == '_id' && ! $model->getKey()) { $model->setAttribute('_id', new ObjectID); } // For deeply nested documents, let the parent handle the changes. if ($this->isNested()) { $this->associate($model); + return $this->parent->save() ? $model : false; } @@ -77,10 +78,10 @@ public function performUpdate(Model $model) // Get the correct foreign key value. $foreignKey = $this->getForeignKeyValue($model); - $values = $this->getUpdateValues($model->getDirty(), $this->localKey . '.$.'); + $values = $this->getUpdateValues($model->getDirty(), $this->localKey.'.$.'); // Update document in database. - $result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey) + $result = $this->getBaseQuery()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey) ->update($values); // Attach the model to its parent. @@ -124,7 +125,7 @@ public function performDelete(Model $model) */ public function associate(Model $model) { - if (!$this->contains($model)) { + if (! $this->contains($model)) { return $this->associateNew($model); } @@ -227,7 +228,7 @@ public function attach(Model $model) protected function associateNew($model) { // Create a new key if needed. - if ($model->getKeyName() === '_id' && !$model->getAttribute('_id')) { + if ($model->getKeyName() === '_id' && ! $model->getAttribute('_id')) { $model->setAttribute('_id', new ObjectID); } @@ -292,7 +293,7 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $perPage, $page, [ - 'path' => Paginator::resolveCurrentPath() + 'path' => Paginator::resolveCurrentPath(), ] ); } @@ -310,7 +311,7 @@ protected function getEmbedded() */ protected function setEmbedded($models) { - if (!is_array($models)) { + if (! is_array($models)) { $models = [$models]; } diff --git a/src/Relations/EmbedsOne.php b/src/Relations/EmbedsOne.php index 43ab96a94..b57a2231a 100644 --- a/src/Relations/EmbedsOne.php +++ b/src/Relations/EmbedsOne.php @@ -38,13 +38,14 @@ public function getEager() public function performInsert(Model $model) { // Generate a new key if needed. - if ($model->getKeyName() == '_id' && !$model->getKey()) { + if ($model->getKeyName() == '_id' && ! $model->getKey()) { $model->setAttribute('_id', new ObjectID); } // For deeply nested documents, let the parent handle the changes. if ($this->isNested()) { $this->associate($model); + return $this->parent->save() ? $model : false; } @@ -71,7 +72,7 @@ public function performUpdate(Model $model) return $this->parent->save(); } - $values = $this->getUpdateValues($model->getDirty(), $this->localKey . '.'); + $values = $this->getUpdateValues($model->getDirty(), $this->localKey.'.'); $result = $this->getBaseQuery()->update($values); @@ -92,6 +93,7 @@ public function performDelete() // For deeply nested documents, let the parent handle the changes. if ($this->isNested()) { $this->dissociate(); + return $this->parent->save(); } diff --git a/src/Relations/EmbedsOneOrMany.php b/src/Relations/EmbedsOneOrMany.php index 5a7f636e7..5e1e9d58b 100644 --- a/src/Relations/EmbedsOneOrMany.php +++ b/src/Relations/EmbedsOneOrMany.php @@ -179,7 +179,7 @@ protected function getIdsArrayFrom($ids) $ids = $ids->all(); } - if (!is_array($ids)) { + if (! is_array($ids)) { $ids = [$ids]; } @@ -331,7 +331,7 @@ protected function isNested() protected function getPathHierarchy($glue = '.') { if ($parentRelation = $this->getParentRelation()) { - return $parentRelation->getPathHierarchy($glue) . $glue . $this->localKey; + return $parentRelation->getPathHierarchy($glue).$glue.$this->localKey; } return $this->localKey; @@ -343,7 +343,7 @@ protected function getPathHierarchy($glue = '.') public function getQualifiedParentKeyName() { if ($parentRelation = $this->getParentRelation()) { - return $parentRelation->getPathHierarchy() . '.' . $this->parent->getKeyName(); + return $parentRelation->getPathHierarchy().'.'.$this->parent->getKeyName(); } return $this->parent->getKeyName(); @@ -359,7 +359,7 @@ protected function getParentKey() } /** - * Return update values + * Return update values. * @param $array * @param string $prepend * @return array @@ -369,7 +369,7 @@ public static function getUpdateValues($array, $prepend = '') $results = []; foreach ($array as $key => $value) { - $results[$prepend . $key] = $value; + $results[$prepend.$key] = $value; } return $results; diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index cc62ec6c1..ad26b4ddb 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -93,6 +93,7 @@ public function dropIndexIfExists($indexOrColumns = null) if ($this->hasIndex($indexOrColumns)) { $this->dropIndex($indexOrColumns); } + return $this; } @@ -114,6 +115,7 @@ public function hasIndex($indexOrColumns = null) return true; } } + return false; } @@ -140,11 +142,12 @@ protected function transformColumns($indexOrColumns) $sorting = $value; } - $transform[$column] = $column . "_" . $sorting; + $transform[$column] = $column.'_'.$sorting; } $indexOrColumns = implode('_', $transform); } + return $indexOrColumns; } diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index dcad10aa9..36aaf9be7 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -3,7 +3,6 @@ namespace Jenssegers\Mongodb\Schema; use Closure; -use Jenssegers\Mongodb\Connection; class Builder extends \Illuminate\Database\Schema\Builder { diff --git a/src/Validation/DatabasePresenceVerifier.php b/src/Validation/DatabasePresenceVerifier.php index 8ed85fd7f..6753db3d9 100644 --- a/src/Validation/DatabasePresenceVerifier.php +++ b/src/Validation/DatabasePresenceVerifier.php @@ -16,7 +16,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe */ public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = []) { - $query = $this->table($collection)->where($column, 'regex', "/" . preg_quote($value) . "/i"); + $query = $this->table($collection)->where($column, 'regex', '/'.preg_quote($value).'/i'); if ($excludeId !== null && $excludeId != 'NULL') { $query->where($idColumn ?: 'id', '<>', $excludeId); @@ -40,7 +40,7 @@ public function getCount($collection, $column, $value, $excludeId = null, $idCol public function getMultiCount($collection, $column, array $values, array $extra = []) { // Generates a regex like '/(a|b|c)/i' which can query multiple values - $regex = '/(' . implode('|', $values) . ')/i'; + $regex = '/('.implode('|', $values).')/i'; $query = $this->table($collection)->where($column, 'regex', $regex); diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 84212b84b..912cc9061 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -29,6 +29,7 @@ public function testRemindOld() { if (Application::VERSION >= '5.2') { $this->expectNotToPerformAssertions(); + return; } diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index 69bebfdf7..81ea989cb 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -1,4 +1,5 @@ assertEquals('mongodb://' . $host . '/custom', (string) $connection->getMongoClient()); + $this->assertEquals('mongodb://'.$host.'/custom', (string) $connection->getMongoClient()); } public function testCustomHostAndPort() @@ -106,7 +107,7 @@ public function testCustomHostAndPort() Config::set('database.connections.mongodb.port', 27000); $connection = DB::connection('mongodb'); - $this->assertEquals("mongodb://db1:27000", (string) $connection->getMongoClient()); + $this->assertEquals('mongodb://db1:27000', (string) $connection->getMongoClient()); } public function testHostWithPorts() diff --git a/tests/DsnTest.php b/tests/DsnTest.php index 2eed354f4..85230f852 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -1,4 +1,5 @@ 'London']); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($address), $address) + ->with('eloquent.saving: '.get_class($address), $address) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.creating: ' . get_class($address), $address) + ->with('eloquent.creating: '.get_class($address), $address) ->andReturn(true); - $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address); - $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: '.get_class($address), $address); $address = $user->addresses()->save($address); $address->unsetEventDispatcher(); @@ -58,17 +59,17 @@ public function testEmbedsManySave() $this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all()); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($address), $address) + ->with('eloquent.saving: '.get_class($address), $address) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.updating: ' . get_class($address), $address) + ->with('eloquent.updating: '.get_class($address), $address) ->andReturn(true); - $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address); - $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.updated: '.get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: '.get_class($address), $address); $address->city = 'New York'; $user->addresses()->save($address); @@ -95,7 +96,7 @@ public function testEmbedsManySave() $this->assertEquals(['London', 'New York', 'Bruxelles'], $user->addresses->pluck('city')->all()); $address = $user->addresses[1]; - $address->city = "Manhattan"; + $address->city = 'Manhattan'; $user->addresses()->save($address); $this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $user->addresses->pluck('city')->all()); @@ -190,7 +191,7 @@ public function testEmbedsManyCreate() public function testEmbedsManyCreateMany() { $user = User::create([]); - list($bruxelles, $paris) = $user->addresses()->createMany([['city' => 'Bruxelles'], ['city' => 'Paris']]); + [$bruxelles, $paris] = $user->addresses()->createMany([['city' => 'Bruxelles'], ['city' => 'Paris']]); $this->assertInstanceOf(Address::class, $bruxelles); $this->assertEquals('Bruxelles', $bruxelles->city); $this->assertEquals(['Bruxelles', 'Paris'], $user->addresses->pluck('city')->all()); @@ -211,14 +212,14 @@ public function testEmbedsManyDestroy() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.deleting: ' . get_class($address), Mockery::type(Address::class)) + ->with('eloquent.deleting: '.get_class($address), Mockery::type(Address::class)) ->andReturn(true); $events->shouldReceive('dispatch') ->once() - ->with('eloquent.deleted: ' . get_class($address), Mockery::type(Address::class)); + ->with('eloquent.deleted: '.get_class($address), Mockery::type(Address::class)); $user->addresses()->destroy($address->_id); $this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all()); @@ -242,7 +243,7 @@ public function testEmbedsManyDestroy() $freshUser = User::find($user->id); $this->assertEquals([], $freshUser->addresses->pluck('city')->all()); - list($london, $bristol, $bruxelles) = $user->addresses()->saveMany([ + [$london, $bristol, $bruxelles] = $user->addresses()->saveMany([ new Address(['city' => 'London']), new Address(['city' => 'Bristol']), new Address(['city' => 'Bruxelles']), @@ -263,14 +264,14 @@ public function testEmbedsManyDelete() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.deleting: ' . get_class($address), Mockery::type(Address::class)) + ->with('eloquent.deleting: '.get_class($address), Mockery::type(Address::class)) ->andReturn(true); $events->shouldReceive('dispatch') ->once() - ->with('eloquent.deleted: ' . get_class($address), Mockery::type(Address::class)); + ->with('eloquent.deleted: '.get_class($address), Mockery::type(Address::class)); $address->delete(); @@ -317,14 +318,14 @@ public function testEmbedsManyCreatingEventReturnsFalse() $address = new Address(['city' => 'London']); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($address), $address) + ->with('eloquent.saving: '.get_class($address), $address) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.creating: ' . get_class($address), $address) + ->with('eloquent.creating: '.get_class($address), $address) ->andReturn(false); $this->assertFalse($user->addresses()->save($address)); @@ -338,10 +339,10 @@ public function testEmbedsManySavingEventReturnsFalse() $address->exists = true; $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($address), $address) + ->with('eloquent.saving: '.get_class($address), $address) ->andReturn(false); $this->assertFalse($user->addresses()->save($address)); @@ -355,14 +356,14 @@ public function testEmbedsManyUpdatingEventReturnsFalse() $user->addresses()->save($address); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($address), $address) + ->with('eloquent.saving: '.get_class($address), $address) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.updating: ' . get_class($address), $address) + ->with('eloquent.updating: '.get_class($address), $address) ->andReturn(false); $address->city = 'Warsaw'; @@ -379,10 +380,10 @@ public function testEmbedsManyDeletingEventReturnsFalse() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($address), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address)) + ->with('eloquent.deleting: '.get_class($address), Mockery::mustBe($address)) ->andReturn(false); $this->assertEquals(0, $user->addresses()->destroy($address)); @@ -516,17 +517,17 @@ public function testEmbedsOne() $father = new User(['name' => 'Mark Doe']); $father->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($father), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($father), $father) + ->with('eloquent.saving: '.get_class($father), $father) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.creating: ' . get_class($father), $father) + ->with('eloquent.creating: '.get_class($father), $father) ->andReturn(true); - $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father); - $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: '.get_class($father), $father); $father = $user->father()->save($father); $father->unsetEventDispatcher(); @@ -542,17 +543,17 @@ public function testEmbedsOne() $this->assertInstanceOf(ObjectId::class, $raw['_id']); $father->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($father), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($father), $father) + ->with('eloquent.saving: '.get_class($father), $father) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.updating: ' . get_class($father), $father) + ->with('eloquent.updating: '.get_class($father), $father) ->andReturn(true); - $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($father), $father); - $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.updated: '.get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: '.get_class($father), $father); $father->name = 'Tom Doe'; $user->father()->save($father); @@ -564,17 +565,17 @@ public function testEmbedsOne() $father = new User(['name' => 'Jim Doe']); $father->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($father), Mockery::any()); $events->shouldReceive('until') ->once() - ->with('eloquent.saving: ' . get_class($father), $father) + ->with('eloquent.saving: '.get_class($father), $father) ->andReturn(true); $events->shouldReceive('until') ->once() - ->with('eloquent.creating: ' . get_class($father), $father) + ->with('eloquent.creating: '.get_class($father), $father) ->andReturn(true); - $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father); - $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: '.get_class($father), $father); $father = $user->father()->save($father); $father->unsetEventDispatcher(); @@ -589,8 +590,8 @@ public function testEmbedsOneAssociate() $father = new User(['name' => 'Mark Doe']); $father->setEventDispatcher($events = Mockery::mock(Dispatcher::class)); - $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); - $events->shouldReceive('until')->times(0)->with('eloquent.saving: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: '.get_class($father), Mockery::any()); + $events->shouldReceive('until')->times(0)->with('eloquent.saving: '.get_class($father), $father); $father = $user->father()->associate($father); $father->unsetEventDispatcher(); diff --git a/tests/GeospatialTest.php b/tests/GeospatialTest.php index 51d44abc7..c86e155af 100644 --- a/tests/GeospatialTest.php +++ b/tests/GeospatialTest.php @@ -1,4 +1,5 @@ assertInstanceOf(MySqlConnection::class, $user->getConnection()); // Mysql User - $user->name = "John Doe"; + $user->name = 'John Doe'; $user->save(); $this->assertIsInt($user->id); @@ -54,7 +55,7 @@ public function testMysqlRelations() // MongoDB User $user = new User; - $user->name = "John Doe"; + $user->name = 'John Doe'; $user->save(); // MongoDB has many @@ -88,7 +89,7 @@ public function testHybridWhereHas() $this->assertInstanceOf(MySqlConnection::class, $otherUser->getConnection()); //MySql User - $user->name = "John Doe"; + $user->name = 'John Doe'; $user->id = 2; $user->save(); // Other user @@ -142,7 +143,7 @@ public function testHybridWith() $this->assertInstanceOf(MySqlConnection::class, $otherUser->getConnection()); //MySql User - $user->name = "John Doe"; + $user->name = 'John Doe'; $user->id = 2; $user->save(); // Other user diff --git a/tests/ModelTest.php b/tests/ModelTest.php index fa799ce0e..75723c1cb 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -1,4 +1,5 @@ insert([ - ['name' => 'John Doe', 'birthday' => new UTCDateTime(Date::parse("1980-01-01 00:00:00")->format('Uv'))], - ['name' => 'Robert Roe', 'birthday' => new UTCDateTime(Date::parse("1982-01-01 00:00:00")->format('Uv'))], - ['name' => 'Mark Moe', 'birthday' => new UTCDateTime(Date::parse("1983-01-01 00:00:00.1")->format('Uv'))], - ['name' => 'Frank White', 'birthday' => new UTCDateTime(Date::parse("1960-01-01 12:12:12.1")->format('Uv'))] + ['name' => 'John Doe', 'birthday' => new UTCDateTime(Date::parse('1980-01-01 00:00:00')->format('Uv'))], + ['name' => 'Robert Roe', 'birthday' => new UTCDateTime(Date::parse('1982-01-01 00:00:00')->format('Uv'))], + ['name' => 'Mark Moe', 'birthday' => new UTCDateTime(Date::parse('1983-01-01 00:00:00.1')->format('Uv'))], + ['name' => 'Frank White', 'birthday' => new UTCDateTime(Date::parse('1960-01-01 12:12:12.1')->format('Uv'))], ]); $user = DB::collection('users') - ->where('birthday', new UTCDateTime(Date::parse("1980-01-01 00:00:00")->format('Uv'))) + ->where('birthday', new UTCDateTime(Date::parse('1980-01-01 00:00:00')->format('Uv'))) ->first(); $this->assertEquals('John Doe', $user['name']); $user = DB::collection('users') - ->where('birthday', new UTCDateTime(Date::parse("1960-01-01 12:12:12.1")->format('Uv'))) + ->where('birthday', new UTCDateTime(Date::parse('1960-01-01 12:12:12.1')->format('Uv'))) ->first(); $this->assertEquals('Frank White', $user['name']); - $user = DB::collection('users')->where('birthday', '=', new DateTime("1980-01-01 00:00:00"))->first(); + $user = DB::collection('users')->where('birthday', '=', new DateTime('1980-01-01 00:00:00'))->first(); $this->assertEquals('John Doe', $user['name']); - $start = new UTCDateTime(1000 * strtotime("1950-01-01 00:00:00")); - $stop = new UTCDateTime(1000 * strtotime("1981-01-01 00:00:00")); + $start = new UTCDateTime(1000 * strtotime('1950-01-01 00:00:00')); + $stop = new UTCDateTime(1000 * strtotime('1981-01-01 00:00:00')); $users = DB::collection('users')->whereBetween('birthday', [$start, $stop])->get(); $this->assertCount(2, $users); @@ -577,25 +578,25 @@ public function testDates() public function testImmutableDates() { DB::collection('users')->insert([ - ['name' => 'John Doe', 'birthday' => new UTCDateTime(Date::parse("1980-01-01 00:00:00")->format('Uv'))], - ['name' => 'Robert Roe', 'birthday' => new UTCDateTime(Date::parse("1982-01-01 00:00:00")->format('Uv'))], + ['name' => 'John Doe', 'birthday' => new UTCDateTime(Date::parse('1980-01-01 00:00:00')->format('Uv'))], + ['name' => 'Robert Roe', 'birthday' => new UTCDateTime(Date::parse('1982-01-01 00:00:00')->format('Uv'))], ]); - $users = DB::collection('users')->where('birthday', '=', new DateTimeImmutable("1980-01-01 00:00:00"))->get(); + $users = DB::collection('users')->where('birthday', '=', new DateTimeImmutable('1980-01-01 00:00:00'))->get(); $this->assertCount(1, $users); - $users = DB::collection('users')->where('birthday', new DateTimeImmutable("1980-01-01 00:00:00"))->get(); + $users = DB::collection('users')->where('birthday', new DateTimeImmutable('1980-01-01 00:00:00'))->get(); $this->assertCount(1, $users); $users = DB::collection('users')->whereIn('birthday', [ - new DateTimeImmutable("1980-01-01 00:00:00"), - new DateTimeImmutable("1982-01-01 00:00:00") + new DateTimeImmutable('1980-01-01 00:00:00'), + new DateTimeImmutable('1982-01-01 00:00:00'), ])->get(); $this->assertCount(2, $users); $users = DB::collection('users')->whereBetween('birthday', [ - new DateTimeImmutable("1979-01-01 00:00:00"), - new DateTimeImmutable("1983-01-01 00:00:00") + new DateTimeImmutable('1979-01-01 00:00:00'), + new DateTimeImmutable('1983-01-01 00:00:00'), ])->get(); $this->assertCount(2, $users); @@ -658,11 +659,11 @@ public function testOperators() $results = DB::collection('items')->where('tags', 'size', 4)->get(); $this->assertCount(1, $results); - $regex = new Regex(".*doe", "i"); + $regex = new Regex('.*doe', 'i'); $results = DB::collection('users')->where('name', 'regex', $regex)->get(); $this->assertCount(2, $results); - $regex = new Regex(".*doe", "i"); + $regex = new Regex('.*doe', 'i'); $results = DB::collection('users')->where('name', 'regexp', $regex)->get(); $this->assertCount(2, $results); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index c5cc1152e..72a030ff6 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -1,4 +1,5 @@ 'required|unique:users'] ); $this->assertFalse($validator->fails()); - + User::create(['name' => 'Johnny Cash', 'email' => 'johnny.cash+200@gmail.com']); - + $validator = Validator::make( ['email' => 'johnny.cash+200@gmail.com'], ['email' => 'required|unique:users'] ); - $this->assertTrue($validator->fails()); - + $this->assertTrue($validator->fails()); + $validator = Validator::make( ['email' => 'johnny.cash+20@gmail.com'], ['email' => 'required|unique:users'] ); $this->assertFalse($validator->fails()); - + $validator = Validator::make( ['email' => 'johnny.cash+1@gmail.com'], ['email' => 'required|unique:users'] ); - $this->assertFalse($validator->fails()); + $this->assertFalse($validator->fails()); } public function testExists(): void diff --git a/tests/config/database.php b/tests/config/database.php index 556b71d33..5f45066a8 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -23,7 +23,7 @@ 'dsn_mongodb_db' => [ 'driver' => 'mongodb', - 'dsn' => "mongodb://$mongoHost:$mongoPort/" . env('MONGO_DATABASE', 'unittest'), + 'dsn' => "mongodb://$mongoHost:$mongoPort/".env('MONGO_DATABASE', 'unittest'), ], 'mysql' => [ diff --git a/tests/models/Address.php b/tests/models/Address.php index 9d094cfcd..5e12ddbb7 100644 --- a/tests/models/Address.php +++ b/tests/models/Address.php @@ -1,4 +1,5 @@ hasTable('books')) { + if (! $schema->hasTable('books')) { Schema::connection('mysql')->create('books', function (Blueprint $table) { $table->string('title'); $table->string('author_id')->nullable(); diff --git a/tests/models/MysqlRole.php b/tests/models/MysqlRole.php index c721ad8c0..a8a490d76 100644 --- a/tests/models/MysqlRole.php +++ b/tests/models/MysqlRole.php @@ -1,4 +1,5 @@ hasTable('roles')) { + if (! $schema->hasTable('roles')) { Schema::connection('mysql')->create('roles', function (Blueprint $table) { $table->string('type'); $table->string('user_id'); diff --git a/tests/models/MysqlUser.php b/tests/models/MysqlUser.php index 67b1052ee..8c1393fd5 100644 --- a/tests/models/MysqlUser.php +++ b/tests/models/MysqlUser.php @@ -1,4 +1,5 @@ hasTable('users')) { + if (! $schema->hasTable('users')) { Schema::connection('mysql')->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); diff --git a/tests/models/Photo.php b/tests/models/Photo.php index beff63825..8cb800922 100644 --- a/tests/models/Photo.php +++ b/tests/models/Photo.php @@ -1,4 +1,5 @@ Date: Wed, 5 May 2021 10:25:59 +0300 Subject: [PATCH 2/2] Pin php-cs-fixer version --- .github/workflows/build-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 4af343a33..023def9be 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -9,6 +9,8 @@ on: jobs: php-cs-fixer: runs-on: ubuntu-latest + env: + PHP_CS_FIXER_VERSION: v2.18.7 strategy: matrix: php: @@ -21,9 +23,9 @@ jobs: with: php-version: ${{ matrix.php }} extensions: curl,mbstring - tools: php-cs-fixer + tools: php-cs-fixer:${{ env.PHP_CS_FIXER_VERSION }} coverage: none - - name: Run PHP-CS-Fixer Fix + - name: Run PHP-CS-Fixer Fix, version ${{ env.PHP_CS_FIXER_VERSION }} run: php-cs-fixer fix --dry-run --diff --ansi build: