Skip to content

Commit

Permalink
Merge branch '5.2' into acasar-scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 2, 2015
2 parents 0fca71e + 491fdb0 commit a8e577d
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,47 @@
use Carbon\Carbon;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model as Eloquent;

class DatabaseEloquentSoftDeletesIntegrationTest extends PHPUnit_Framework_TestCase
{
/**
* Bootstrap Eloquent.
*
* @return void
*/
public static function setUpBeforeClass()
public function setUp()
{
Eloquent::setConnectionResolver(
new SoftDeletesDatabaseIntegrationTestConnectionResolver
);
$db = new DB;

Eloquent::setEventDispatcher(
new Illuminate\Events\Dispatcher
);
}
$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
]);

/**
* Tear down Eloquent.
*/
public static function tearDownAfterClass()
{
Eloquent::unsetEventDispatcher();
Eloquent::unsetConnectionResolver();
$db->bootEloquent();
$db->setAsGlobal();

$this->createSchema();
}

/**
* Setup the database schema.
*
* @return void
*/
public function setUp()
public function createSchema()
{
$this->schema()->create('users', function ($table) {
$table->increments('id');
$table->string('email')->unique();
$table->timestamps();
$table->softDeletes();
});

$this->schema()->create('posts', function ($table) {
$table->increments('id');
$table->integer('user_id');
$table->string('title');
$table->timestamps();
$table->softDeletes();
});
}

/**
Expand Down Expand Up @@ -132,6 +131,19 @@ public function testFirstOrNewIgnoresSoftDelete()
$this->assertEquals('[email protected]', $taylor->email);
}

public function testWhereHasWithDeletedRelationship()
{
$this->createUsers();

$abigail = SoftDeletesTestUser::where('email', '[email protected]')->first();
$post = $abigail->posts()->create(['title' => 'First Title']);
$post->delete();

$users = SoftDeletesTestUser::has('posts')->get();

$this->assertEquals(0, count($users));
}

/**
* Helpers...
*/
Expand Down Expand Up @@ -174,31 +186,21 @@ class SoftDeletesTestUser extends Eloquent
protected $dates = ['deleted_at'];
protected $table = 'users';
protected $guarded = [];

public function posts()
{
return $this->hasMany(SoftDeletesTestPost::class, 'user_id');
}
}

/**
* Connection Resolver.
* Eloquent Models...
*/
class SoftDeletesDatabaseIntegrationTestConnectionResolver implements Illuminate\Database\ConnectionResolverInterface
class SoftDeletesTestPost extends Eloquent
{
protected $connection;

public function connection($name = null)
{
if (isset($this->connection)) {
return $this->connection;
}

return $this->connection = new Illuminate\Database\SQLiteConnection(new PDO('sqlite::memory:'));
}

public function getDefaultConnection()
{
return 'default';
}
use SoftDeletes;

public function setDefaultConnection($name)
{
//
}
protected $dates = ['deleted_at'];
protected $table = 'posts';
protected $guarded = [];
}

0 comments on commit a8e577d

Please sign in to comment.