Skip to content

Commit

Permalink
♻️ Make tests compatible with latest phpunit version
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Sep 8, 2019
1 parent 7592967 commit cf45ec6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ composer.lock
*.sublime-workspace
*.project
.idea/
.phpunit.result.cache
4 changes: 1 addition & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
stopOnFailure="false">
<testsuites>
<testsuite name="all">
<directory>tests/</directory>
Expand Down
2 changes: 1 addition & 1 deletion tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testCollection()
// public function testDynamic()
// {
// $dbs = DB::connection('mongodb')->listCollections();
// $this->assertInternalType('array', $dbs);
// $this->assertIsArray($dbs);
// }

// public function testMultipleConnections()
Expand Down
14 changes: 7 additions & 7 deletions tests/EmbeddedRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testEmbedsManySave()
$this->assertInstanceOf('DateTime', $address->created_at);
$this->assertInstanceOf('DateTime', $address->updated_at);
$this->assertNotNull($address->_id);
$this->assertInternalType('string', $address->_id);
$this->assertIsString($address->_id);

$raw = $address->getAttributes();
$this->assertInstanceOf(\MongoDB\BSON\ObjectID::class, $raw['_id']);
Expand Down Expand Up @@ -177,7 +177,7 @@ public function testEmbedsManyCreate()
$user = User::create([]);
$address = $user->addresses()->create(['city' => 'Bruxelles']);
$this->assertInstanceOf('Address', $address);
$this->assertInternalType('string', $address->_id);
$this->assertIsString($address->_id);
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());

$raw = $address->getAttributes();
Expand All @@ -188,7 +188,7 @@ public function testEmbedsManyCreate()

$user = User::create([]);
$address = $user->addresses()->create(['_id' => '', 'city' => 'Bruxelles']);
$this->assertInternalType('string', $address->_id);
$this->assertIsString($address->_id);

$raw = $address->getAttributes();
$this->assertInstanceOf(\MongoDB\BSON\ObjectID::class, $raw['_id']);
Expand Down Expand Up @@ -388,14 +388,14 @@ public function testEmbedsManyEagerLoading()
$relations = $user->getRelations();
$this->assertArrayNotHasKey('addresses', $relations);
$this->assertArrayHasKey('addresses', $user->toArray());
$this->assertInternalType('array', $user->toArray()['addresses']);
$this->assertIsArray($user->toArray()['addresses']);

$user = User::with('addresses')->get()->first();
$relations = $user->getRelations();
$this->assertArrayHasKey('addresses', $relations);
$this->assertEquals(2, $relations['addresses']->count());
$this->assertArrayHasKey('addresses', $user->toArray());
$this->assertInternalType('array', $user->toArray()['addresses']);
$this->assertIsArray($user->toArray()['addresses']);
}

public function testEmbedsManyDeleteAll()
Expand Down Expand Up @@ -467,7 +467,7 @@ public function testEmbedsOne()
$this->assertInstanceOf('DateTime', $father->created_at);
$this->assertInstanceOf('DateTime', $father->updated_at);
$this->assertNotNull($father->_id);
$this->assertInternalType('string', $father->_id);
$this->assertIsString($father->_id);

$raw = $father->getAttributes();
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
Expand Down Expand Up @@ -543,7 +543,7 @@ public function testEmbedsManyToArray()

$array = $user->toArray();
$this->assertArrayHasKey('addresses', $array);
$this->assertInternalType('array', $array['addresses']);
$this->assertIsArray($array['addresses']);
}

public function testEmbeddedSave()
Expand Down
10 changes: 5 additions & 5 deletions tests/HybridRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testMysqlRelations()
// Mysql User
$user->name = "John Doe";
$user->save();
$this->assertInternalType('int', $user->id);
$this->assertIsInt($user->id);

// SQL has many
$book = new Book(['title' => 'Game of Thrones']);
Expand Down Expand Up @@ -94,8 +94,8 @@ public function testHybridWhereHas()
$otherUser->id = 3;
$otherUser->save();
// Make sure they are created
$this->assertInternalType('int', $user->id);
$this->assertInternalType('int', $otherUser->id);
$this->assertIsInt($user->id);
$this->assertIsInt($otherUser->id);
// Clear to start
$user->books()->truncate();
$otherUser->books()->truncate();
Expand Down Expand Up @@ -148,8 +148,8 @@ public function testHybridWith()
$otherUser->id = 3;
$otherUser->save();
// Make sure they are created
$this->assertInternalType('int', $user->id);
$this->assertInternalType('int', $otherUser->id);
$this->assertIsInt($user->id);
$this->assertIsInt($otherUser->id);
// Clear to start
Book::truncate();
MysqlBook::truncate();
Expand Down
12 changes: 6 additions & 6 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testInsert(): void
$this->assertEquals(1, User::count());

$this->assertTrue(isset($user->_id));
$this->assertInternalType('string', $user->_id);
$this->assertIsString($user->_id);
$this->assertNotEquals('', (string) $user->_id);
$this->assertNotEquals(0, strlen((string) $user->_id));
$this->assertInstanceOf(Carbon::class, $user->created_at);
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testManualStringId(): void
$this->assertEquals('customId', $user->_id);

$raw = $user->getAttributes();
$this->assertInternalType('string', $raw['_id']);
$this->assertIsString($raw['_id']);
}

public function testManualIntId(): void
Expand All @@ -128,7 +128,7 @@ public function testManualIntId(): void
$this->assertEquals(1, $user->_id);

$raw = $user->getAttributes();
$this->assertInternalType('integer', $raw['_id']);
$this->assertIsInt($raw['_id']);
}

public function testDelete(): void
Expand Down Expand Up @@ -349,9 +349,9 @@ public function testToArray(): void
$keys = array_keys($array);
sort($keys);
$this->assertEquals(['_id', 'created_at', 'name', 'type', 'updated_at'], $keys);
$this->assertInternalType('string', $array['created_at']);
$this->assertInternalType('string', $array['updated_at']);
$this->assertInternalType('string', $array['_id']);
$this->assertIsString($array['created_at']);
$this->assertIsString($array['updated_at']);
$this->assertIsString($array['_id']);
}

public function testUnset(): void
Expand Down
12 changes: 6 additions & 6 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testInsert()

$user = $users[0];
$this->assertEquals('John Doe', $user['name']);
$this->assertInternalType('array', $user['tags']);
$this->assertIsArray($user['tags']);
}

public function testInsertGetId()
Expand All @@ -111,7 +111,7 @@ public function testBatchInsert()

$users = DB::collection('users')->get();
$this->assertCount(2, $users);
$this->assertInternalType('array', $users[0]['tags']);
$this->assertIsArray($users[0]['tags']);
}

public function testFind()
Expand Down Expand Up @@ -247,7 +247,7 @@ public function testPush()
DB::collection('users')->where('_id', $id)->push('tags', 'tag1');

$user = DB::collection('users')->find($id);
$this->assertInternalType('array', $user['tags']);
$this->assertIsArray($user['tags']);
$this->assertCount(1, $user['tags']);
$this->assertEquals('tag1', $user['tags'][0]);

Expand All @@ -269,7 +269,7 @@ public function testPush()
$message = ['from' => 'Jane', 'body' => 'Hi John'];
DB::collection('users')->where('_id', $id)->push('messages', $message);
$user = DB::collection('users')->find($id);
$this->assertInternalType('array', $user['messages']);
$this->assertIsArray($user['messages']);
$this->assertCount(1, $user['messages']);
$this->assertEquals($message, $user['messages'][0]);

Expand Down Expand Up @@ -298,14 +298,14 @@ public function testPull()
DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');

$user = DB::collection('users')->find($id);
$this->assertInternalType('array', $user['tags']);
$this->assertIsArray($user['tags']);
$this->assertCount(3, $user['tags']);
$this->assertEquals('tag4', $user['tags'][2]);

DB::collection('users')->where('_id', $id)->pull('messages', $message1);

$user = DB::collection('users')->find($id);
$this->assertInternalType('array', $user['messages']);
$this->assertIsArray($user['messages']);
$this->assertCount(1, $user['messages']);

// Raw
Expand Down

0 comments on commit cf45ec6

Please sign in to comment.