Skip to content

Commit ca8c74c

Browse files
committed
Fix and re-enable tests for auth
1 parent 315b84e commit ca8c74c

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace Jenssegers\Mongodb\Auth;
22

3-
use DateTime;
4-
use MongoDate;
3+
use Carbon\Carbon;
4+
use MongoDB\BSON\UTCDateTime;
55

66
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository {
77

@@ -14,7 +14,7 @@ class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRe
1414
*/
1515
protected function getPayload($email, $token)
1616
{
17-
return ['email' => $email, 'token' => $token, 'created_at' => new MongoDate];
17+
return ['email' => $email, 'token' => $token, 'created_at' => new UTCDateTime(round(microtime(true) * 1000))];
1818
}
1919

2020
/**
@@ -25,12 +25,10 @@ protected function getPayload($email, $token)
2525
*/
2626
protected function tokenExpired($token)
2727
{
28-
// Convert MongoDate to a date string.
29-
if ($token['created_at'] instanceof MongoDate)
28+
// Convert UTCDateTime to a date string.
29+
if ($token['created_at'] instanceof UTCDateTime)
3030
{
31-
$date = new DateTime;
32-
33-
$date->setTimestamp($token['created_at']->sec);
31+
$date = $token['created_at']->toDateTime();
3432

3533
$token['created_at'] = $date->format('Y-m-d H:i:s');
3634
}

src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ protected function registerTokenRepository()
1919
// interface, and is responsible for the actual storing of auth tokens and
2020
// their e-mail addresses. We will inject this table and hash key to it.
2121
$table = $app['config']['auth.password.table'];
22+
2223
$key = $app['config']['app.key'];
24+
2325
$expire = $app['config']->get('auth.password.expire', 60);
2426

2527
return new DbRepository($connection, $table, $key, $expire);

tests/No.php renamed to tests/AuthTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testRemind()
4343
$reminder = DB::collection('password_resets')->first();
4444
$this->assertEquals('[email protected]', $reminder['email']);
4545
$this->assertNotNull($reminder['token']);
46-
$this->assertInstanceOf('MongoDate', $reminder['created_at']);
46+
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $reminder['created_at']);
4747

4848
$credentials = [
4949
'email' => '[email protected]',

tests/models/MysqlBook.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3-
use \Illuminate\Support\Facades\Schema;
4-
use Jenssegers\Eloquent\Model as Eloquent;
3+
use Illuminate\Support\Facades\Schema;
4+
use Jenssegers\Mongodb\Eloquent\HybridRelations;
55

66
class MysqlBook extends Eloquent {
77

8+
use HybridRelations;
9+
810
protected $connection = 'mysql';
911
protected $table = 'books';
1012
protected static $unguarded = true;
@@ -17,7 +19,6 @@ public function author()
1719

1820
/**
1921
* Check if we need to run the schema.
20-
* @return [type] [description]
2122
*/
2223
public static function executeSchema()
2324
{

tests/models/MysqlRole.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3-
use \Illuminate\Support\Facades\Schema;
4-
use Jenssegers\Eloquent\Model as Eloquent;
3+
use Illuminate\Support\Facades\Schema;
4+
use Jenssegers\Mongodb\Eloquent\HybridRelations;
55

66
class MysqlRole extends Eloquent {
77

8+
use HybridRelations;
9+
810
protected $connection = 'mysql';
911
protected $table = 'roles';
1012
protected static $unguarded = true;
@@ -21,7 +23,6 @@ public function mysqlUser()
2123

2224
/**
2325
* Check if we need to run the schema.
24-
* @return [type] [description]
2526
*/
2627
public static function executeSchema()
2728
{

tests/models/MysqlUser.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3-
use \Illuminate\Support\Facades\Schema;
4-
use Jenssegers\Eloquent\Model as Eloquent;
3+
use Illuminate\Support\Facades\Schema;
4+
use Jenssegers\Mongodb\Eloquent\HybridRelations;
55

66
class MysqlUser extends Eloquent {
77

8+
use HybridRelations;
9+
810
protected $connection = 'mysql';
911
protected $table = 'users';
1012
protected static $unguarded = true;
@@ -21,7 +23,6 @@ public function role()
2123

2224
/**
2325
* Check if we need to run the schema.
24-
* @return [type] [description]
2526
*/
2627
public static function executeSchema()
2728
{

0 commit comments

Comments
 (0)