Skip to content

Commit 9c027fb

Browse files
authored
Merge branch 'main' into codex/remove-danish-locale-from-taskfactory
2 parents 9d1c490 + edeba92 commit 9c027fb

File tree

5 files changed

+100
-10
lines changed

5 files changed

+100
-10
lines changed

phpunit.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
colors="true"
4+
verbose="true">
5+
<testsuites>
6+
<testsuite name="Package Tests">
7+
<directory suffix="Test.php">./tests</directory>
8+
</testsuite>
9+
</testsuites>
10+
</phpunit>

src/Models/Task.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function scopeOverdue($query): mixed
108108
*/
109109
public function scopeDueToday($query): mixed
110110
{
111-
return $query->where('due_date', now()->format('Y-m-d'));
111+
return $query->whereDate('due_date', '=', now());
112112
}
113113

114114
/**
@@ -117,7 +117,7 @@ public function scopeDueToday($query): mixed
117117
*/
118118
public function scopeDueTomorrow($query): mixed
119119
{
120-
return $query->where('due_date', now()->addDay()->format('Y-m-d'));
120+
return $query->whereDate('due_date', '=', now()->addDay());
121121
}
122122

123123
/**
@@ -126,7 +126,7 @@ public function scopeDueTomorrow($query): mixed
126126
*/
127127
public function scopeDueThisWeek($query): mixed
128128
{
129-
return $query->whereBetween('due_date', [now()->startOfWeek()->format('Y-m-d'), now()->endOfWeek()->format('Y-m-d')]);
129+
return $query->whereBetween('due_date', [now()->startOfWeek(), now()->endOfWeek()]);
130130
}
131131

132132
/**
@@ -135,7 +135,7 @@ public function scopeDueThisWeek($query): mixed
135135
*/
136136
public function scopeDueNextWeek($query): mixed
137137
{
138-
return $query->whereBetween('due_date', [now()->addWeek()->startOfWeek()->format('Y-m-d'), now()->addWeek()->endOfWeek()->format('Y-m-d')]);
138+
return $query->whereBetween('due_date', [now()->addWeek()->startOfWeek(), now()->addWeek()->endOfWeek()]);
139139
}
140140

141141
/**
@@ -144,7 +144,7 @@ public function scopeDueNextWeek($query): mixed
144144
*/
145145
public function scopeDueThisMonth($query): mixed
146146
{
147-
return $query->whereBetween('due_date', [now()->startOfMonth()->format('Y-m-d'), now()->endOfMonth()->format('Y-m-d')]);
147+
return $query->whereBetween('due_date', [now()->startOfMonth(), now()->endOfMonth()]);
148148
}
149149

150150
/**
@@ -153,7 +153,7 @@ public function scopeDueThisMonth($query): mixed
153153
*/
154154
public function scopeDueNextMonth($query): mixed
155155
{
156-
return $query->whereBetween('due_date', [now()->addMonth()->startOfMonth()->format('Y-m-d'), now()->addMonth()->endOfMonth()->format('Y-m-d')]);
156+
return $query->whereBetween('due_date', [now()->addMonth()->startOfMonth(), now()->addMonth()->endOfMonth()]);
157157
}
158158

159159
/**
@@ -162,7 +162,7 @@ public function scopeDueNextMonth($query): mixed
162162
*/
163163
public function scopeDueThisYear($query): mixed
164164
{
165-
return $query->whereBetween('due_date', [now()->startOfYear()->format('Y-m-d'), now()->endOfYear()->format('Y-m-d')]);
165+
return $query->whereBetween('due_date', [now()->startOfYear(), now()->endOfYear()]);
166166
}
167167

168168
/**
@@ -171,7 +171,7 @@ public function scopeDueThisYear($query): mixed
171171
*/
172172
public function scopeDueNextYear($query): mixed
173173
{
174-
return $query->whereBetween('due_date', [now()->addYear()->startOfYear()->format('Y-m-d'), now()->addYear()->endOfYear()->format('Y-m-d')]);
174+
return $query->whereBetween('due_date', [now()->addYear()->startOfYear(), now()->addYear()->endOfYear()]);
175175
}
176176

177177
/**
@@ -252,7 +252,7 @@ public function scopeDueOnOrBetween($query, $from, $to): mixed
252252
*/
253253
public function scopeDueOnOrBeforeToday($query): mixed
254254
{
255-
return $query->where('due_date', '<=', now()->format('Y-m-d'));
255+
return $query->whereDate('due_date', '<=', now());
256256
}
257257

258258
/**
@@ -261,7 +261,7 @@ public function scopeDueOnOrBeforeToday($query): mixed
261261
*/
262262
public function scopeDueOnOrAfterToday($query): mixed
263263
{
264-
return $query->where('due_date', '>=', now()->format('Y-m-d'));
264+
return $query->whereDate('due_date', '>=', now());
265265
}
266266

267267
/**

tests/HasTasksTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Michal78\Tasks\Tests;
4+
5+
use Michal78\Tasks\Models\Task;
6+
7+
class HasTasksTest extends TestCase
8+
{
9+
public function test_model_can_create_and_retrieve_tasks()
10+
{
11+
$user = User::create(['name' => 'Test User']);
12+
13+
$task = $user->addTask(['name' => 'Test Task']);
14+
15+
$this->assertInstanceOf(Task::class, $task);
16+
$this->assertEquals($user->id, $task->owner_id);
17+
$this->assertEquals(User::class, $task->owner_class);
18+
19+
$this->assertCount(1, $user->tasks);
20+
$this->assertTrue($user->tasks->first()->is($task));
21+
$this->assertCount(1, $user->pendingTasks());
22+
}
23+
}

tests/TestCase.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Michal78\Tasks\Tests;
4+
5+
use Orchestra\Testbench\TestCase as Orchestra;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
use Michal78\Tasks\TasksServiceProvider;
9+
10+
abstract class TestCase extends Orchestra
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
Schema::create('users', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('name')->nullable();
19+
$table->timestamps();
20+
});
21+
22+
// run package migrations
23+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
24+
}
25+
26+
protected function getPackageProviders($app)
27+
{
28+
return [
29+
TasksServiceProvider::class,
30+
];
31+
}
32+
33+
protected function getEnvironmentSetUp($app)
34+
{
35+
$app['config']->set('database.default', 'testing');
36+
$app['config']->set('database.connections.testing', [
37+
'driver' => 'sqlite',
38+
'database' => ':memory:',
39+
'prefix' => '',
40+
]);
41+
}
42+
}

tests/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Michal78\Tasks\Tests;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Michal78\Tasks\Traits\HasTasks;
7+
8+
class User extends Model
9+
{
10+
use HasTasks;
11+
12+
protected $table = 'users';
13+
14+
protected $guarded = [];
15+
}

0 commit comments

Comments
 (0)