-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5.2' into acasar-scopes
- Loading branch information
Showing
1 changed file
with
44 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -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... | ||
*/ | ||
|
@@ -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 = []; | ||
} |