Commit f37336a1 authored by Jens Segers's avatar Jens Segers

Fix merge conflict

parents 4fc8f12f 8031c3fc
......@@ -6,3 +6,4 @@ composer.lock
*.sublime-project
*.sublime-workspace
*.project
.idea/
language: php
php:
- 5.4
- 5.5
- 5.6
......
This diff is collapsed.
......@@ -10,14 +10,14 @@
],
"license" : "MIT",
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.2.*",
"illuminate/container": "4.2.*",
"illuminate/database": "4.2.*",
"illuminate/events": "4.2.*"
"php": ">=5.5.0",
"illuminate/support": "5.0.*",
"illuminate/container": "5.0.*",
"illuminate/database": "5.0.*",
"illuminate/events": "5.0.*"
},
"require-dev": {
"orchestra/testbench": "2.2.*",
"orchestra/testbench": "3.0.*",
"mockery/mockery": "*",
"satooshi/php-coveralls": "*"
},
......
......@@ -3,7 +3,7 @@
use DateTime;
use MongoDate;
class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseReminderRepository {
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository {
/**
* Build the record payload for the table.
......@@ -14,36 +14,28 @@ class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseRemi
*/
protected function getPayload($email, $token)
{
return array('email' => $email, 'token' => $token, 'created_at' => new MongoDate);
return ['email' => $email, 'token' => $token, 'created_at' => new MongoDate];
}
/**
* Determine if the reminder has expired.
* Determine if the token has expired.
*
* @param object $reminder
* @param array $token
* @return bool
*/
protected function reminderExpired($reminder)
protected function tokenExpired($token)
{
// Convert MongoDate to a date string.
if ($reminder['created_at'] instanceof MongoDate)
if ($token['created_at'] instanceof MongoDate)
{
$date = new DateTime;
$date->setTimestamp($reminder['created_at']->sec);
$date->setTimestamp($token['created_at']->sec);
$reminder['created_at'] = $date->format('Y-m-d H:i:s');
$token['created_at'] = $date->format('Y-m-d H:i:s');
}
// Convert DateTime to a date string (backwards compatibility).
elseif (is_array($reminder['created_at']))
{
$date = DateTime::__set_state($reminder['created_at']);
$reminder['created_at'] = $date->format('Y-m-d H:i:s');
}
return parent::reminderExpired($reminder);
return parent::tokenExpired($token);
}
}
<?php namespace Jenssegers\Mongodb\Auth;
use Jenssegers\Mongodb\Auth\DatabaseReminderRepository as DbRepository;
use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
class ReminderServiceProvider extends \Illuminate\Auth\Reminders\ReminderServiceProvider {
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider {
/**
* Register the reminder repository implementation.
* Register the token repository implementation.
*
* @return void
*/
protected function registerReminderRepository()
protected function registerTokenRepository()
{
$this->app->bindShared('auth.reminder.repository', function($app)
$this->app->singleton('auth.password.tokens', function($app)
{
$connection = $app['db']->connection();
// The database reminder repository is an implementation of the reminder repo
// The database token repository is an implementation of the token repository
// interface, and is responsible for the actual storing of auth tokens and
// their e-mail addresses. We will inject this table and hash key to it.
$table = $app['config']['auth.reminder.table'];
$table = $app['config']['auth.password.table'];
$key = $app['config']['app.key'];
$expire = $app['config']->get('auth.reminder.expire', 60);
$expire = $app['config']->get('auth.password.expire', 60);
return new DbRepository($connection, $table, $key, $expire);
});
}
......
<?php namespace Jenssegers\Mongodb\Eloquent;
trait SoftDeletingTrait {
trait SoftDeletes {
use \Illuminate\Database\Eloquent\SoftDeletingTrait;
use \Illuminate\Database\Eloquent\SoftDeletes;
/**
* Get the fully qualified "deleted at" column.
......
......@@ -2,8 +2,8 @@
use MongoId;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
class EmbedsMany extends EmbedsOneOrMany {
......@@ -275,17 +275,19 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
public function paginate($perPage = null, $columns = array('*'))
{
$page = Paginator::resolveCurrentPage();
$perPage = $perPage ?: $this->related->getPerPage();
$paginator = $this->related->getConnection()->getPaginator();
$results = $this->getEmbedded();
$start = ($paginator->getCurrentPage() - 1) * $perPage;
$total = count($results);
$start = ($page - 1) * $perPage;
$sliced = array_slice($results, $start, $perPage);
return $paginator->make($sliced, count($results), $perPage);
return new LengthAwarePaginator($sliced, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath()
]);
}
/**
......
......@@ -383,7 +383,7 @@ abstract class EmbedsOneOrMany extends Relation {
*
* @return string
*/
protected function getQualifiedParentKeyName()
public function getQualifiedParentKeyName()
{
if ($parentRelation = $this->getParentRelation())
{
......
<?php
use Illuminate\Auth\Passwords\PasswordBroker;
class AuthTest extends TestCase {
public function tearDown()
......@@ -23,7 +25,10 @@ class AuthTest extends TestCase {
public function testRemind()
{
$mailer = Mockery::mock('Illuminate\Mail\Mailer');
$this->app->instance('mailer', $mailer);
$tokens = $this->app->make('auth.password.tokens');
$users = $this->app['auth']->driver()->getProvider();
$broker = new PasswordBroker($tokens, $users, $mailer, '');
$user = User::create(array(
'name' => 'John Doe',
......@@ -32,10 +37,10 @@ class AuthTest extends TestCase {
));
$mailer->shouldReceive('send')->once();
Password::remind(array('email' => 'john@doe.com'));
$broker->sendResetLink(array('email' => 'john@doe.com'));
$this->assertEquals(1, DB::collection('password_reminders')->count());
$reminder = DB::collection('password_reminders')->first();
$this->assertEquals(1, DB::collection('password_resets')->count());
$reminder = DB::collection('password_resets')->first();
$this->assertEquals('john@doe.com', $reminder['email']);
$this->assertNotNull($reminder['token']);
$this->assertInstanceOf('MongoDate', $reminder['created_at']);
......@@ -47,49 +52,14 @@ class AuthTest extends TestCase {
'token' => $reminder['token']
);
$response = Password::reset($credentials, function($user, $password)
{
$user->password = Hash::make($password);
$user->save();
});
$this->assertEquals('reminders.reset', $response);
$this->assertEquals(0, DB::collection('password_reminders')->count());
}
public function testDeprecatedRemind()
{
$mailer = Mockery::mock('Illuminate\Mail\Mailer');
$this->app->instance('mailer', $mailer);
$user = User::create(array(
'name' => 'John Doe',
'email' => 'john@doe.com',
'password' => Hash::make('foobar')
));
$mailer->shouldReceive('send')->once();
Password::remind(array('email' => 'john@doe.com'));
DB::collection('password_reminders')->update(array('created_at' => new DateTime));
$reminder = DB::collection('password_reminders')->first();
$this->assertTrue(is_array($reminder['created_at']));
$credentials = array(
'email' => 'john@doe.com',
'password' => 'foobar',
'password_confirmation' => 'foobar',
'token' => $reminder['token']
);
$response = Password::reset($credentials, function($user, $password)
$response = $broker->reset($credentials, function($user, $password)
{
$user->password = Hash::make($password);
$user->password = bcrypt($password);
$user->save();
});
$this->assertEquals('reminders.reset', $response);
$this->assertEquals(0, DB::collection('password_reminders')->count());
$this->assertEquals('passwords.reset', $response);
$this->assertEquals(0, DB::collection('password_resets')->count());
}
}
<?php
class CacheTest extends TestCase {
public function tearDown()
{
User::truncate();
Cache::forget('db.users');
}
public function testCache()
{
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
$users = DB::collection('users')->where('age', '>', 10)->remember(10)->get();
$this->assertEquals(3, count($users));
$users = DB::collection('users')->where('age', '>', 10)->getCached();
$this->assertEquals(3, count($users));
$users = User::where('age', '>', 10)->remember(10, 'db.users')->get();
$this->assertEquals(3, count($users));
$users = Cache::get('db.users');
$this->assertEquals(3, count($users));
}
}
......@@ -64,6 +64,8 @@ class ConnectionTest extends TestCase {
public function testQueryLog()
{
DB::enableQueryLog();
$this->assertEquals(0, count(DB::getQueryLog()));
DB::collection('items')->get();
......
......@@ -746,7 +746,7 @@ class EmbeddedRelationsTest extends TestCase {
$results = $user->addresses()->paginate(2);
$this->assertEquals(2, $results->count());
$this->assertEquals(3, $results->getTotal());
$this->assertEquals(3, $results->total());
}
}
......@@ -24,11 +24,6 @@ class QueryTest extends TestCase {
self::$started = true;
}
public static function tearDownAfterClass()
{
User::truncate();
}
public function testWhere()
{
$users = User::where('age', 35)->get();
......@@ -316,4 +311,14 @@ class QueryTest extends TestCase {
$this->assertNull($results->first()->title);
}
/*
* FIXME: This should be done in tearDownAfterClass, but something doens't work:
* https://travis-ci.org/duxet/laravel-mongodb/jobs/46657530
*/
public function testTruncate()
{
User::truncate();
$this->assertEquals(0, User::count());
}
}
......@@ -5,13 +5,14 @@ class TestCase extends Orchestra\Testbench\TestCase {
/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders()
protected function getPackageProviders($app)
{
return array(
'Jenssegers\Mongodb\MongodbServiceProvider',
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider',
);
}
......@@ -36,7 +37,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
$app['config']->set('database.connections.mysql', $config['connections']['mysql']);
$app['config']->set('database.connections.mongodb', $config['connections']['mongodb']);
// overwrite cache configuration
$app['config']->set('auth.model', 'User');
$app['config']->set('cache.driver', 'array');
}
......
<?php
use Jenssegers\Mongodb\Model as Eloquent;
use Jenssegers\Mongodb\Eloquent\SoftDeletingTrait;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Soft extends Eloquent {
use SoftDeletingTrait;
use SoftDeletes;
protected $collection = 'soft';
protected static $unguarded = true;
......
......@@ -2,14 +2,14 @@
use Jenssegers\Mongodb\Model as Eloquent;
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Eloquent implements UserInterface, RemindableInterface {
class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract {
use UserTrait, RemindableTrait;
use Authenticatable, CanResetPassword;
protected $dates = array('birthday', 'entry.date');
protected static $unguarded = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment