generated from red-explosion/laravel-package-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add separate test classes for mixins
- Loading branch information
1 parent
613f3fd
commit 5c0209b
Showing
6 changed files
with
130 additions
and
65 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Workbench\App\Models\Customer; | ||
use Workbench\Database\Factories\CustomerFactory; | ||
|
||
it(description: 'can find a model by its sqid', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
$sqid = $customer->sqid; | ||
|
||
expect(Customer::findBySqid(sqid: $sqid)) | ||
->toBeInstanceOf(Customer::class) | ||
->is($customer)->toBeTrue(); | ||
}); | ||
|
||
it(description: 'can find a model by its sqid from a specific column', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
$sqid = $customer->sqid; | ||
|
||
expect(Customer::findBySqid(sqid: $sqid, columns: ['id'])) | ||
->toBeInstanceOf(Customer::class) | ||
->is($customer)->toBeTrue(); | ||
}); | ||
|
||
it(description: 'returns null if it cannot find a model with the given sqid', closure: function (): void { | ||
expect(Customer::findBySqid(sqid: 'missing-sqid')) | ||
->toBeNull(); | ||
}); |
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Workbench\App\Models\Customer; | ||
use Workbench\Database\Factories\CustomerFactory; | ||
|
||
it(description: 'can find or fail a model by its sqid', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
$sqid = $customer->sqid; | ||
|
||
expect(Customer::findBySqidOrFail(sqid: $sqid)) | ||
->toBeInstanceOf(Customer::class) | ||
->is($customer)->toBeTrue(); | ||
|
||
$this->expectException(ModelNotFoundException::class); | ||
|
||
Customer::findBySqidOrFail(sqid: 'missing-sqid'); | ||
}); | ||
|
||
it(description: 'can find or fail a model by its sqid from a specific column', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
$sqid = $customer->sqid; | ||
|
||
expect(Customer::findBySqidOrFail(sqid: $sqid, columns: ['id'])) | ||
->toBeInstanceOf(Customer::class) | ||
->is($customer)->toBeTrue(); | ||
|
||
$this->expectException(ModelNotFoundException::class); | ||
|
||
Customer::findBySqidOrFail(sqid: 'missing-sqid', columns: ['id']); | ||
}); |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Workbench\App\Models\Customer; | ||
use Workbench\Database\Factories\CustomerFactory; | ||
|
||
it(description: 'can query all models with the given sqids', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
|
||
CustomerFactory::new()->count(count: 10)->create(); | ||
|
||
$customers = Customer::query() | ||
->whereSqidIn(column: 'id', sqids: [$customer->sqid]) | ||
->get(); | ||
|
||
expect($customers) | ||
->toBeInstanceOf(class: Collection::class) | ||
->toHaveCount(count: 1) | ||
->first()->toBeInstanceOf(class: Customer::class) | ||
->first()->is($customer); | ||
}); |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Workbench\App\Models\Customer; | ||
use Workbench\Database\Factories\CustomerFactory; | ||
|
||
it(description: 'can query a model by its sqid', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
|
||
CustomerFactory::new()->count(count: 10)->create(); | ||
|
||
$customers = Customer::query() | ||
->whereSqid(sqid: $customer->sqid) | ||
->get(); | ||
|
||
expect($customers) | ||
->toBeInstanceOf(class: Collection::class) | ||
->toHaveCount(count: 1) | ||
->first()->toBeInstanceOf(class: Customer::class) | ||
->first()->is($customer); | ||
}); |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Workbench\App\Models\Customer; | ||
use Workbench\Database\Factories\CustomerFactory; | ||
|
||
it(description: 'can query all models except the given sqids', closure: function (): void { | ||
$customer = CustomerFactory::new()->create(); | ||
|
||
CustomerFactory::new()->count(count: 10)->create(); | ||
|
||
$customers = Customer::query() | ||
->whereSqidNotIn(column: 'id', sqids: [$customer->sqid]) | ||
->get(); | ||
|
||
expect($customers) | ||
->toBeInstanceOf(class: Collection::class) | ||
->toHaveCount(count: 10) | ||
->pluck('id')->not->toContain($customer->id); | ||
}); |
This file was deleted.
Oops, something went wrong.