diff --git a/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php b/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php index da6159f9e..515fb60af 100644 --- a/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php +++ b/src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php @@ -27,7 +27,7 @@ protected function tokenExpired($createdAt) $date = $createdAt->toDateTime(); $date->setTimezone(new DateTimeZone(date_default_timezone_get())); $createdAt = $date->format('Y-m-d H:i:s'); - } elseif (is_array($createdAt) and isset($createdAt['date'])) { + } elseif (is_array($createdAt) && isset($createdAt['date'])) { $date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC')); $date->setTimezone(new DateTimeZone(date_default_timezone_get())); $createdAt = $date->format('Y-m-d H:i:s'); diff --git a/src/Jenssegers/Mongodb/Eloquent/Builder.php b/src/Jenssegers/Mongodb/Eloquent/Builder.php index fff1cbdb8..358be6b50 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Builder.php +++ b/src/Jenssegers/Mongodb/Eloquent/Builder.php @@ -188,8 +188,7 @@ public function raw($expression = null) */ protected function addUpdatedAtColumn(array $values) { - if (! $this->model->usesTimestamps() || - is_null($this->model->getUpdatedAtColumn())) { + if (! $this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) { return $values; } diff --git a/src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php b/src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php index 307f5e330..c073e58a1 100644 --- a/src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php +++ b/src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php @@ -22,17 +22,17 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r // If no relation name was given, we will use this debug backtrace to extract // 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 (is_null($relation)) { + if ($relation === null) { list(, $caller) = debug_backtrace(false); $relation = $caller['function']; } - if (is_null($localKey)) { + if ($localKey === null) { $localKey = $relation; } - if (is_null($foreignKey)) { + if ($foreignKey === null) { $foreignKey = Str::snake(class_basename($this)); } @@ -57,17 +57,17 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re // If no relation name was given, we will use this debug backtrace to extract // 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 (is_null($relation)) { + if ($relation === null) { list(, $caller) = debug_backtrace(false); $relation = $caller['function']; } - if (is_null($localKey)) { + if ($localKey === null) { $localKey = $relation; } - if (is_null($foreignKey)) { + if ($foreignKey === null) { $foreignKey = Str::snake(class_basename($this)); } diff --git a/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php b/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php index 34b8b5788..b4af4dfc8 100644 --- a/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php +++ b/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php @@ -133,7 +133,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat // If no relation name was given, we will use this debug backtrace to extract // 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 (is_null($relation)) { + if ($relation === null) { list($current, $caller) = debug_backtrace(false, 2); $relation = $caller['function']; @@ -147,7 +147,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat // If no foreign key was supplied, we can use a backtrace to guess the proper // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. - if (is_null($foreignKey)) { + if ($foreignKey === null) { $foreignKey = Str::snake($relation) . '_id'; } @@ -177,7 +177,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null // If no name is provided, we will use the backtrace to get the function name // 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 (is_null($name)) { + if ($name === null) { list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $name = Str::snake($caller['function']); @@ -188,7 +188,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null // 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 // there are multiple types in the morph and we can't use single queries. - if (is_null($class = $this->$type)) { + if (($class = $this->$type) === null) { return new MorphTo( $this->newQuery(), $this, $id, null, $type, $name ); @@ -197,15 +197,13 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null // If we are not eager loading the relationship we will essentially treat this // as a belongs-to style relationship since morph-to extends that class and // we will pass in the appropriate values so that it behaves as expected. - else { - $class = $this->getActualClassNameForMorph($class); + $class = $this->getActualClassNameForMorph($class); - $instance = new $class; + $instance = new $class; - return new MorphTo( - $instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name - ); - } + return new MorphTo( + $instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name + ); } /** @@ -232,7 +230,7 @@ public function belongsToMany( // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the // title of this relation since that is a great convention to apply. - if (is_null($relation)) { + if ($relation === null) { $relation = $this->guessBelongsToManyRelation(); } @@ -261,7 +259,7 @@ public function belongsToMany( // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names // are transformed to snake case from their default CamelCase also. - if (is_null($collection)) { + if ($collection === null) { $collection = $instance->getTable(); } @@ -303,8 +301,8 @@ public function newEloquentBuilder($query) { if (is_subclass_of($this, \Jenssegers\Mongodb\Eloquent\Model::class)) { return new Builder($query); - } else { - return new EloquentBuilder($query); } + + return new EloquentBuilder($query); } } diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index d5c5b8278..88dfef68a 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -233,7 +233,7 @@ public function getFresh($columns = []) // If no columns have been specified for the select statement, we will set them // here to either the passed columns, or the standard default of retrieving // all of the columns on the table using the "wildcard" column character. - if (is_null($this->columns)) { + if ($this->columns === null) { $this->columns = $columns; } @@ -469,7 +469,7 @@ public function aggregate($function, $columns = []) */ public function exists() { - return !is_null($this->first()); + return $this->first() !== null; } /** @@ -580,7 +580,7 @@ public function insertGetId(array $values, $sequence = null) $result = $this->collection->insertOne($values); if (1 == (int) $result->isAcknowledged()) { - if (is_null($sequence)) { + if ($sequence === null) { $sequence = '_id'; } @@ -652,7 +652,7 @@ public function forPageAfterId($perPage = 15, $lastId = 0, $column = '_id') */ public function pluck($column, $key = null) { - $results = $this->get(is_null($key) ? [$column] : [$column, $key]); + $results = $this->get($key === null ? [$column] : [$column, $key]); // Convert ObjectID's to strings if ($key == '_id') { @@ -674,7 +674,7 @@ public function delete($id = null) // If an ID is passed to the method, we will set the where clause to check // the ID to allow developers to simply and quickly remove a single row // from their database without manually specifying the where clauses. - if (!is_null($id)) { + if ($id !== null) { $this->where('_id', '=', $id); } @@ -730,8 +730,10 @@ public function raw($expression = null) // Execute the closure on the mongodb collection if ($expression instanceof Closure) { return call_user_func($expression, $this->collection); - } // Create an expression for the given value - elseif (!is_null($expression)) { + } + + // Create an expression for the given value + if ($expression !== null) { return new Expression($expression); } @@ -854,7 +856,9 @@ public function convertKey($id) { if (is_string($id) && strlen($id) === 24 && ctype_xdigit($id)) { return new ObjectID($id); - } elseif (is_string($id) && strlen($id) === 16 && preg_match('~[^\x20-\x7E\t\r\n]~', $id) > 0) { + } + + if (is_string($id) && strlen($id) === 16 && preg_match('~[^\x20-\x7E\t\r\n]~', $id) > 0) { return new Binary($id, Binary::TYPE_UUID); } @@ -1009,7 +1013,7 @@ protected function compileWhereBasic(array $where) $regex = '^' . $regex; } if (!Str::endsWith($value, '%')) { - $regex = $regex . '$'; + $regex .= '$'; } $value = new Regex($regex, 'i'); @@ -1121,14 +1125,14 @@ protected function compileWhereBetween(array $where) ], ], ]; - } else { - return [ - $column => [ - '$gte' => $values[0], - '$lte' => $values[1], - ], - ]; } + + return [ + $column => [ + '$gte' => $values[0], + '$lte' => $values[1], + ], + ]; } /** diff --git a/src/Jenssegers/Mongodb/Queue/MongoQueue.php b/src/Jenssegers/Mongodb/Queue/MongoQueue.php index e9cd8da9c..5f08f7071 100644 --- a/src/Jenssegers/Mongodb/Queue/MongoQueue.php +++ b/src/Jenssegers/Mongodb/Queue/MongoQueue.php @@ -39,7 +39,7 @@ public function pop($queue = null) { $queue = $this->getQueue($queue); - if (!is_null($this->retryAfter)) { + if ($this->retryAfter !== null) { $this->releaseJobsThatHaveBeenReservedTooLong($queue); } diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php index 825b0d594..e26658e69 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php @@ -130,9 +130,9 @@ public function associate(Model $model) { if (!$this->contains($model)) { return $this->associateNew($model); - } else { - return $this->associateExisting($model); } + + return $this->associateExisting($model); } /** diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php index 177160bf1..f3bc58b8e 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php @@ -279,7 +279,7 @@ protected function toCollection(array $records = []) */ protected function toModel($attributes = []) { - if (is_null($attributes)) { + if ($attributes === null) { return; } diff --git a/src/Jenssegers/Mongodb/Schema/Blueprint.php b/src/Jenssegers/Mongodb/Schema/Blueprint.php index 0c01c96aa..4b30c87fc 100644 --- a/src/Jenssegers/Mongodb/Schema/Blueprint.php +++ b/src/Jenssegers/Mongodb/Schema/Blueprint.php @@ -243,7 +243,7 @@ public function sparse_and_unique($columns = null, $options = []) */ protected function fluent($columns = null) { - if (is_null($columns)) { + if ($columns === null) { return $this->columns; } elseif (is_string($columns)) { return $this->columns = [$columns]; diff --git a/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php b/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php index 75722a8cc..fa3d68854 100644 --- a/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php +++ b/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php @@ -19,7 +19,7 @@ public function getCount($collection, $column, $value, $excludeId = null, $idCol { $query = $this->table($collection)->where($column, 'regex', "/$value/i"); - if (!is_null($excludeId) && $excludeId != 'NULL') { + if ($excludeId !== null && $excludeId != 'NULL') { $query->where($idColumn ?: 'id', '<>', $excludeId); } diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index f7b37bbac..d38687a54 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -1,4 +1,5 @@ assertInstanceOf('Jenssegers\Mongodb\Connection', $connection); + $this->assertInstanceOf(\Jenssegers\Mongodb\Connection::class, $connection); } public function testReconnect() @@ -23,22 +26,22 @@ public function testReconnect() public function testDb() { $connection = DB::connection('mongodb'); - $this->assertInstanceOf('MongoDB\Database', $connection->getMongoDB()); + $this->assertInstanceOf(\MongoDB\Database::class, $connection->getMongoDB()); $connection = DB::connection('mongodb'); - $this->assertInstanceOf('MongoDB\Client', $connection->getMongoClient()); + $this->assertInstanceOf(\MongoDB\Client::class, $connection->getMongoClient()); } public function testCollection() { $collection = DB::connection('mongodb')->getCollection('unittest'); - $this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection); + $this->assertInstanceOf(Jenssegers\Mongodb\Collection::class, $collection); $collection = DB::connection('mongodb')->collection('unittests'); - $this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection); + $this->assertInstanceOf(Jenssegers\Mongodb\Query\Builder::class, $collection); $collection = DB::connection('mongodb')->table('unittests'); - $this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection); + $this->assertInstanceOf(Jenssegers\Mongodb\Query\Builder::class, $collection); } // public function testDynamic() @@ -87,7 +90,7 @@ public function testQueryLog() public function testSchemaBuilder() { $schema = DB::connection('mongodb')->getSchemaBuilder(); - $this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema); + $this->assertInstanceOf(\Jenssegers\Mongodb\Schema\Builder::class, $schema); } public function testDriverName() diff --git a/tests/DsnTest.php b/tests/DsnTest.php index 08fa0a8aa..2eed354f4 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -1,4 +1,5 @@ 'John Doe']); $address = new Address(['city' => 'London']); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true); @@ -31,7 +32,7 @@ public function testEmbedsManySave() $address->unsetEventDispatcher(); $this->assertNotNull($user->addresses); - $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->addresses); + $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $user->addresses); $this->assertEquals(['London'], $user->addresses->pluck('city')->all()); $this->assertInstanceOf('DateTime', $address->created_at); $this->assertInstanceOf('DateTime', $address->updated_at); @@ -39,14 +40,14 @@ public function testEmbedsManySave() $this->assertInternalType('string', $address->_id); $raw = $address->getAttributes(); - $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); + $this->assertInstanceOf(\MongoDB\BSON\ObjectID::class, $raw['_id']); $address = $user->addresses()->save(new Address(['city' => 'Paris'])); $user = User::find($user->_id); $this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all()); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true); @@ -91,7 +92,7 @@ public function testEmbedsManySave() // $user = User::create(['name' => 'John Doe']); // $address = new Address(['city' => 'London']); - // $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + // $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); // $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address); @@ -99,7 +100,7 @@ public function testEmbedsManySave() // $address->save(); - // $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + // $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); // $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address); @@ -180,7 +181,7 @@ public function testEmbedsManyCreate() $this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all()); $raw = $address->getAttributes(); - $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); + $this->assertInstanceOf(\MongoDB\BSON\ObjectID::class, $raw['_id']); $freshUser = User::find($user->id); $this->assertEquals(['Bruxelles'], $freshUser->addresses->pluck('city')->all()); @@ -190,7 +191,7 @@ public function testEmbedsManyCreate() $this->assertInternalType('string', $address->_id); $raw = $address->getAttributes(); - $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); + $this->assertInstanceOf(\MongoDB\BSON\ObjectID::class, $raw['_id']); } public function testEmbedsManyCreateMany() @@ -212,7 +213,7 @@ public function testEmbedsManyDestroy() $address = $user->addresses->first(); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true); $events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); @@ -251,7 +252,7 @@ public function testEmbedsManyDelete() $address = $user->addresses->first(); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true); $events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); @@ -300,7 +301,7 @@ public function testEmbedsManyCreatingEventReturnsFalse() $user = User::create(['name' => 'John Doe']); $address = new Address(['city' => 'London']); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(false); @@ -315,7 +316,7 @@ public function testEmbedsManySavingEventReturnsFalse() $address = new Address(['city' => 'Paris']); $address->exists = true; - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(false); @@ -329,7 +330,7 @@ public function testEmbedsManyUpdatingEventReturnsFalse() $address = new Address(['city' => 'New York']); $user->addresses()->save($address); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(false); @@ -347,7 +348,7 @@ public function testEmbedsManyDeletingEventReturnsFalse() $address = $user->addresses->first(); - $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address))->andReturn(false); @@ -451,7 +452,7 @@ public function testEmbedsOne() $user = User::create(['name' => 'John Doe']); $father = new User(['name' => 'Mark Doe']); - $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $father->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true); @@ -471,7 +472,7 @@ public function testEmbedsOne() $raw = $father->getAttributes(); $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); - $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $father->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($father), $father)->andReturn(true); @@ -487,7 +488,7 @@ public function testEmbedsOne() $father = new User(['name' => 'Jim Doe']); - $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $father->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class)); $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true); @@ -506,7 +507,7 @@ public function testEmbedsOneAssociate() $user = User::create(['name' => 'John Doe']); $father = new User(['name' => 'Mark Doe']); - $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); + $father->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\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); @@ -534,6 +535,7 @@ public function testEmbedsOneDelete() public function testEmbedsManyToArray() { + /** @var User $user */ $user = User::create(['name' => 'John Doe']); $user->addresses()->save(new Address(['city' => 'New York'])); $user->addresses()->save(new Address(['city' => 'Paris'])); @@ -546,7 +548,9 @@ public function testEmbedsManyToArray() public function testEmbeddedSave() { + /** @var User $user */ $user = User::create(['name' => 'John Doe']); + /** @var \Address $address */ $address = $user->addresses()->create(['city' => 'New York']); $father = $user->father()->create(['name' => 'Mark Doe']); diff --git a/tests/GeospatialTest.php b/tests/GeospatialTest.php index b13ed46af..f1237e582 100644 --- a/tests/GeospatialTest.php +++ b/tests/GeospatialTest.php @@ -1,4 +1,5 @@ assertInstanceOf(Model::class, $user); - $this->assertInstanceOf('Jenssegers\Mongodb\Connection', $user->getConnection()); + $this->assertInstanceOf(\Jenssegers\Mongodb\Connection::class, $user->getConnection()); $this->assertFalse($user->exists); $this->assertEquals('users', $user->getTable()); $this->assertEquals('_id', $user->getKeyName()); } - public function testInsert() + public function testInsert(): void { $user = new User; $user->name = 'John Doe'; @@ -51,7 +53,7 @@ public function testInsert() $this->assertEquals(35, $user->age); } - public function testUpdate() + public function testUpdate(): void { $user = new User; $user->name = 'John Doe'; @@ -62,8 +64,8 @@ public function testUpdate() $raw = $user->getAttributes(); $this->assertInstanceOf(ObjectID::class, $raw['_id']); + /** @var User $check */ $check = User::find($user->_id); - $check->age = 36; $check->save(); @@ -84,7 +86,7 @@ public function testUpdate() $this->assertEquals(20, $check->age); } - public function testManualStringId() + public function testManualStringId(): void { $user = new User; $user->_id = '4af9f23d8ead0e1d32000000'; @@ -113,7 +115,7 @@ public function testManualStringId() $this->assertInternalType('string', $raw['_id']); } - public function testManualIntId() + public function testManualIntId(): void { $user = new User; $user->_id = 1; @@ -129,7 +131,7 @@ public function testManualIntId() $this->assertInternalType('integer', $raw['_id']); } - public function testDelete() + public function testDelete(): void { $user = new User; $user->name = 'John Doe'; @@ -145,7 +147,7 @@ public function testDelete() $this->assertEquals(0, User::count()); } - public function testAll() + public function testAll(): void { $user = new User; $user->name = 'John Doe'; @@ -166,7 +168,7 @@ public function testAll() $this->assertContains('Jane Doe', $all->pluck('name')); } - public function testFind() + public function testFind(): void { $user = new User; $user->name = 'John Doe'; @@ -174,6 +176,7 @@ public function testFind() $user->age = 35; $user->save(); + /** @var User $check */ $check = User::find($user->_id); $this->assertInstanceOf(Model::class, $check); @@ -184,7 +187,7 @@ public function testFind() $this->assertEquals(35, $check->age); } - public function testGet() + public function testGet(): void { User::insert([ ['name' => 'John Doe'], @@ -197,19 +200,20 @@ public function testGet() $this->assertInstanceOf(Model::class, $users[0]); } - public function testFirst() + public function testFirst(): void { User::insert([ ['name' => 'John Doe'], ['name' => 'Jane Doe'], ]); + /** @var User $user */ $user = User::first(); $this->assertInstanceOf(Model::class, $user); $this->assertEquals('John Doe', $user->name); } - public function testNoDocument() + public function testNoDocument(): void { $items = Item::where('name', 'nothing')->get(); $this->assertInstanceOf(Collection::class, $items); @@ -222,25 +226,27 @@ public function testNoDocument() $this->assertNull($item); } - public function testFindOrfail() + public function testFindOrFail(): void { - $this->expectException(Illuminate\Database\Eloquent\ModelNotFoundException::class); - User::findOrfail('51c33d8981fec6813e00000a'); + $this->expectException(ModelNotFoundException::class); + User::findOrFail('51c33d8981fec6813e00000a'); } - public function testCreate() + public function testCreate(): void { + /** @var User $user */ $user = User::create(['name' => 'Jane Poe']); $this->assertInstanceOf(Model::class, $user); $this->assertTrue($user->exists); $this->assertEquals('Jane Poe', $user->name); + /** @var User $check */ $check = User::where('name', 'Jane Poe')->first(); $this->assertEquals($user->_id, $check->_id); } - public function testDestroy() + public function testDestroy(): void { $user = new User; $user->name = 'John Doe'; @@ -253,7 +259,7 @@ public function testDestroy() $this->assertEquals(0, User::count()); } - public function testTouch() + public function testTouch(): void { $user = new User; $user->name = 'John Doe'; @@ -264,18 +270,21 @@ public function testTouch() $old = $user->updated_at; sleep(1); $user->touch(); + + /** @var User $check */ $check = User::find($user->_id); $this->assertNotEquals($old, $check->updated_at); } - public function testSoftDelete() + public function testSoftDelete(): void { Soft::create(['name' => 'John Doe']); Soft::create(['name' => 'Jane Doe']); $this->assertEquals(2, Soft::count()); + /** @var Soft $user */ $user = Soft::where('name', 'John Doe')->first(); $this->assertTrue($user->exists); $this->assertFalse($user->trashed()); @@ -300,7 +309,7 @@ public function testSoftDelete() $this->assertEquals(2, Soft::count()); } - public function testPrimaryKey() + public function testPrimaryKey(): void { $user = new User; $this->assertEquals('_id', $user->getKeyName()); @@ -314,13 +323,14 @@ public function testPrimaryKey() $this->assertEquals('A Game of Thrones', $book->getKey()); + /** @var Book $check */ $check = Book::find('A Game of Thrones'); $this->assertEquals('title', $check->getKeyName()); $this->assertEquals('A Game of Thrones', $check->getKey()); $this->assertEquals('A Game of Thrones', $check->title); } - public function testScope() + public function testScope(): void { Item::insert([ ['name' => 'knife', 'type' => 'sharp'], @@ -331,7 +341,7 @@ public function testScope() $this->assertEquals(1, $sharp->count()); } - public function testToArray() + public function testToArray(): void { $item = Item::create(['name' => 'fork', 'type' => 'sharp']); @@ -344,7 +354,7 @@ public function testToArray() $this->assertInternalType('string', $array['_id']); } - public function testUnset() + public function testUnset(): void { $user1 = User::create(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']); $user2 = User::create(['name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF']); @@ -371,7 +381,7 @@ public function testUnset() $this->assertObjectNotHasAttribute('note2', $user2); } - public function testDates() + public function testDates(): void { $birthday = new DateTime('1980/1/1'); $user = User::create(['name' => 'John Doe', 'birthday' => $birthday]); @@ -398,10 +408,12 @@ public function testDates() $this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp())); // test default date format for json output + /** @var Item $item */ $item = Item::create(['name' => 'sword']); $json = $item->toArray(); $this->assertEquals($item->created_at->format('Y-m-d H:i:s'), $json['created_at']); + /** @var User $user */ $user = User::create(['name' => 'Jane Doe', 'birthday' => time()]); $this->assertInstanceOf(Carbon::class, $user->birthday); @@ -422,8 +434,9 @@ public function testDates() $this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']); } - public function testIdAttribute() + public function testIdAttribute(): void { + /** @var User $user */ $user = User::create(['name' => 'John Doe']); $this->assertEquals($user->id, $user->_id); @@ -431,8 +444,9 @@ public function testIdAttribute() $this->assertNotEquals($user->id, $user->_id); } - public function testPushPull() + public function testPushPull(): void { + /** @var User $user */ $user = User::create(['name' => 'John Doe']); $user->push('tags', 'tag1'); @@ -457,36 +471,36 @@ public function testPushPull() $this->assertEquals([], $user->tags); } - public function testRaw() + public function testRaw(): void { User::create(['name' => 'John Doe', 'age' => 35]); User::create(['name' => 'Jane Doe', 'age' => 35]); User::create(['name' => 'Harry Hoe', 'age' => 15]); - $users = User::raw(function ($collection) { + $users = User::raw(function (\Jenssegers\Mongodb\Collection $collection) { return $collection->find(['age' => 35]); }); $this->assertInstanceOf(Collection::class, $users); $this->assertInstanceOf(Model::class, $users[0]); - $user = User::raw(function ($collection) { + $user = User::raw(function (\Jenssegers\Mongodb\Collection $collection) { return $collection->findOne(['age' => 35]); }); $this->assertInstanceOf(Model::class, $user); - $count = User::raw(function ($collection) { + $count = User::raw(function (\Jenssegers\Mongodb\Collection $collection) { return $collection->count(); }); $this->assertEquals(3, $count); - $result = User::raw(function ($collection) { + $result = User::raw(function (\Jenssegers\Mongodb\Collection $collection) { return $collection->insertOne(['name' => 'Yvonne Yoe', 'age' => 35]); }); $this->assertNotNull($result); } - public function testDotNotation() + public function testDotNotation(): void { $user = User::create([ 'name' => 'John Doe', @@ -508,8 +522,9 @@ public function testDotNotation() $this->assertEquals('Strasbourg', $user['address.city']); } - public function testMultipleLevelDotNotation() + public function testMultipleLevelDotNotation(): void { + /** @var Book $book */ $book = Book::create([ 'title' => 'A Game of Thrones', 'chapters' => [ @@ -524,7 +539,7 @@ public function testMultipleLevelDotNotation() $this->assertEquals('The first chapter', $book['chapters.one.title']); } - public function testGetDirtyDates() + public function testGetDirtyDates(): void { $user = new User(); $user->setRawAttributes(['name' => 'John Doe', 'birthday' => new DateTime('19 august 1989')], true); @@ -534,14 +549,14 @@ public function testGetDirtyDates() $this->assertEmpty($user->getDirty()); } - public function testChunkById() + public function testChunkById(): void { User::create(['name' => 'fork', 'tags' => ['sharp', 'pointy']]); User::create(['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']]); User::create(['name' => 'spoon', 'tags' => ['round', 'bowl']]); $count = 0; - User::chunkById(2, function ($items) use (&$count) { + User::chunkById(2, function (\Illuminate\Database\Eloquent\Collection $items) use (&$count) { $count += count($items); }); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 097ded65b..4b1321684 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -1,5 +1,7 @@ get(); $this->assertCount(3, $users); @@ -46,7 +47,7 @@ public function testWhere() $this->assertCount(6, $users); } - public function testAndWhere() + public function testAndWhere(): void { $users = User::where('age', 35)->where('title', 'admin')->get(); $this->assertCount(2, $users); @@ -55,7 +56,7 @@ public function testAndWhere() $this->assertCount(2, $users); } - public function testLike() + public function testLike(): void { $users = User::where('name', 'like', '%doe')->get(); $this->assertCount(2, $users); @@ -70,7 +71,7 @@ public function testLike() $this->assertCount(1, $users); } - public function testSelect() + public function testSelect(): void { $user = User::where('name', 'John Doe')->select('name')->first(); @@ -96,7 +97,7 @@ public function testSelect() $this->assertNull($user->age); } - public function testOrWhere() + public function testOrWhere(): void { $users = User::where('age', 13)->orWhere('title', 'admin')->get(); $this->assertCount(4, $users); @@ -105,7 +106,7 @@ public function testOrWhere() $this->assertCount(2, $users); } - public function testBetween() + public function testBetween(): void { $users = User::whereBetween('age', [0, 25])->get(); $this->assertCount(2, $users); @@ -118,7 +119,7 @@ public function testBetween() $this->assertCount(6, $users); } - public function testIn() + public function testIn(): void { $users = User::whereIn('age', [13, 23])->get(); $this->assertCount(2, $users); @@ -134,19 +135,19 @@ public function testIn() $this->assertCount(3, $users); } - public function testWhereNull() + public function testWhereNull(): void { $users = User::whereNull('age')->get(); $this->assertCount(1, $users); } - public function testWhereNotNull() + public function testWhereNotNull(): void { $users = User::whereNotNull('age')->get(); $this->assertCount(8, $users); } - public function testOrder() + public function testOrder(): void { $user = User::whereNotNull('age')->orderBy('age', 'asc')->first(); $this->assertEquals(13, $user->age); @@ -167,7 +168,7 @@ public function testOrder() $this->assertEquals(35, $user->age); } - public function testGroupBy() + public function testGroupBy(): void { $users = User::groupBy('title')->get(); $this->assertCount(3, $users); @@ -197,7 +198,7 @@ public function testGroupBy() $this->assertNotNull($users[0]->name); } - public function testCount() + public function testCount(): void { $count = User::where('age', '<>', 35)->count(); $this->assertEquals(6, $count); @@ -207,13 +208,13 @@ public function testCount() $this->assertEquals(6, $count); } - public function testExists() + public function testExists(): void { $this->assertFalse(User::where('age', '>', 37)->exists()); $this->assertTrue(User::where('age', '<', 37)->exists()); } - public function testSubquery() + public function testSubQuery(): void { $users = User::where('title', 'admin')->orWhere(function ($query) { $query->where('name', 'Tommy Toe') @@ -262,7 +263,7 @@ public function testSubquery() $this->assertEquals(5, $users->count()); } - public function testWhereRaw() + public function testWhereRaw(): void { $where = ['age' => ['$gt' => 30, '$lt' => 40]]; $users = User::whereRaw($where)->get(); @@ -276,7 +277,7 @@ public function testWhereRaw() $this->assertCount(6, $users); } - public function testMultipleOr() + public function testMultipleOr(): void { $users = User::where(function ($query) { $query->where('age', 35)->orWhere('age', 33); @@ -297,7 +298,7 @@ public function testMultipleOr() $this->assertCount(2, $users); } - public function testPaginate() + public function testPaginate(): void { $results = User::paginate(2); $this->assertEquals(2, $results->count()); @@ -311,7 +312,7 @@ public function testPaginate() $this->assertEquals(1, $results->currentPage()); } - public function testUpdate() + public function testUpdate(): void { $this->assertEquals(1, User::where(['name' => 'John Doe'])->update(['name' => 'Jim Morrison'])); $this->assertEquals(1, User::where(['name' => 'Jim Morrison'])->count()); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 7502ce6f7..6ff26d35c 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -1,4 +1,5 @@ table(Config::get('queue.failed.table'))->truncate(); } - public function testQueueJobLifeCycle() + public function testQueueJobLifeCycle(): void { $id = Queue::push('test', ['action' => 'QueueJobLifeCycle'], 'test'); $this->assertNotNull($id); @@ -34,7 +35,7 @@ public function testQueueJobLifeCycle() $this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count()); } - public function testQueueJobExpired() + public function testQueueJobExpired(): void { $id = Queue::push('test', ['action' => 'QueueJobExpired'], 'test'); $this->assertNotNull($id); diff --git a/tests/RelationsTest.php b/tests/RelationsTest.php index de3e0f222..decc4f14b 100644 --- a/tests/RelationsTest.php +++ b/tests/RelationsTest.php @@ -1,4 +1,5 @@ 'George R. R. Martin']); Book::create(['title' => 'A Game of Thrones', 'author_id' => $author->_id]); @@ -36,7 +37,7 @@ public function testHasMany() $this->assertCount(3, $items); } - public function testBelongsTo() + public function testBelongsTo(): void { $user = User::create(['name' => 'George R. R. Martin']); Book::create(['title' => 'A Game of Thrones', 'author_id' => $user->_id]); @@ -55,7 +56,7 @@ public function testBelongsTo() $this->assertNull($book->author); } - public function testHasOne() + public function testHasOne(): void { $user = User::create(['name' => 'John Doe']); Role::create(['type' => 'admin', 'user_id' => $user->_id]); @@ -78,7 +79,7 @@ public function testHasOne() $this->assertEquals($user->_id, $role->user_id); } - public function testWithBelongsTo() + public function testWithBelongsTo(): void { $user = User::create(['name' => 'John Doe']); Item::create(['type' => 'knife', 'user_id' => $user->_id]); @@ -95,7 +96,7 @@ public function testWithBelongsTo() $this->assertNull($items[3]->getRelation('user')); } - public function testWithHashMany() + public function testWithHashMany(): void { $user = User::create(['name' => 'John Doe']); Item::create(['type' => 'knife', 'user_id' => $user->_id]); @@ -110,7 +111,7 @@ public function testWithHashMany() $this->assertInstanceOf('Item', $items[0]); } - public function testWithHasOne() + public function testWithHasOne(): void { $user = User::create(['name' => 'John Doe']); Role::create(['type' => 'admin', 'user_id' => $user->_id]); @@ -123,7 +124,7 @@ public function testWithHasOne() $this->assertEquals('admin', $role->type); } - public function testEasyRelation() + public function testEasyRelation(): void { // Has Many $user = User::create(['name' => 'John Doe']); @@ -148,7 +149,7 @@ public function testEasyRelation() $this->assertEquals($user->_id, $role->user_id); } - public function testBelongsToMany() + public function testBelongsToMany(): void { $user = User::create(['name' => 'John Doe']); @@ -222,7 +223,7 @@ public function testBelongsToMany() $this->assertCount(1, $client->users); } - public function testBelongsToManyAttachesExistingModels() + public function testBelongsToManyAttachesExistingModels(): void { $user = User::create(['name' => 'John Doe', 'client_ids' => ['1234523']]); @@ -261,7 +262,7 @@ public function testBelongsToManyAttachesExistingModels() $this->assertStringStartsWith('synced', $user->clients[1]->name); } - public function testBelongsToManySync() + public function testBelongsToManySync(): void { // create test instances $user = User::create(['name' => 'John Doe']); @@ -280,7 +281,7 @@ public function testBelongsToManySync() $this->assertCount(1, $user->clients); } - public function testBelongsToManyAttachArray() + public function testBelongsToManyAttachArray(): void { $user = User::create(['name' => 'John Doe']); $client1 = Client::create(['name' => 'Test 1'])->_id; @@ -291,7 +292,7 @@ public function testBelongsToManyAttachArray() $this->assertCount(2, $user->clients); } - public function testBelongsToManyAttachEloquentCollection() + public function testBelongsToManyAttachEloquentCollection(): void { $user = User::create(['name' => 'John Doe']); $client1 = Client::create(['name' => 'Test 1']); @@ -303,7 +304,7 @@ public function testBelongsToManyAttachEloquentCollection() $this->assertCount(2, $user->clients); } - public function testBelongsToManySyncAlreadyPresent() + public function testBelongsToManySyncAlreadyPresent(): void { $user = User::create(['name' => 'John Doe']); $client1 = Client::create(['name' => 'Test 1'])->_id; @@ -320,7 +321,7 @@ public function testBelongsToManySyncAlreadyPresent() $this->assertCount(1, $user['client_ids']); } - public function testBelongsToManyCustom() + public function testBelongsToManyCustom(): void { $user = User::create(['name' => 'John Doe']); $group = $user->groups()->create(['name' => 'Admins']); @@ -340,7 +341,7 @@ public function testBelongsToManyCustom() $this->assertEquals($user->_id, $group->users()->first()->_id); } - public function testMorph() + public function testMorph(): void { $user = User::create(['name' => 'John Doe']); $client = Client::create(['name' => 'Jane Doe']); @@ -383,7 +384,7 @@ public function testMorph() $this->assertInstanceOf('Client', $photos[1]->imageable); } - public function testHasManyHas() + public function testHasManyHas(): void { $author1 = User::create(['name' => 'George R. R. Martin']); $author1->books()->create(['title' => 'A Game of Thrones', 'rating' => 5]); @@ -433,7 +434,7 @@ public function testHasManyHas() $this->assertCount(1, $authors); } - public function testHasOneHas() + public function testHasOneHas(): void { $user1 = User::create(['name' => 'John Doe']); $user1->role()->create(['title' => 'admin']); @@ -455,7 +456,7 @@ public function testHasOneHas() $this->assertCount(2, $users); } - public function testNestedKeys() + public function testNestedKeys(): void { $client = Client::create([ 'data' => [ @@ -481,7 +482,7 @@ public function testNestedKeys() $this->assertEquals('Paris', $client->addresses->first()->data['city']); } - public function testDoubleSaveOneToMany() + public function testDoubleSaveOneToMany(): void { $author = User::create(['name' => 'George R. R. Martin']); $book = Book::create(['title' => 'A Game of Thrones']); @@ -504,7 +505,7 @@ public function testDoubleSaveOneToMany() $this->assertEquals($author->_id, $book->author_id); } - public function testDoubleSaveManyToMany() + public function testDoubleSaveManyToMany(): void { $user = User::create(['name' => 'John Doe']); $client = Client::create(['name' => 'Admins']); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index b56cc639c..a8fac2f1f 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -1,4 +1,5 @@ assertTrue(Schema::hasCollection('newcollection')); $this->assertTrue(Schema::hasTable('newcollection')); } - public function testCreateWithCallback() + public function testCreateWithCallback(): void { $instance = $this; @@ -26,21 +27,21 @@ public function testCreateWithCallback() $this->assertTrue(Schema::hasCollection('newcollection')); } - public function testCreateWithOptions() + public function testCreateWithOptions(): void { Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]); $this->assertTrue(Schema::hasCollection('newcollection_two')); $this->assertTrue(Schema::hasTable('newcollection_two')); } - public function testDrop() + public function testDrop(): void { Schema::create('newcollection'); Schema::drop('newcollection'); $this->assertFalse(Schema::hasCollection('newcollection')); } - public function testBluePrint() + public function testBluePrint(): void { $instance = $this; @@ -53,7 +54,7 @@ public function testBluePrint() }); } - public function testIndex() + public function testIndex(): void { Schema::collection('newcollection', function ($collection) { $collection->index('mykey1'); @@ -77,7 +78,7 @@ public function testIndex() $this->assertEquals(1, $index['key']['mykey3']); } - public function testPrimary() + public function testPrimary(): void { Schema::collection('newcollection', function ($collection) { $collection->string('mykey', 100)->primary(); @@ -87,7 +88,7 @@ public function testPrimary() $this->assertEquals(1, $index['unique']); } - public function testUnique() + public function testUnique(): void { Schema::collection('newcollection', function ($collection) { $collection->unique('uniquekey'); @@ -97,7 +98,7 @@ public function testUnique() $this->assertEquals(1, $index['unique']); } - public function testDropIndex() + public function testDropIndex(): void { Schema::collection('newcollection', function ($collection) { $collection->unique('uniquekey'); @@ -144,7 +145,7 @@ public function testDropIndex() $this->assertFalse($index); } - public function testBackground() + public function testBackground(): void { Schema::collection('newcollection', function ($collection) { $collection->background('backgroundkey'); @@ -154,7 +155,7 @@ public function testBackground() $this->assertEquals(1, $index['background']); } - public function testSparse() + public function testSparse(): void { Schema::collection('newcollection', function ($collection) { $collection->sparse('sparsekey'); @@ -164,7 +165,7 @@ public function testSparse() $this->assertEquals(1, $index['sparse']); } - public function testExpire() + public function testExpire(): void { Schema::collection('newcollection', function ($collection) { $collection->expire('expirekey', 60); @@ -174,7 +175,7 @@ public function testExpire() $this->assertEquals(60, $index['expireAfterSeconds']); } - public function testSoftDeletes() + public function testSoftDeletes(): void { Schema::collection('newcollection', function ($collection) { $collection->softDeletes(); @@ -188,7 +189,7 @@ public function testSoftDeletes() $this->assertEquals(1, $index['key']['email']); } - public function testFluent() + public function testFluent(): void { Schema::collection('newcollection', function ($collection) { $collection->string('email')->index(); @@ -203,7 +204,7 @@ public function testFluent() $this->assertEquals(1, $index['key']['token']); } - public function testGeospatial() + public function testGeospatial(): void { Schema::collection('newcollection', function ($collection) { $collection->geospatial('point'); @@ -221,7 +222,7 @@ public function testGeospatial() $this->assertEquals('2dsphere', $index['key']['continent']); } - public function testDummies() + public function testDummies(): void { Schema::collection('newcollection', function ($collection) { $collection->boolean('activated')->default(0); @@ -229,7 +230,7 @@ public function testDummies() }); } - public function testSparseUnique() + public function testSparseUnique(): void { Schema::collection('newcollection', function ($collection) { $collection->sparse_and_unique('sparseuniquekey'); @@ -240,7 +241,7 @@ public function testSparseUnique() $this->assertEquals(1, $index['unique']); } - protected function getIndex($collection, $name) + protected function getIndex(string $collection, string $name) { $collection = DB::getCollection($collection); diff --git a/tests/SeederTest.php b/tests/SeederTest.php index 61143e330..d78117799 100644 --- a/tests/SeederTest.php +++ b/tests/SeederTest.php @@ -1,4 +1,5 @@ run(); @@ -16,7 +17,7 @@ public function testSeed() $this->assertTrue($user->seed); } - public function testArtisan() + public function testArtisan(): void { Artisan::call('db:seed'); diff --git a/tests/TestCase.php b/tests/TestCase.php index f4b26be2d..5f9ec7a89 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,4 +1,7 @@ 'John Doe'], @@ -42,7 +43,7 @@ public function testUnique() $this->assertFalse($validator->fails()); } - public function testExists() + public function testExists(): void { $validator = Validator::make( ['name' => 'John Doe'], diff --git a/tests/config/database.php b/tests/config/database.php index 9c22bb05a..a210595fa 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -25,7 +25,7 @@ 'host' => env('MYSQL_HOST', 'mysql'), 'database' => env('MYSQL_DATABASE', 'unittest'), 'username' => env('MYSQL_USERNAME', 'root'), - 'password' => '', + 'password' => env('MYSQL_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', diff --git a/tests/models/Address.php b/tests/models/Address.php index f2f1278e1..9d094cfcd 100644 --- a/tests/models/Address.php +++ b/tests/models/Address.php @@ -1,13 +1,15 @@ embedsMany('Address'); } diff --git a/tests/models/Book.php b/tests/models/Book.php index 1cf8d22cb..27243ebcb 100644 --- a/tests/models/Book.php +++ b/tests/models/Book.php @@ -1,7 +1,16 @@ belongsTo('User', 'author_id'); } - public function mysqlAuthor() + public function mysqlAuthor(): BelongsTo { return $this->belongsTo('MysqlUser', 'author_id'); } diff --git a/tests/models/Client.php b/tests/models/Client.php index b8309deef..dc023e00a 100644 --- a/tests/models/Client.php +++ b/tests/models/Client.php @@ -1,5 +1,9 @@ belongsToMany('User'); } - public function photo() + public function photo(): MorphOne { return $this->morphOne('Photo', 'imageable'); } - public function addresses() + public function addresses(): HasMany { return $this->hasMany('Address', 'data.client_id', 'data.client_id'); } diff --git a/tests/models/Group.php b/tests/models/Group.php index 494836ad9..369f673e8 100644 --- a/tests/models/Group.php +++ b/tests/models/Group.php @@ -1,5 +1,7 @@ belongsToMany('User', 'users', 'groups', 'users', '_id', '_id', 'users'); } diff --git a/tests/models/Item.php b/tests/models/Item.php index ac52226db..1bdc4189e 100644 --- a/tests/models/Item.php +++ b/tests/models/Item.php @@ -1,19 +1,27 @@ belongsTo('User'); } - public function scopeSharp($query) + public function scopeSharp(Builder $query) { return $query->where('type', 'sharp'); } diff --git a/tests/models/Location.php b/tests/models/Location.php index aa5f36a57..3d44d5ea5 100644 --- a/tests/models/Location.php +++ b/tests/models/Location.php @@ -1,4 +1,5 @@ belongsTo('User', 'author_id'); } @@ -20,12 +23,13 @@ public function author() /** * Check if we need to run the schema. */ - public static function executeSchema() + public static function executeSchema(): void { + /** @var \Illuminate\Database\Schema\MySqlBuilder $schema */ $schema = Schema::connection('mysql'); if (!$schema->hasTable('books')) { - Schema::connection('mysql')->create('books', function ($table) { + Schema::connection('mysql')->create('books', function (Blueprint $table) { $table->string('title'); $table->string('author_id')->nullable(); $table->integer('mysql_user_id')->unsigned()->nullable(); diff --git a/tests/models/MysqlRole.php b/tests/models/MysqlRole.php index e7db21d60..c721ad8c0 100644 --- a/tests/models/MysqlRole.php +++ b/tests/models/MysqlRole.php @@ -1,5 +1,8 @@ belongsTo('User'); } - public function mysqlUser() + public function mysqlUser(): BelongsTo { return $this->belongsTo('MysqlUser'); } @@ -26,10 +29,11 @@ public function mysqlUser() */ public static function executeSchema() { + /** @var \Illuminate\Database\Schema\MySqlBuilder $schema */ $schema = Schema::connection('mysql'); if (!$schema->hasTable('roles')) { - Schema::connection('mysql')->create('roles', function ($table) { + Schema::connection('mysql')->create('roles', function (Blueprint $table) { $table->string('type'); $table->string('user_id'); $table->timestamps(); diff --git a/tests/models/MysqlUser.php b/tests/models/MysqlUser.php index ca15c53ff..67b1052ee 100644 --- a/tests/models/MysqlUser.php +++ b/tests/models/MysqlUser.php @@ -1,5 +1,9 @@ hasMany('Book', 'author_id'); } - public function role() + public function role(): HasOne { return $this->hasOne('Role'); } - public function mysqlBooks() + public function mysqlBooks(): HasMany { return $this->hasMany(MysqlBook::class); } @@ -29,12 +33,13 @@ public function mysqlBooks() /** * Check if we need to run the schema. */ - public static function executeSchema() + public static function executeSchema(): void { + /** @var \Illuminate\Database\Schema\MySqlBuilder $schema */ $schema = Schema::connection('mysql'); if (!$schema->hasTable('users')) { - Schema::connection('mysql')->create('users', function ($table) { + Schema::connection('mysql')->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); diff --git a/tests/models/Photo.php b/tests/models/Photo.php index 81a5cc2de..beff63825 100644 --- a/tests/models/Photo.php +++ b/tests/models/Photo.php @@ -1,5 +1,7 @@ morphTo(); } diff --git a/tests/models/Role.php b/tests/models/Role.php index a59ce7e02..1e1dc9eb6 100644 --- a/tests/models/Role.php +++ b/tests/models/Role.php @@ -1,5 +1,7 @@ belongsTo('User'); } - public function mysqlUser() + public function mysqlUser(): BelongsTo { return $this->belongsTo('MysqlUser'); } diff --git a/tests/models/Scoped.php b/tests/models/Scoped.php index 77a55bd55..444549916 100644 --- a/tests/models/Scoped.php +++ b/tests/models/Scoped.php @@ -1,4 +1,5 @@