forked from userfrosting/UserFrosting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
withTrashed
not available when SoftDeletes
is not used
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
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
63 changes: 63 additions & 0 deletions
63
app/sprinkles/account/tests/Integration/FindUniqueTest.php
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* UserFrosting (http://www.userfrosting.com) | ||
* | ||
* @link https://github.com/userfrosting/UserFrosting | ||
* @copyright Copyright (c) 2019 Alexander Weissman | ||
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License) | ||
*/ | ||
|
||
namespace UserFrosting\Sprinkle\Account\Tests\Integration; | ||
|
||
use UserFrosting\Sprinkle\Account\Database\Models\User; | ||
use UserFrosting\Sprinkle\Account\Database\Models\Group; | ||
use UserFrosting\Sprinkle\Account\Tests\withTestUser; | ||
use UserFrosting\Sprinkle\Core\Tests\TestDatabase; | ||
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase; | ||
use UserFrosting\Tests\TestCase; | ||
|
||
/** | ||
* Test for bug with `withTrashed` in `findUnique` not available when `SoftDeletes` trait is not included in a model. | ||
* @see https://chat.userfrosting.com/channel/support?msg=aAYvdwczSvBMzriJ6 | ||
*/ | ||
class FindUniqueTest extends TestCase | ||
{ | ||
use TestDatabase; | ||
use RefreshDatabase; | ||
use withTestUser; | ||
|
||
/** | ||
* Setup the database schema. | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// Setup test database | ||
$this->setupTestDatabase(); | ||
$this->refreshDatabase(); | ||
} | ||
|
||
/** | ||
* User Model does have the soft Delete | ||
*/ | ||
public function testUserFindUnique(): void | ||
{ | ||
$user = $this->createTestUser(); | ||
$resultA = User::findUnique($user->user_name, 'user_name', true); | ||
$resultB = $this->ci->classMapper->staticMethod('user', 'findUnique', $user->user_name, 'user_name'); | ||
$this->assertEquals($resultA, $resultB); | ||
} | ||
|
||
/** | ||
* Group model doesn't have the soft delete | ||
*/ | ||
public function testGroupFindUnique(): void | ||
{ | ||
$group = $this->ci->factory->create(Group::class); | ||
$resultA = Group::findUnique($group->name, 'name', true); | ||
$resultB = $this->ci->classMapper->staticMethod('group', 'findUnique', $group->name, 'name'); | ||
$this->assertEquals($resultA, $resultB); | ||
} | ||
} |
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