Skip to content

Commit 89bab08

Browse files
committed
Update tests
1 parent 73dc14f commit 89bab08

File tree

60 files changed

+211
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+211
-208
lines changed

src/Config/ConstAdapter.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CraftCms\Cms\Config;
66

77
use Dotenv\Repository\Adapter\AdapterInterface;
8+
use Override;
89
use PhpOption\Option;
910
use PhpOption\Some;
1011

@@ -22,8 +23,8 @@ private function __construct() {}
2223
*
2324
* @return Option<AdapterInterface>
2425
*/
25-
#[\Override]
26-
public static function create()
26+
#[Override]
27+
public static function create(): Option
2728
{
2829
/** @var Option<AdapterInterface> */
2930
return Some::create(new self);
@@ -35,8 +36,8 @@ public static function create()
3536
* @param non-empty-string $name
3637
* @return Option<string>
3738
*/
38-
#[\Override]
39-
public function read(string $name)
39+
#[Override]
40+
public function read(string $name): Option
4041
{
4142
return Option::fromValue(defined($name) ? constant($name) : null);
4243
}
@@ -45,10 +46,9 @@ public function read(string $name)
4546
* Write to an environment variable, if possible.
4647
*
4748
* @param non-empty-string $name
48-
* @return bool
4949
*/
50-
#[\Override]
51-
public function write(string $name, string $value)
50+
#[Override]
51+
public function write(string $name, string $value): bool
5252
{
5353
define($name, $value);
5454

@@ -59,10 +59,9 @@ public function write(string $name, string $value)
5959
* Delete an environment variable, if possible.
6060
*
6161
* @param non-empty-string $name
62-
* @return bool
6362
*/
64-
#[\Override]
65-
public function delete(string $name)
63+
#[Override]
64+
public function delete(string $name): bool
6665
{
6766
return false;
6867
}

src/Database/Migrations/Install.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use CraftCms\Cms\Support\Facades\Sites;
3434
use CraftCms\Cms\Support\Str;
3535
use Illuminate\Database\Schema\Blueprint;
36+
use Illuminate\Support\Facades\Auth;
3637
use Illuminate\Support\Facades\DB;
3738
use Illuminate\Support\Facades\Event;
3839
use Illuminate\Support\Facades\Schema;
@@ -74,6 +75,7 @@ public function up(): void
7475
$this->insertDefaultData();
7576
} catch (Throwable $e) {
7677
$this->components->error("Error inserting default data: {$e->getMessage()}");
78+
$this->getOutput()->info($e->getTraceAsString());
7779
}
7880
});
7981

@@ -1130,8 +1132,8 @@ public function insertDefaultData(): void
11301132
'language' => $this->site->getLanguage(),
11311133
]);
11321134

1133-
if (! Craft::$app->getRequest()->getIsConsoleRequest()) {
1134-
Craft::$app->getUser()->login($user, Cms::config()->userSessionDuration);
1135+
if (! app()->runningInConsole()) {
1136+
Auth::guard('craft')->loginUsingId($user->id);
11351137
}
11361138
});
11371139
}

src/Database/Queries/Concerns/QueriesDraftsAndRevisions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use CraftCms\Cms\Database\Queries\ElementQuery;
99
use CraftCms\Cms\Database\Table;
1010
use CraftCms\Cms\Support\Arr;
11-
use CraftCms\Cms\User\Models\User;
11+
use CraftCms\Cms\User\Elements\User;
1212
use Illuminate\Database\Query\Builder;
1313
use Illuminate\Support\Collection;
1414
use InvalidArgumentException;

src/Utility/Utilities/ClearCaches.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public static function contentHtml(): string
9696
*/
9797
public static function cacheOptions(): array
9898
{
99+
/**
100+
* TODO: Remove this when dependency on app('Craft') is gone.
101+
*/
102+
if (app()->runningUnitTests()) {
103+
return [];
104+
}
105+
99106
$pathService = app('Craft')->getPath();
100107

101108
$options = [

tests/Announcement/AnnouncementsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
});
1414

1515
it('can get announcements for a user', function () {
16-
$user = User::find();
16+
$user = User::find()->one();
1717

1818
$announcement = Announcement::factory()
1919
->unread()
@@ -29,7 +29,7 @@
2929
});
3030

3131
it('can mark announcements as read', function () {
32-
$user = User::first();
32+
$user = User::find()->one();
3333

3434
$announcement = Announcement::factory()
3535
->unread()

tests/Dashboard/DashboardTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
use CraftCms\Cms\Dashboard\Widgets\CraftSupport;
1212
use CraftCms\Cms\Dashboard\Widgets\Feed;
1313
use CraftCms\Cms\Dashboard\Widgets\Widget;
14-
use CraftCms\Cms\User\Models\User;
14+
use CraftCms\Cms\User\Elements\User;
1515
use Illuminate\Support\Facades\Event;
1616

1717
use function Pest\Laravel\actingAs;
1818

1919
beforeEach(function () {
2020
$this->dashboard = app(Dashboard::class);
2121

22-
actingAs(User::first());
22+
actingAs(User::find()->one());
2323

2424
WidgetModel::all()->each->delete();
2525
});

tests/Dashboard/Widgets/CraftSupportTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use CraftCms\Cms\Dashboard\Dashboard;
66
use CraftCms\Cms\Dashboard\Widgets\CraftSupport;
7-
use CraftCms\Cms\User\Models\User;
7+
use CraftCms\Cms\User\Elements\User;
8+
use CraftCms\Cms\User\Models\User as UserModel;
89
use Illuminate\Support\Facades\Session;
910

1011
use function Pest\Laravel\actingAs;
1112

1213
it('can render', function () {
13-
actingAs(User::first());
14+
actingAs(User::find()->one());
1415
Session::start();
1516

1617
$dashboard = app(Dashboard::class);
@@ -20,15 +21,15 @@
2021
});
2122

2223
it('is only selectable by admins', function () {
23-
User::first()->update(['admin' => false]);
24+
UserModel::first()->update(['admin' => false]);
2425

25-
actingAs(User::first());
26+
actingAs(User::find()->one());
2627
Session::start();
2728

2829
expect(CraftSupport::isSelectable())->toBeFalse();
2930

30-
User::first()->update(['admin' => true]);
31-
actingAs(User::first());
31+
UserModel::first()->update(['admin' => true]);
32+
actingAs(User::find()->one());
3233

3334
expect(CraftSupport::isSelectable())->toBeTrue();
3435
});

tests/Dashboard/Widgets/FeedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use CraftCms\Cms\Dashboard\Dashboard;
66
use CraftCms\Cms\Dashboard\Widgets\Feed;
7-
use CraftCms\Cms\User\Models\User;
7+
use CraftCms\Cms\User\Elements\User;
88
use Illuminate\Support\Facades\Session;
99

1010
use function Pest\Laravel\actingAs;
1111

1212
it('can render', function () {
13-
actingAs(User::first());
13+
actingAs(User::find()->one());
1414
Session::start();
1515

1616
$dashboard = app(Dashboard::class);

tests/Dashboard/Widgets/MyDraftsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use CraftCms\Cms\Dashboard\Dashboard;
66
use CraftCms\Cms\Dashboard\Widgets\MyDrafts;
7-
use CraftCms\Cms\User\Models\User;
7+
use CraftCms\Cms\User\Elements\User;
88
use Illuminate\Support\Facades\Session;
99

1010
use function Pest\Laravel\actingAs;
1111

1212
it('can render', function () {
13-
actingAs(User::first());
13+
actingAs(User::find()->one());
1414
Session::start();
1515

1616
$dashboard = app(Dashboard::class);

tests/Dashboard/Widgets/QuickPostTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use CraftCms\Cms\Dashboard\Dashboard;
66
use CraftCms\Cms\Dashboard\Widgets\QuickPost;
7-
use CraftCms\Cms\User\Models\User;
7+
use CraftCms\Cms\User\Elements\User;
88
use Illuminate\Support\Facades\Session;
99

1010
use function Pest\Laravel\actingAs;
1111

1212
it('can render', function () {
13-
actingAs(User::first());
13+
actingAs(User::find()->one());
1414
Session::start();
1515

1616
$dashboard = app(Dashboard::class);

0 commit comments

Comments
 (0)