Skip to content

Fix tests #1724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: php
php:
- "7.2"
- "7.1"
- "7.3"

services:
- docker
Expand Down
36 changes: 23 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
ARG COMPOSER_VERSION=1.8
ARG PHP_VERSION=7.2
FROM composer:${COMPOSER_VERSION} as composer-build
FROM php:${PHP_VERSION}-cli-alpine

FROM php:${PHP_VERSION}-cli
RUN apk add --update --no-cache -t .php-build-deps \
autoconf \
libmcrypt=2.5.8-r7 \
git \
make \
g++ \
gcc \
openssl-dev \
libzip-dev; \
pecl install mongodb-1.5.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this fixed version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can't we still use the docker-php-ext-install?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mongodb-1.5.3 latest stable version in https://pecl.php.net/package/mongodb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In original Dockerfile used https://github.com/jenssegers/laravel-mongodb/blob/master/Dockerfile#L10
pecl install mongodb && docker-php-ext-enable mongodb


RUN pecl install xdebug
RUN set -xe; \
if [[ "${PHP_VERSION:0:3}" != "7.3" ]]; then \
pecl install xdebug-2.6.1; \
docker-php-ext-enable xdebug; \
fi;

RUN docker-php-ext-enable mongodb && \
docker-php-ext-install -j$(nproc) pdo pdo_mysql zip

RUN apt-get update && \
apt-get install -y autoconf pkg-config libssl-dev git zlib1g-dev

RUN pecl install mongodb && docker-php-ext-enable mongodb && \
docker-php-ext-install -j$(nproc) pdo pdo_mysql zip && docker-php-ext-enable xdebug

RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer

ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}"
COPY --from=composer-build /usr/bin/composer /usr/local/bin/composer
RUN composer global require "hirak/prestissimo:^0.3"
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"Jenssegers\\Mongodb\\MongodbQueueServiceProvider"
]
}
},
"scripts": {
"run-tests": "vendor/bin/phpunit"
}
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
volumes:
- .:/code
working_dir: /code
command: bash -c "composer install --prefer-source --no-interaction && php ./vendor/bin/phpunit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also revert these changes please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jenssegers, I reverted this changes

command: sh -c "composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable && composer run-tests"
depends_on:
- mysql
- mongodb
Expand Down
25 changes: 25 additions & 0 deletions src/Jenssegers/Mongodb/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ public function raw($expression = null)
return $results;
}

/**
* 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
*
* @param array $values
* @return array
*/
protected function addUpdatedAtColumn(array $values)
{
if (! $this->model->usesTimestamps() ||
is_null($this->model->getUpdatedAtColumn())) {
return $values;
}

$column = $this->model->getUpdatedAtColumn();
$values = array_merge(
[$column => $this->model->freshTimestampString()],
$values
);

return $values;
}

/**
* @return \Illuminate\Database\ConnectionInterface
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

class AuthTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
parent::setUp();
User::truncate();
DB::collection('password_reminders')->truncate();
}
Expand Down
58 changes: 29 additions & 29 deletions tests/EmbeddedRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class EmbeddedRelationsTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Mockery::close();

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address);
$events->shouldReceive('fire')->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();
Expand All @@ -47,11 +47,11 @@ public function testEmbedsManySave()
$this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all());

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address);
$events->shouldReceive('fire')->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);
Expand Down Expand Up @@ -94,16 +94,16 @@ public function testEmbedsManySave()
// $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
// $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('fire')->once()->with('eloquent.created: ' . get_class($address), $address);
// $events->shouldReceive('fire')->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->save();

// $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
// $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('fire')->once()->with('eloquent.updated: ' . get_class($address), $address);
// $events->shouldReceive('fire')->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 = 'Paris';
// $address->save();
Expand Down Expand Up @@ -213,9 +213,9 @@ public function testEmbedsManyDestroy()
$address = $user->addresses->first();

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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'))->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
$events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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'))->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
$events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));

$address->delete();

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(false);

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(false);

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(false);

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

$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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))->andReturn(false);

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

$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
$events->shouldReceive('fire')->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();
Expand All @@ -472,11 +472,11 @@ public function testEmbedsOne()
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);

$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($father), $father);
$events->shouldReceive('fire')->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);
Expand All @@ -488,11 +488,11 @@ public function testEmbedsOne()
$father = new User(['name' => 'Jim Doe']);

$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->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)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true);
$events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father);
$events->shouldReceive('fire')->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();
Expand All @@ -507,7 +507,7 @@ public function testEmbedsOneAssociate()
$father = new User(['name' => 'Mark Doe']);

$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any());
$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);
Expand Down
4 changes: 2 additions & 2 deletions tests/GeospatialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class GeospatialTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -43,7 +43,7 @@ public function setUp()
]);
}

public function tearDown()
public function tearDown(): void
{
Schema::drop('locations');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/HybridRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HybridRelationsTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -11,7 +11,7 @@ public function setUp()
MysqlRole::executeSchema();
}

public function tearDown()
public function tearDown(): void
{
MysqlUser::truncate();
MysqlBook::truncate();
Expand Down
3 changes: 1 addition & 2 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ModelTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
Soft::truncate();
Expand Down Expand Up @@ -262,7 +262,6 @@ public function testTouch()
$user->save();

$old = $user->updated_at;

sleep(1);
$user->touch();
$check = User::find($user->_id);
Expand Down
2 changes: 1 addition & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class QueryBuilderTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
DB::collection('users')->truncate();
DB::collection('items')->truncate();
Expand Down
4 changes: 2 additions & 2 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class QueryTest extends TestCase
{
protected static $started = false;

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

public function tearDown()
public function tearDown(): void
{
User::truncate();
parent::tearDown();
Expand Down
2 changes: 1 addition & 1 deletion tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class QueueTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RelationsTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Mockery::close();

Expand Down
2 changes: 1 addition & 1 deletion tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SchemaTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Schema::drop('newcollection');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SeederTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SeederTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
}
Expand Down
Loading