Skip to content

Commit bdb15c9

Browse files
Smolevichjenssegers
authored andcommitted
Fix tests (#1724)
*   Update Dockerfile, add for methods setUp and tearDown return type hint in all tests, replace fire on dispatch * Resolve error test with touch * Use COMPOSER_VERSION in Dockerfile * Add alias for composer * Change parent method's names Broken commit in laravel: laravel/framework@2ee1892 * Remove changes in .travis.yml * Remove changes from Dockerfile * Revert changes in docker-compose.yml * Update image with mysql
1 parent 55c1aa1 commit bdb15c9

15 files changed

+72
-47
lines changed

Diff for: docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616

1717
mysql:
1818
container_name: mysql
19-
image: mysql
19+
image: mysql:5.7
2020
environment:
2121
MYSQL_ROOT_PASSWORD:
2222
MYSQL_DATABASE: unittest

Diff for: src/Jenssegers/Mongodb/Eloquent/Builder.php

+25
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ public function raw($expression = null)
177177
return $results;
178178
}
179179

180+
/**
181+
* Add the "updated at" column to an array of values.
182+
* TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e
183+
* wiil be reverted
184+
* Issue in laravel frawework https://github.com/laravel/framework/issues/27791
185+
*
186+
* @param array $values
187+
* @return array
188+
*/
189+
protected function addUpdatedAtColumn(array $values)
190+
{
191+
if (! $this->model->usesTimestamps() ||
192+
is_null($this->model->getUpdatedAtColumn())) {
193+
return $values;
194+
}
195+
196+
$column = $this->model->getUpdatedAtColumn();
197+
$values = array_merge(
198+
[$column => $this->model->freshTimestampString()],
199+
$values
200+
);
201+
202+
return $values;
203+
}
204+
180205
/**
181206
* @return \Illuminate\Database\ConnectionInterface
182207
*/

Diff for: src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function getRelatedConstraintKey($relation)
110110
}
111111

112112
if ($relation instanceof BelongsTo) {
113-
return $relation->getForeignKey();
113+
return $relation->getForeignKeyName();
114114
}
115115

116116
if ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation)) {
@@ -130,7 +130,7 @@ protected function getHasCompareKey($relation)
130130
return $relation->getHasCompareKey();
131131
}
132132

133-
return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKey();
133+
return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKeyName();
134134
}
135135

136136
/**

Diff for: tests/AuthTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
class AuthTest extends TestCase
77
{
8-
public function tearDown()
8+
public function tearDown(): void
99
{
10+
parent::setUp();
1011
User::truncate();
1112
DB::collection('password_reminders')->truncate();
1213
}

Diff for: tests/EmbeddedRelationsTest.php

+29-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class EmbeddedRelationsTest extends TestCase
44
{
5-
public function tearDown()
5+
public function tearDown(): void
66
{
77
Mockery::close();
88

@@ -21,11 +21,11 @@ public function testEmbedsManySave()
2121
$address = new Address(['city' => 'London']);
2222

2323
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
24-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
24+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
2525
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
2626
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true);
27-
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address);
28-
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
27+
$events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address);
28+
$events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
2929

3030
$address = $user->addresses()->save($address);
3131
$address->unsetEventDispatcher();
@@ -47,11 +47,11 @@ public function testEmbedsManySave()
4747
$this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all());
4848

4949
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
50-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
50+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
5151
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
5252
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true);
53-
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address);
54-
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
53+
$events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address);
54+
$events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
5555

5656
$address->city = 'New York';
5757
$user->addresses()->save($address);
@@ -94,16 +94,16 @@ public function testEmbedsManySave()
9494
// $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
9595
// $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
9696
// $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true);
97-
// $events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address);
98-
// $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
97+
// $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address);
98+
// $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
9999

100100
// $address->save();
101101

102102
// $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
103103
// $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
104104
// $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true);
105-
// $events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address);
106-
// $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address);
105+
// $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address);
106+
// $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
107107

108108
// $address->city = 'Paris';
109109
// $address->save();
@@ -213,9 +213,9 @@ public function testEmbedsManyDestroy()
213213
$address = $user->addresses->first();
214214

215215
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
216-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
216+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
217217
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true);
218-
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
218+
$events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
219219

220220
$user->addresses()->destroy($address->_id);
221221
$this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all());
@@ -252,9 +252,9 @@ public function testEmbedsManyDelete()
252252
$address = $user->addresses->first();
253253

254254
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
255-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
255+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
256256
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true);
257-
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
257+
$events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
258258

259259
$address->delete();
260260

@@ -301,7 +301,7 @@ public function testEmbedsManyCreatingEventReturnsFalse()
301301
$address = new Address(['city' => 'London']);
302302

303303
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
304-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
304+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
305305
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
306306
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(false);
307307

@@ -316,7 +316,7 @@ public function testEmbedsManySavingEventReturnsFalse()
316316
$address->exists = true;
317317

318318
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
319-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
319+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
320320
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(false);
321321

322322
$this->assertFalse($user->addresses()->save($address));
@@ -330,7 +330,7 @@ public function testEmbedsManyUpdatingEventReturnsFalse()
330330
$user->addresses()->save($address);
331331

332332
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
333-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
333+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
334334
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
335335
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(false);
336336

@@ -348,7 +348,7 @@ public function testEmbedsManyDeletingEventReturnsFalse()
348348
$address = $user->addresses->first();
349349

350350
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
351-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
351+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any());
352352
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address))->andReturn(false);
353353

354354
$this->assertEquals(0, $user->addresses()->destroy($address));
@@ -452,11 +452,11 @@ public function testEmbedsOne()
452452
$father = new User(['name' => 'Mark Doe']);
453453

454454
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
455-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
455+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
456456
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
457457
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
458-
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
459-
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
458+
$events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father);
459+
$events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father);
460460

461461
$father = $user->father()->save($father);
462462
$father->unsetEventDispatcher();
@@ -472,11 +472,11 @@ public function testEmbedsOne()
472472
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
473473

474474
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
475-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
475+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
476476
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
477477
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($father), $father)->andReturn(true);
478-
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($father), $father);
479-
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
478+
$events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($father), $father);
479+
$events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father);
480480

481481
$father->name = 'Tom Doe';
482482
$user->father()->save($father);
@@ -488,11 +488,11 @@ public function testEmbedsOne()
488488
$father = new User(['name' => 'Jim Doe']);
489489

490490
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
491-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
491+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
492492
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true);
493493
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
494-
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
495-
$events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father);
494+
$events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father);
495+
$events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father);
496496

497497
$father = $user->father()->save($father);
498498
$father->unsetEventDispatcher();
@@ -507,7 +507,7 @@ public function testEmbedsOneAssociate()
507507
$father = new User(['name' => 'Mark Doe']);
508508

509509
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
510-
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
510+
$events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
511511
$events->shouldReceive('until')->times(0)->with('eloquent.saving: ' . get_class($father), $father);
512512

513513
$father = $user->father()->associate($father);

Diff for: tests/GeospatialTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class GeospatialTest extends TestCase
44
{
5-
public function setUp()
5+
public function setUp(): void
66
{
77
parent::setUp();
88

@@ -43,7 +43,7 @@ public function setUp()
4343
]);
4444
}
4545

46-
public function tearDown()
46+
public function tearDown(): void
4747
{
4848
Schema::drop('locations');
4949
}

Diff for: tests/HybridRelationsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class HybridRelationsTest extends TestCase
44
{
5-
public function setUp()
5+
public function setUp(): void
66
{
77
parent::setUp();
88

@@ -11,7 +11,7 @@ public function setUp()
1111
MysqlRole::executeSchema();
1212
}
1313

14-
public function tearDown()
14+
public function tearDown(): void
1515
{
1616
MysqlUser::truncate();
1717
MysqlBook::truncate();

Diff for: tests/ModelTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class ModelTest extends TestCase
1010
{
11-
public function tearDown()
11+
public function tearDown(): void
1212
{
1313
User::truncate();
1414
Soft::truncate();
@@ -262,7 +262,6 @@ public function testTouch()
262262
$user->save();
263263

264264
$old = $user->updated_at;
265-
266265
sleep(1);
267266
$user->touch();
268267
$check = User::find($user->_id);

Diff for: tests/QueryBuilderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class QueryBuilderTest extends TestCase
77
{
8-
public function tearDown()
8+
public function tearDown(): void
99
{
1010
DB::collection('users')->truncate();
1111
DB::collection('items')->truncate();

Diff for: tests/QueryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class QueryTest extends TestCase
44
{
55
protected static $started = false;
66

7-
public function setUp()
7+
public function setUp(): void
88
{
99
parent::setUp();
1010
User::create(['name' => 'John Doe', 'age' => 35, 'title' => 'admin']);
@@ -18,7 +18,7 @@ public function setUp()
1818
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
1919
}
2020

21-
public function tearDown()
21+
public function tearDown(): void
2222
{
2323
User::truncate();
2424
parent::tearDown();

Diff for: tests/QueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class QueueTest extends TestCase
44
{
5-
public function setUp()
5+
public function setUp(): void
66
{
77
parent::setUp();
88

Diff for: tests/RelationsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class RelationsTest extends TestCase
44
{
5-
public function tearDown()
5+
public function tearDown(): void
66
{
77
Mockery::close();
88

Diff for: tests/SchemaTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class SchemaTest extends TestCase
44
{
5-
public function tearDown()
5+
public function tearDown(): void
66
{
77
Schema::drop('newcollection');
88
}

Diff for: tests/SeederTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class SeederTest extends TestCase
44
{
5-
public function tearDown()
5+
public function tearDown(): void
66
{
77
User::truncate();
88
}

Diff for: tests/ValidationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ValidationTest extends TestCase
44
{
5-
public function tearDown()
5+
public function tearDown(): void
66
{
77
User::truncate();
88
}

0 commit comments

Comments
 (0)