|
5 | 5 | use Illuminate\Database\Schema\Blueprint;
|
6 | 6 | use Illuminate\Support\Carbon;
|
7 | 7 | use LaracraftTech\LaravelDateScopes\DateRange;
|
| 8 | +use LaracraftTech\LaravelDateScopes\Tests\Models\CustomTransaction; |
8 | 9 | use LaracraftTech\LaravelDateScopes\Tests\Models\Transaction;
|
9 | 10 |
|
10 | 11 | function getCreatedAtValues(): array
|
@@ -183,3 +184,30 @@ function getCreatedAtValues(): array
|
183 | 184 | ->and(Transaction::ofLast12Months(DateRange::INCLUSIVE)->get())->toHaveCount(23)
|
184 | 185 | ->and(Transaction::ofLastQuarters(8, DateRange::INCLUSIVE)->get())->toHaveCount(24);
|
185 | 186 | });
|
| 187 | + |
| 188 | +it('also works with a custom created_at column name', function() { |
| 189 | + Schema::create('custom_transactions', function (Blueprint $blueprint) { |
| 190 | + $blueprint->id(); |
| 191 | + $blueprint->string('col1'); |
| 192 | + $blueprint->integer('col2'); |
| 193 | + $blueprint->timestamp('custom_created_at')->nullable(); |
| 194 | + }); |
| 195 | + |
| 196 | + $start = '2023-03-31 13:15:15'; |
| 197 | + Carbon::setTestNow(Carbon::parse($start)); |
| 198 | + |
| 199 | + $createdAtValues = [ |
| 200 | + ['custom_created_at' => '2023-03-31 13:05:14'], |
| 201 | + ['custom_created_at' => '2022-03-31 13:15:00'], |
| 202 | + ['custom_created_at' => '2013-03-31 13:13:15'] |
| 203 | + ]; |
| 204 | + |
| 205 | + CustomTransaction::factory() |
| 206 | + ->count(count($createdAtValues)) |
| 207 | + ->state(new Sequence(...$createdAtValues)) |
| 208 | + ->create(); |
| 209 | + |
| 210 | + expect(CustomTransaction::ofLast15Minutes()->get())->toHaveCount(1) |
| 211 | + ->and(CustomTransaction::ofLastYear()->get())->toHaveCount(1) |
| 212 | + ->and(CustomTransaction::ofLastDecade()->get())->toHaveCount(1); |
| 213 | +}); |
0 commit comments