From 5791c052b41c6b593556adc687076bfbdd13c501 Mon Sep 17 00:00:00 2001 From: driesvints Date: Fri, 15 Mar 2024 10:17:07 +0000 Subject: [PATCH 01/10] Update version to v10.48.3 --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 0b0479bab68f..a35b35c10664 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -40,7 +40,7 @@ class Application extends Container implements ApplicationContract, CachesConfig * * @var string */ - const VERSION = '10.48.2'; + const VERSION = '10.48.3'; /** * The base path for the Laravel installation. From fc7b8f6984c58265d1fe111dafa124f9620db767 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 15 Mar 2024 18:39:46 +0100 Subject: [PATCH 02/10] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a94009a3237..b9c0d153a75f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes for 10.x -## [Unreleased](https://github.com/laravel/framework/compare/v10.48.2...10.x) +## [Unreleased](https://github.com/laravel/framework/compare/v10.48.3...10.x) + +## [v10.48.3](https://github.com/laravel/framework/compare/v10.48.2...v10.48.3) - 2024-03-15 + +- Re-tag version ## [v10.48.2](https://github.com/laravel/framework/compare/v10.48.1...v10.48.2) - 2024-03-12 From 8fc7bd47d62fcfa48eb3369f040addabd39dc946 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Mar 2024 04:04:10 +0800 Subject: [PATCH 03/10] [10.x] Test Improvements (#50642) * Test Improvements Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * Update composer.json --------- Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- tests/Support/SupportCollectionTest.php | 4 ++++ tests/Support/SupportNumberTest.php | 32 +++++++------------------ 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index f4abfd3b3f8d..169bc9942622 100644 --- a/composer.json +++ b/composer.json @@ -105,7 +105,7 @@ "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.5.1", "nyholm/psr7": "^1.2", - "orchestra/testbench-core": "^8.18", + "orchestra/testbench-core": "^8.23.4", "pda/pheanstalk": "^4.0", "phpstan/phpstan": "^1.4.7", "phpunit/phpunit": "^10.0.7", diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 7c8d47a0d4ea..6eb4f372bf44 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -2095,6 +2095,8 @@ public function testSortByAlwaysReturnsAssoc($collection) #[DataProvider('collectionClassProvider')] public function testSortByMany($collection) { + $defaultLocale = setlocale(LC_ALL, 0); + $data = new $collection([['item' => '1'], ['item' => '10'], ['item' => 5], ['item' => 20]]); $expected = $data->pluck('item')->toArray(); @@ -2172,6 +2174,8 @@ public function testSortByMany($collection) sort($expected, SORT_LOCALE_STRING); $data = $data->sortBy(['item'], SORT_LOCALE_STRING); $this->assertEquals($data->pluck('item')->toArray(), $expected); + + setlocale(LC_ALL, $defaultLocale); } /** diff --git a/tests/Support/SupportNumberTest.php b/tests/Support/SupportNumberTest.php index c15dafddf812..e54c03d77d1c 100644 --- a/tests/Support/SupportNumberTest.php +++ b/tests/Support/SupportNumberTest.php @@ -3,14 +3,14 @@ namespace Illuminate\Tests\Support; use Illuminate\Support\Number; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; class SupportNumberTest extends TestCase { + #[RequiresPhpExtension('intl')] public function testFormat() { - $this->needsIntlExtension(); - $this->assertSame('0', Number::format(0)); $this->assertSame('0', Number::format(0.0)); $this->assertSame('0', Number::format(0.00)); @@ -40,10 +40,9 @@ public function testFormat() $this->assertSame('NaN', Number::format(NAN)); } + #[RequiresPhpExtension('intl')] public function testFormatWithDifferentLocale() { - $this->needsIntlExtension(); - $this->assertSame('123,456,789', Number::format(123456789, locale: 'en')); $this->assertSame('123.456.789', Number::format(123456789, locale: 'de')); $this->assertSame('123 456 789', Number::format(123456789, locale: 'fr')); @@ -51,10 +50,9 @@ public function testFormatWithDifferentLocale() $this->assertSame('123 456 789', Number::format(123456789, locale: 'sv')); } + #[RequiresPhpExtension('intl')] public function testFormatWithAppLocale() { - $this->needsIntlExtension(); - $this->assertSame('123,456,789', Number::format(123456789)); Number::useLocale('de'); @@ -70,17 +68,15 @@ public function testSpellout() $this->assertSame('one point two', Number::spell(1.2)); } + #[RequiresPhpExtension('intl')] public function testSpelloutWithLocale() { - $this->needsIntlExtension(); - $this->assertSame('trois', Number::spell(3, 'fr')); } + #[RequiresPhpExtension('intl')] public function testSpelloutWithThreshold() { - $this->needsIntlExtension(); - $this->assertSame('9', Number::spell(9, after: 10)); $this->assertSame('10', Number::spell(10, after: 10)); $this->assertSame('eleven', Number::spell(11, after: 10)); @@ -100,10 +96,9 @@ public function testOrdinal() $this->assertSame('3rd', Number::ordinal(3)); } + #[RequiresPhpExtension('intl')] public function testToPercent() { - $this->needsIntlExtension(); - $this->assertSame('0%', Number::percentage(0, precision: 0)); $this->assertSame('0%', Number::percentage(0)); $this->assertSame('1%', Number::percentage(1)); @@ -124,10 +119,9 @@ public function testToPercent() $this->assertSame('0.1235%', Number::percentage(0.12345, precision: 4)); } + #[RequiresPhpExtension('intl')] public function testToCurrency() { - $this->needsIntlExtension(); - $this->assertSame('$0.00', Number::currency(0)); $this->assertSame('$1.00', Number::currency(1)); $this->assertSame('$10.00', Number::currency(10)); @@ -141,10 +135,9 @@ public function testToCurrency() $this->assertSame('$5.32', Number::currency(5.325)); } + #[RequiresPhpExtension('intl')] public function testToCurrencyWithDifferentLocale() { - $this->needsIntlExtension(); - $this->assertSame('1,00 €', Number::currency(1, 'EUR', 'de')); $this->assertSame('1,00 $', Number::currency(1, 'USD', 'de')); $this->assertSame('1,00 £', Number::currency(1, 'GBP', 'de')); @@ -293,11 +286,4 @@ public function testSummarize() $this->assertSame('-1Q', Number::abbreviate(-1000000000000000)); $this->assertSame('-1KQ', Number::abbreviate(-1000000000000000000)); } - - protected function needsIntlExtension() - { - if (! extension_loaded('intl')) { - $this->markTestSkipped('The intl extension is not installed. Please install the extension to enable '.__CLASS__); - } - } } From 9f26b84c0cd0b3fb1dd7924eaa490e20fe9675c2 Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:09:13 +0100 Subject: [PATCH 04/10] Fix `Collection::concat()` return type (#50669) --- src/Illuminate/Collections/Collection.php | 7 +++++-- src/Illuminate/Collections/Enumerable.php | 7 +++++-- src/Illuminate/Collections/LazyCollection.php | 7 +++++-- types/Support/Collection.php | 1 + types/Support/LazyCollection.php | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 0bbbe189816f..c46fc052f972 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -998,8 +998,11 @@ public function push(...$values) /** * Push all of the given items onto the collection. * - * @param iterable $source - * @return static + * @template TConcatKey of array-key + * @template TConcatValue + * + * @param iterable $source + * @return static */ public function concat($source) { diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index a561488e8a59..918f64758e66 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -789,8 +789,11 @@ public function partition($key, $operator = null, $value = null); /** * Push all of the given items onto the collection. * - * @param iterable $source - * @return static + * @template TConcatKey of array-key + * @template TConcatValue + * + * @param iterable $source + * @return static */ public function concat($source); diff --git a/src/Illuminate/Collections/LazyCollection.php b/src/Illuminate/Collections/LazyCollection.php index a8b7716d35d6..84b22ebf9257 100644 --- a/src/Illuminate/Collections/LazyCollection.php +++ b/src/Illuminate/Collections/LazyCollection.php @@ -991,8 +991,11 @@ public function select($keys) /** * Push all of the given items onto the collection. * - * @param iterable $source - * @return static + * @template TConcatKey of array-key + * @template TConcatValue + * + * @param iterable $source + * @return static */ public function concat($source) { diff --git a/types/Support/Collection.php b/types/Support/Collection.php index 77861041deaf..2e8b4a926386 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -657,6 +657,7 @@ function ($collection, $count) { assertType('Illuminate\Support\Collection', $collection->make([1])->concat([2])); assertType('Illuminate\Support\Collection', $collection->make(['string'])->concat(['string'])); +assertType('Illuminate\Support\Collection', $collection->make([1])->concat(['string'])); assertType('Illuminate\Support\Collection|int', $collection->make([1])->random(2)); assertType('Illuminate\Support\Collection|string', $collection->make(['string'])->random()); diff --git a/types/Support/LazyCollection.php b/types/Support/LazyCollection.php index c9ad444ec154..ef3c5f21578a 100644 --- a/types/Support/LazyCollection.php +++ b/types/Support/LazyCollection.php @@ -547,6 +547,7 @@ assertType('Illuminate\Support\LazyCollection', $collection->make([1])->concat([2])); assertType('Illuminate\Support\LazyCollection', $collection->make(['string'])->concat(['string'])); +assertType('Illuminate\Support\LazyCollection', $collection->make([1])->concat(['string'])); assertType('Illuminate\Support\LazyCollection|int', $collection->make([1])->random(2)); assertType('Illuminate\Support\LazyCollection|string', $collection->make(['string'])->random()); From 3d3063c5d03d6ef69e4a31bac689545127260a69 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:44:47 +0800 Subject: [PATCH 05/10] [10.x] Test Improvements for Mail & Notifications tests (#50690) * [10.x] Test Improvements for Mail & Notifications tests Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- .../Mail/RenderingMailWithLocaleTest.php | 7 +++---- .../Mail/SendingMailWithLocaleTest.php | 7 +++---- .../Mail/SendingMarkdownMailTest.php | 5 ++--- .../Integration/Mail/SendingQueuedMailTest.php | 3 +-- tests/Integration/Mail/SentMessageMailTest.php | 12 +++++++++--- .../SendingMailNotificationsTest.php | 12 ++---------- .../SendingMailableNotificationsTest.php | 17 ++++++++++------- ...gNotificationsViaAnonymousNotifiableTest.php | 2 -- .../SendingNotificationsWithLocaleTest.php | 9 +++------ 9 files changed, 33 insertions(+), 41 deletions(-) diff --git a/tests/Integration/Mail/RenderingMailWithLocaleTest.php b/tests/Integration/Mail/RenderingMailWithLocaleTest.php index 2780d60b5568..b3cd5e995657 100644 --- a/tests/Integration/Mail/RenderingMailWithLocaleTest.php +++ b/tests/Integration/Mail/RenderingMailWithLocaleTest.php @@ -3,18 +3,17 @@ namespace Illuminate\Tests\Integration\Mail; use Illuminate\Mail\Mailable; -use Illuminate\Support\Facades\View; use Orchestra\Testbench\TestCase; class RenderingMailWithLocaleTest extends TestCase { - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app['config']->set('app.locale', 'en'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); - app('translator')->setLoaded([ + $app['translator']->setLoaded([ '*' => [ '*' => [ 'en' => ['nom' => 'name'], diff --git a/tests/Integration/Mail/SendingMailWithLocaleTest.php b/tests/Integration/Mail/SendingMailWithLocaleTest.php index 8b307c058188..06a6dc096e45 100644 --- a/tests/Integration/Mail/SendingMailWithLocaleTest.php +++ b/tests/Integration/Mail/SendingMailWithLocaleTest.php @@ -9,21 +9,20 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\View; use Illuminate\Testing\Assert; use Orchestra\Testbench\TestCase; class SendingMailWithLocaleTest extends TestCase { - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app['config']->set('mail.driver', 'array'); $app['config']->set('app.locale', 'en'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); - app('translator')->setLoaded([ + $app['translator']->setLoaded([ '*' => [ '*' => [ 'en' => ['nom' => 'name'], diff --git a/tests/Integration/Mail/SendingMarkdownMailTest.php b/tests/Integration/Mail/SendingMarkdownMailTest.php index b3e5a561b85d..69bb8bb4d529 100644 --- a/tests/Integration/Mail/SendingMarkdownMailTest.php +++ b/tests/Integration/Mail/SendingMarkdownMailTest.php @@ -7,7 +7,6 @@ use Illuminate\Mail\Mailables\Envelope; use Illuminate\Mail\Markdown; use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\View; use Orchestra\Testbench\TestCase; class SendingMarkdownMailTest extends TestCase @@ -16,8 +15,8 @@ protected function getEnvironmentSetUp($app) { $app['config']->set('mail.driver', 'array'); - View::addNamespace('mail', __DIR__.'/Fixtures'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addNamespace('mail', __DIR__.'/Fixtures') + ->addLocation(__DIR__.'/Fixtures'); } public function testMailIsSent() diff --git a/tests/Integration/Mail/SendingQueuedMailTest.php b/tests/Integration/Mail/SendingQueuedMailTest.php index 6f5cc503ee95..6f982043ce65 100644 --- a/tests/Integration/Mail/SendingQueuedMailTest.php +++ b/tests/Integration/Mail/SendingQueuedMailTest.php @@ -7,7 +7,6 @@ use Illuminate\Queue\Middleware\RateLimited; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Queue; -use Illuminate\Support\Facades\View; use Orchestra\Testbench\TestCase; class SendingQueuedMailTest extends TestCase @@ -16,7 +15,7 @@ protected function getEnvironmentSetUp($app) { $app['config']->set('mail.driver', 'array'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); } public function testMailIsSentWithDefaultLocale() diff --git a/tests/Integration/Mail/SentMessageMailTest.php b/tests/Integration/Mail/SentMessageMailTest.php index af72a6c33159..76350090e3fd 100644 --- a/tests/Integration/Mail/SentMessageMailTest.php +++ b/tests/Integration/Mail/SentMessageMailTest.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Notifications\Events\NotificationSent; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notifiable; @@ -14,15 +15,20 @@ class SentMessageMailTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); + use LazilyRefreshDatabase; + protected function afterRefreshingDatabase() + { Schema::create('sent_message_users', function (Blueprint $table) { $table->increments('id'); }); } + protected function beforeRefreshingDatabase() + { + Schema::dropIfExists('sent_message_users'); + } + public function testDispatchesNotificationSent() { $notificationWasSent = false; diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index 26cf3e4e391b..9b59f4c7c0da 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -14,7 +14,6 @@ use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\View; use Illuminate\Support\Str; use Mockery as m; use Orchestra\Testbench\TestCase; @@ -25,14 +24,7 @@ class SendingMailNotificationsTest extends TestCase public $mailer; public $markdown; - protected function tearDown(): void - { - parent::tearDown(); - - m::close(); - } - - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $this->mailFactory = m::mock(MailFactory::class); $this->mailer = m::mock(Mailer::class); @@ -51,7 +43,7 @@ protected function getEnvironmentSetUp($app) return $this->mailFactory; }); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); } protected function setUp(): void diff --git a/tests/Integration/Notifications/SendingMailableNotificationsTest.php b/tests/Integration/Notifications/SendingMailableNotificationsTest.php index c074e4490974..dcbecf0c4fb1 100644 --- a/tests/Integration/Notifications/SendingMailableNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailableNotificationsTest.php @@ -4,18 +4,18 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\View; use Orchestra\Testbench\TestCase; class SendingMailableNotificationsTest extends TestCase { - public $mailer; + use RefreshDatabase; - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app['config']->set('mail.driver', 'array'); @@ -23,13 +23,11 @@ protected function getEnvironmentSetUp($app) $app['config']->set('mail.markdown.theme', 'blank'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); } - protected function setUp(): void + protected function afterRefreshingDatabase() { - parent::setUp(); - Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); @@ -37,6 +35,11 @@ protected function setUp(): void }); } + protected function beforeRefreshingDatabase() + { + Schema::dropIfExists('users'); + } + public function testMarkdownNotification() { $user = MailableNotificationUser::forceCreate([ diff --git a/tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php b/tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php index 38f7f252bdbf..4ba3ea787a54 100644 --- a/tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php +++ b/tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php @@ -10,8 +10,6 @@ class SendingNotificationsViaAnonymousNotifiableTest extends TestCase { - public $mailer; - public function testMailIsSent() { $notifiable = (new AnonymousNotifiable) diff --git a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php index 9b9862abfa51..95a0f4e39f38 100644 --- a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php +++ b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php @@ -15,23 +15,20 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Notification as NotificationFacade; use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\View; use Illuminate\Testing\Assert; use Orchestra\Testbench\TestCase; class SendingNotificationsWithLocaleTest extends TestCase { - public $mailer; - - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app['config']->set('mail.driver', 'array'); $app['config']->set('app.locale', 'en'); - View::addLocation(__DIR__.'/Fixtures'); + $app['view']->addLocation(__DIR__.'/Fixtures'); - app('translator')->setLoaded([ + $app['translator']->setLoaded([ '*' => [ '*' => [ 'en' => ['hi' => 'hello'], From ebf2a8343384c8b8f7799f6d7f3b8be2d06011d6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:45:06 +0800 Subject: [PATCH 06/10] [10.x] Test Improvements for HTTP tests (#50687) Signed-off-by: Mior Muhammad Zaki --- .../Http/Middleware/HandleCorsTest.php | 26 +++++++------------ .../Integration/Http/ThrottleRequestsTest.php | 14 ++-------- .../Http/ThrottleRequestsWithRedisTest.php | 13 ++-------- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/tests/Integration/Http/Middleware/HandleCorsTest.php b/tests/Integration/Http/Middleware/HandleCorsTest.php index e30eaf8324f3..38ed647a621a 100644 --- a/tests/Integration/Http/Middleware/HandleCorsTest.php +++ b/tests/Integration/Http/Middleware/HandleCorsTest.php @@ -13,23 +13,8 @@ class HandleCorsTest extends TestCase { use ValidatesRequests; - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { - $kernel = $app->make(Kernel::class); - $kernel->prependMiddleware(HandleCors::class); - - $router = $app['router']; - - $this->addWebRoutes($router); - $this->addApiRoutes($router); - - parent::getEnvironmentSetUp($app); - } - - protected function resolveApplicationConfiguration($app) - { - parent::resolveApplicationConfiguration($app); - $app['config']['cors'] = [ 'paths' => ['api/*'], 'supports_credentials' => false, @@ -39,6 +24,15 @@ protected function resolveApplicationConfiguration($app) 'exposed_headers' => [], 'max_age' => 0, ]; + + $kernel = $app->make(Kernel::class); + $kernel->prependMiddleware(HandleCors::class); + } + + protected function defineRoutes($router) + { + $this->addWebRoutes($router); + $this->addApiRoutes($router); } public function testShouldReturnHeaderAssessControlAllowOriginWhenDontHaveHttpOriginOnRequest() diff --git a/tests/Integration/Http/ThrottleRequestsTest.php b/tests/Integration/Http/ThrottleRequestsTest.php index 6ddd2a0ef51e..d3cb97cd3d20 100644 --- a/tests/Integration/Http/ThrottleRequestsTest.php +++ b/tests/Integration/Http/ThrottleRequestsTest.php @@ -9,23 +9,13 @@ use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Route; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; use Throwable; +#[WithConfig('hashing.driver', 'bcrypt')] class ThrottleRequestsTest extends TestCase { - protected function tearDown(): void - { - parent::tearDown(); - - Carbon::setTestNow(null); - } - - public function getEnvironmentSetUp($app) - { - $app['config']->set('hashing', ['driver' => 'bcrypt']); - } - public function testLockOpensImmediatelyAfterDecay() { Carbon::setTestNow(Carbon::create(2018, 1, 1, 0, 0, 0)); diff --git a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php index ef7a98b75401..37f98dc73f33 100644 --- a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php +++ b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php @@ -6,24 +6,15 @@ use Illuminate\Routing\Middleware\ThrottleRequestsWithRedis; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Route; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; use Throwable; +#[WithConfig('hashing.driver', 'bcrypt')] class ThrottleRequestsWithRedisTest extends TestCase { use InteractsWithRedis; - protected function tearDown(): void - { - parent::tearDown(); - Carbon::setTestNow(null); - } - - public function getEnvironmentSetUp($app) - { - $app['config']->set('hashing', ['driver' => 'bcrypt']); - } - public function testLockOpensImmediatelyAfterDecay() { $this->ifRedisAvailable(function () { From f2ec6fa15151844748ef920f57816ff7b41369f0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:45:26 +0800 Subject: [PATCH 07/10] [10.x] Test Improvements for Console tests (#50685) Signed-off-by: Mior Muhammad Zaki --- tests/Integration/Console/CommandEventsTest.php | 5 ++--- tests/Integration/Console/CommandSchedulingTest.php | 5 ++--- tests/Integration/Console/GeneratorCommandTest.php | 5 ++--- tests/Integration/Console/Scheduling/CallbackEventTest.php | 7 ------- tests/Integration/Console/Scheduling/EventPingTest.php | 7 ------- .../Console/Scheduling/SubMinuteSchedulingTest.php | 3 ++- tests/Integration/Cookie/CookieTest.php | 7 ------- 7 files changed, 8 insertions(+), 31 deletions(-) diff --git a/tests/Integration/Console/CommandEventsTest.php b/tests/Integration/Console/CommandEventsTest.php index 167835eb9b7f..cc63e22dc4fc 100644 --- a/tests/Integration/Console/CommandEventsTest.php +++ b/tests/Integration/Console/CommandEventsTest.php @@ -12,6 +12,7 @@ use Illuminate\Support\Str; use Orchestra\Testbench\Foundation\Application as Testbench; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class CommandEventsTest extends TestCase { @@ -48,9 +49,7 @@ protected function setUp(): void parent::setUp(); } - /** - * @dataProvider foregroundCommandEventsProvider - */ + #[DataProvider('foregroundCommandEventsProvider')] public function testCommandEventsReceiveParsedInput($callback) { $this->app[ConsoleKernel::class]->registerCommand(new CommandEventsTestCommand); diff --git a/tests/Integration/Console/CommandSchedulingTest.php b/tests/Integration/Console/CommandSchedulingTest.php index 1e02c3b3d2fa..1a4c918aa5e0 100644 --- a/tests/Integration/Console/CommandSchedulingTest.php +++ b/tests/Integration/Console/CommandSchedulingTest.php @@ -6,6 +6,7 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class CommandSchedulingTest extends TestCase { @@ -62,9 +63,7 @@ protected function tearDown(): void parent::tearDown(); } - /** - * @dataProvider executionProvider - */ + #[DataProvider('executionProvider')] public function testExecutionOrder($background, $expected) { $schedule = $this->app->make(Schedule::class); diff --git a/tests/Integration/Console/GeneratorCommandTest.php b/tests/Integration/Console/GeneratorCommandTest.php index 18889bf5ed3b..cb8ce75a6818 100644 --- a/tests/Integration/Console/GeneratorCommandTest.php +++ b/tests/Integration/Console/GeneratorCommandTest.php @@ -3,12 +3,11 @@ namespace Illuminate\Tests\Integration\Console; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class GeneratorCommandTest extends TestCase { - /** - * @dataProvider reservedNamesDataProvider - */ + #[DataProvider('reservedNamesDataProvider')] public function testItCannotGenerateClassUsingReservedName($given) { $this->artisan('make:command', ['name' => $given]) diff --git a/tests/Integration/Console/Scheduling/CallbackEventTest.php b/tests/Integration/Console/Scheduling/CallbackEventTest.php index f884a6f3b80b..586857bd4151 100644 --- a/tests/Integration/Console/Scheduling/CallbackEventTest.php +++ b/tests/Integration/Console/Scheduling/CallbackEventTest.php @@ -10,13 +10,6 @@ class CallbackEventTest extends TestCase { - protected function tearDown(): void - { - parent::tearDown(); - - m::close(); - } - public function testDefaultResultIsSuccess() { $success = null; diff --git a/tests/Integration/Console/Scheduling/EventPingTest.php b/tests/Integration/Console/Scheduling/EventPingTest.php index 04c4774d3fc2..f5b648cac661 100644 --- a/tests/Integration/Console/Scheduling/EventPingTest.php +++ b/tests/Integration/Console/Scheduling/EventPingTest.php @@ -16,13 +16,6 @@ class EventPingTest extends TestCase { - protected function tearDown(): void - { - parent::tearDown(); - - m::close(); - } - public function testPingRescuesTransferExceptions() { $this->spy(ExceptionHandler::class) diff --git a/tests/Integration/Console/Scheduling/SubMinuteSchedulingTest.php b/tests/Integration/Console/Scheduling/SubMinuteSchedulingTest.php index 05f220576f79..de6f9cb3ae1e 100644 --- a/tests/Integration/Console/Scheduling/SubMinuteSchedulingTest.php +++ b/tests/Integration/Console/Scheduling/SubMinuteSchedulingTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Sleep; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class SubMinuteSchedulingTest extends TestCase { @@ -45,7 +46,7 @@ public function test_it_doesnt_wait_for_sub_minute_events_when_none_are_schedule Sleep::assertNeverSlept(); } - /** @dataProvider frequencyProvider */ + #[DataProvider('frequencyProvider')] public function test_it_runs_sub_minute_callbacks($frequency, $expectedRuns) { $runs = 0; diff --git a/tests/Integration/Cookie/CookieTest.php b/tests/Integration/Cookie/CookieTest.php index 83aa4ab9b9a4..bc5252630376 100644 --- a/tests/Integration/Cookie/CookieTest.php +++ b/tests/Integration/Cookie/CookieTest.php @@ -14,13 +14,6 @@ class CookieTest extends TestCase { - protected function tearDown(): void - { - parent::tearDown(); - - Carbon::setTestNow(null); - } - public function test_cookie_is_sent_back_with_proper_expire_time_when_should_expire_on_close() { $this->app['config']->set('session.expire_on_close', true); From 8a1a5a20c86b20795386e2669c08d0cc3acd1871 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:45:53 +0800 Subject: [PATCH 08/10] [10.x] Test Improvements for Cache tests (#50684) * [10.x] Test Improvements for Cache tests Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * Update MemcachedTaggedCacheTestCase.php * Update PhpRedisCacheLockTest.php * wip --------- Signed-off-by: Mior Muhammad Zaki --- tests/Integration/Cache/DynamoDbStoreTest.php | 11 ++-------- tests/Integration/Cache/FileCacheLockTest.php | 13 ++---------- .../Cache/MemcachedCacheLockTestCase.php | 5 ++--- .../Cache/MemcachedTaggedCacheTestCase.php | 5 ++--- tests/Integration/Cache/NoLockTest.php | 20 +++---------------- .../Cache/PhpRedisCacheLockTest.php | 17 +++++----------- tests/Integration/Cache/Psr6RedisTest.php | 5 ++--- 7 files changed, 18 insertions(+), 58 deletions(-) diff --git a/tests/Integration/Cache/DynamoDbStoreTest.php b/tests/Integration/Cache/DynamoDbStoreTest.php index e59ebbfd774b..b465cc61ea0e 100644 --- a/tests/Integration/Cache/DynamoDbStoreTest.php +++ b/tests/Integration/Cache/DynamoDbStoreTest.php @@ -7,19 +7,12 @@ use Illuminate\Contracts\Cache\Repository; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; +use Orchestra\Testbench\Attributes\RequiresEnv; use Orchestra\Testbench\TestCase; +#[RequiresEnv('DYNAMODB_CACHE_TABLE')] class DynamoDbStoreTest extends TestCase { - protected function setUp(): void - { - if (! env('DYNAMODB_CACHE_TABLE')) { - $this->markTestSkipped('DynamoDB not configured.'); - } - - parent::setUp(); - } - public function testItemsCanBeStoredAndRetrieved() { Cache::driver('dynamodb')->put('name', 'Taylor', 10); diff --git a/tests/Integration/Cache/FileCacheLockTest.php b/tests/Integration/Cache/FileCacheLockTest.php index c00409fe9e0e..594471806393 100644 --- a/tests/Integration/Cache/FileCacheLockTest.php +++ b/tests/Integration/Cache/FileCacheLockTest.php @@ -4,21 +4,12 @@ use Exception; use Illuminate\Support\Facades\Cache; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; +#[WithConfig('cache.default', 'file')] class FileCacheLockTest extends TestCase { - /** - * Define environment setup. - * - * @param \Illuminate\Foundation\Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - $app['config']->set('cache.default', 'file'); - } - public function testLocksCanBeAcquiredAndReleased() { Cache::lock('foo')->forceRelease(); diff --git a/tests/Integration/Cache/MemcachedCacheLockTestCase.php b/tests/Integration/Cache/MemcachedCacheLockTestCase.php index 8dbbd481f17e..e4fc82dca804 100644 --- a/tests/Integration/Cache/MemcachedCacheLockTestCase.php +++ b/tests/Integration/Cache/MemcachedCacheLockTestCase.php @@ -4,10 +4,9 @@ use Illuminate\Contracts\Cache\LockTimeoutException; use Illuminate\Support\Facades\Cache; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -/** - * @requires extension memcached - */ +#[RequiresPhpExtension('memcached')] class MemcachedCacheLockTestCase extends MemcachedIntegrationTestCase { public function testMemcachedLocksCanBeAcquiredAndReleased() diff --git a/tests/Integration/Cache/MemcachedTaggedCacheTestCase.php b/tests/Integration/Cache/MemcachedTaggedCacheTestCase.php index 4aab9422a8fd..ee7787aa407e 100644 --- a/tests/Integration/Cache/MemcachedTaggedCacheTestCase.php +++ b/tests/Integration/Cache/MemcachedTaggedCacheTestCase.php @@ -3,10 +3,9 @@ namespace Illuminate\Tests\Integration\Cache; use Illuminate\Support\Facades\Cache; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -/** - * @requires extension memcached - */ +#[RequiresPhpExtension('memcached')] class MemcachedTaggedCacheTestCase extends MemcachedIntegrationTestCase { public function testMemcachedCanStoreAndRetrieveTaggedCacheItems() diff --git a/tests/Integration/Cache/NoLockTest.php b/tests/Integration/Cache/NoLockTest.php index 9f1fc983b3aa..3851ea1278c2 100644 --- a/tests/Integration/Cache/NoLockTest.php +++ b/tests/Integration/Cache/NoLockTest.php @@ -3,27 +3,13 @@ namespace Illuminate\Tests\Integration\Cache; use Illuminate\Support\Facades\Cache; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; +#[WithConfig('cache.default', 'null')] +#[WithConfig('cache.stores.null', ['driver' => 'null'])] class NoLockTest extends TestCase { - /** - * Define environment setup. - * - * @param \Illuminate\Foundation\Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - $app['config']->set('cache.default', 'null'); - - $app['config']->set('cache.stores', [ - 'null' => [ - 'driver' => 'null', - ], - ]); - } - public function testLocksCanAlwaysBeAcquiredAndReleased() { Cache::lock('foo')->forceRelease(); diff --git a/tests/Integration/Cache/PhpRedisCacheLockTest.php b/tests/Integration/Cache/PhpRedisCacheLockTest.php index 0ca4ea85f960..63016545fdcf 100644 --- a/tests/Integration/Cache/PhpRedisCacheLockTest.php +++ b/tests/Integration/Cache/PhpRedisCacheLockTest.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; use Illuminate\Support\Facades\Cache; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Redis; class PhpRedisCacheLockTest extends TestCase @@ -138,9 +139,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithMsgpackSerialization() $this->assertNull($store->lockConnection()->get($store->getPrefix().'foo')); } - /** - * @requires extension lzf - */ + #[RequiresPhpExtension('lzf')] public function testRedisLockCanBeAcquiredAndReleasedWithLzfCompression() { if (! defined('Redis::COMPRESSION_LZF')) { @@ -167,9 +166,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithLzfCompression() $this->assertNull($store->lockConnection()->get($store->getPrefix().'foo')); } - /** - * @requires extension zstd - */ + #[RequiresPhpExtension('zstd')] public function testRedisLockCanBeAcquiredAndReleasedWithZstdCompression() { if (! defined('Redis::COMPRESSION_ZSTD')) { @@ -215,9 +212,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithZstdCompression() $this->assertNull($store->lockConnection()->get($store->getPrefix().'foo')); } - /** - * @requires extension lz4 - */ + #[RequiresPhpExtension('lz4')] public function testRedisLockCanBeAcquiredAndReleasedWithLz4Compression() { if (! defined('Redis::COMPRESSION_LZ4')) { @@ -263,9 +258,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithLz4Compression() $this->assertNull($store->lockConnection()->get($store->getPrefix().'foo')); } - /** - * @requires extension Lzf - */ + #[RequiresPhpExtension('Lzf')] public function testRedisLockCanBeAcquiredAndReleasedWithSerializationAndCompression() { if (! defined('Redis::COMPRESSION_LZF')) { diff --git a/tests/Integration/Cache/Psr6RedisTest.php b/tests/Integration/Cache/Psr6RedisTest.php index a242a2f77e29..062d5ec4dbfb 100644 --- a/tests/Integration/Cache/Psr6RedisTest.php +++ b/tests/Integration/Cache/Psr6RedisTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Tests\Integration\Cache\Fixtures\Unserializable; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class Psr6RedisTest extends TestCase { @@ -25,9 +26,7 @@ protected function tearDown(): void $this->tearDownRedis(); } - /** - * @dataProvider redisClientDataProvider - */ + #[DataProvider('redisClientDataProvider')] public function testTransactionIsNotOpenedWhenSerializationFails($redisClient): void { $this->app['config']['cache.default'] = 'redis'; From 1ad93540156a5049c0fabc975063efd08673baa1 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:46:48 +0800 Subject: [PATCH 09/10] [10.x] Test Improvements for Auth tests (#50683) * Test Improvements for Auth tests Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- .../ApiAuthenticationWithEloquentTest.php | 14 ++---- tests/Integration/Auth/AuthenticationTest.php | 50 +++++++++++-------- tests/Integration/Auth/ForgotPasswordTest.php | 10 ++-- ...ForgotPasswordWithoutDefaultRoutesTest.php | 10 ++-- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php index c5fc77aec88d..ca09a8c89213 100644 --- a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php +++ b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php @@ -3,21 +3,18 @@ namespace Illuminate\Tests\Integration\Auth; use Illuminate\Database\QueryException; -use Illuminate\Foundation\Auth\User as FoundationUser; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -/** - * @requires extension pdo_mysql - */ +#[RequiresPhpExtension('pdo_mysql')] class ApiAuthenticationWithEloquentTest extends TestCase { - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { // Auth configuration $app['config']->set('auth.defaults.guard', 'api'); - $app['config']->set('auth.providers.users.model', User::class); $app['config']->set('auth.guards.api', [ 'driver' => 'token', @@ -59,8 +56,3 @@ public function testAuthenticationViaApiWithEloquentUsingWrongDatabaseCredential } } } - -class User extends FoundationUser -{ - // -} diff --git a/tests/Integration/Auth/AuthenticationTest.php b/tests/Integration/Auth/AuthenticationTest.php index 388f23d030be..cd65dd793145 100644 --- a/tests/Integration/Auth/AuthenticationTest.php +++ b/tests/Integration/Auth/AuthenticationTest.php @@ -13,6 +13,7 @@ use Illuminate\Auth\SessionGuard; use Illuminate\Database\Schema\Blueprint; use Illuminate\Events\Dispatcher; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Schema; @@ -20,27 +21,42 @@ use Illuminate\Support\Testing\Fakes\EventFake; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; use InvalidArgumentException; +use Orchestra\Testbench\Attributes\WithMigration; use Orchestra\Testbench\TestCase; +#[WithMigration] class AuthenticationTest extends TestCase { - protected function getEnvironmentSetUp($app) + use RefreshDatabase; + + protected function defineEnvironment($app) { - $app['config']->set('auth.providers.users.model', AuthenticationTestUser::class); + $app['config']->set([ + 'auth.providers.users.model' => AuthenticationTestUser::class, + 'hashing.driver' => 'bcrypt', + ]); + } - $app['config']->set('hashing', ['driver' => 'bcrypt']); + protected function defineRoutes($router) + { + $router->get('basic', function () { + return $this->app['auth']->guard()->basic() + ?: $this->app['auth']->user()->toJson(); + }); + + $router->get('basicWithCondition', function () { + return $this->app['auth']->guard()->basic('email', ['is_active' => true]) + ?: $this->app['auth']->user()->toJson(); + }); } - protected function setUp(): void + protected function afterRefreshingDatabase() { - parent::setUp(); - - Schema::create('users', function (Blueprint $table) { - $table->increments('id'); - $table->string('email'); - $table->string('username'); - $table->string('password'); - $table->string('remember_token')->default(null)->nullable(); + Schema::table('users', function (Blueprint $table) { + $table->renameColumn('name', 'username'); + }); + + Schema::table('users', function (Blueprint $table) { $table->tinyInteger('is_active')->default(0); }); @@ -50,16 +66,6 @@ protected function setUp(): void 'password' => bcrypt('password'), 'is_active' => true, ]); - - $this->app->make('router')->get('basic', function () { - return $this->app['auth']->guard()->basic() - ?: $this->app['auth']->user()->toJson(); - }); - - $this->app->make('router')->get('basicWithCondition', function () { - return $this->app['auth']->guard()->basic('email', ['is_active' => true]) - ?: $this->app['auth']->user()->toJson(); - }); } public function testBasicAuthProtectsRoute() diff --git a/tests/Integration/Auth/ForgotPasswordTest.php b/tests/Integration/Auth/ForgotPasswordTest.php index 46a682c229d8..1bdee928b130 100644 --- a/tests/Integration/Auth/ForgotPasswordTest.php +++ b/tests/Integration/Auth/ForgotPasswordTest.php @@ -3,16 +3,21 @@ namespace Illuminate\Tests\Integration\Auth; use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Password; use Illuminate\Support\Str; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; +use Orchestra\Testbench\Attributes\WithMigration; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; +#[WithMigration] class ForgotPasswordTest extends TestCase { + use RefreshDatabase; + protected function tearDown(): void { ResetPassword::$createUrlCallback = null; @@ -27,11 +32,6 @@ protected function defineEnvironment($app) $app['config']->set('auth.providers.users.model', AuthenticationTestUser::class); } - protected function defineDatabaseMigrations() - { - $this->loadLaravelMigrations(); - } - protected function defineRoutes($router) { $router->get('password/reset/{token}', function ($token) { diff --git a/tests/Integration/Auth/ForgotPasswordWithoutDefaultRoutesTest.php b/tests/Integration/Auth/ForgotPasswordWithoutDefaultRoutesTest.php index e34dcd78b82d..f5f680beb1bc 100644 --- a/tests/Integration/Auth/ForgotPasswordWithoutDefaultRoutesTest.php +++ b/tests/Integration/Auth/ForgotPasswordWithoutDefaultRoutesTest.php @@ -3,16 +3,21 @@ namespace Illuminate\Tests\Integration\Auth; use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Password; use Illuminate\Support\Str; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; +use Orchestra\Testbench\Attributes\WithMigration; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; +#[WithMigration] class ForgotPasswordWithoutDefaultRoutesTest extends TestCase { + use RefreshDatabase; + protected function tearDown(): void { ResetPassword::$createUrlCallback = null; @@ -27,11 +32,6 @@ protected function defineEnvironment($app) $app['config']->set('auth.providers.users.model', AuthenticationTestUser::class); } - protected function defineDatabaseMigrations() - { - $this->loadLaravelMigrations(); - } - protected function defineRoutes($router) { $router->get('custom/password/reset/{token}', function ($token) { From a2d70b5a1e61b3c6b3c73c813779cd1b0a518150 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 16:47:19 +0800 Subject: [PATCH 10/10] [10.x] Test Improvements for Encryption, Events, Filesystem, Foundation, Redis & Session tests (#50686) * [10.x] Test Improvements for Encryption, Events, Filesystem, Redis & Session tests Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- .../Integration/Encryption/EncryptionTest.php | 13 +---- tests/Integration/Events/EventFakeTest.php | 11 ++-- tests/Integration/Events/ListenerTest.php | 2 +- .../ShouldDispatchAfterCommitEventTest.php | 3 +- .../Integration/Filesystem/FilesystemTest.php | 5 +- tests/Integration/Filesystem/StorageTest.php | 5 +- .../Foundation/MaintenanceModeTest.php | 11 ++-- .../InteractsWithAuthenticationTest.php | 52 ++++++------------- .../Redis/PredisConnectionTest.php | 7 +-- .../Session/CookieSessionHandlerTest.php | 2 +- .../Session/SessionPersistenceTest.php | 2 +- 11 files changed, 36 insertions(+), 77 deletions(-) diff --git a/tests/Integration/Encryption/EncryptionTest.php b/tests/Integration/Encryption/EncryptionTest.php index 1ef8dab14193..d0a281bc292c 100644 --- a/tests/Integration/Encryption/EncryptionTest.php +++ b/tests/Integration/Encryption/EncryptionTest.php @@ -3,22 +3,13 @@ namespace Illuminate\Tests\Integration\Encryption; use Illuminate\Encryption\Encrypter; -use Illuminate\Encryption\EncryptionServiceProvider; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; use RuntimeException; +#[WithConfig('app.key', 'base64:IUHRqAQ99pZ0A1MPjbuv1D6ff3jxv0GIvS2qIW4JNU4=')] class EncryptionTest extends TestCase { - protected function getEnvironmentSetUp($app) - { - $app['config']->set('app.key', 'base64:IUHRqAQ99pZ0A1MPjbuv1D6ff3jxv0GIvS2qIW4JNU4='); - } - - protected function getPackageProviders($app) - { - return [EncryptionServiceProvider::class]; - } - public function testEncryptionProviderBind() { $this->assertInstanceOf(Encrypter::class, $this->app->make('encrypter')); diff --git a/tests/Integration/Events/EventFakeTest.php b/tests/Integration/Events/EventFakeTest.php index a7e9b97cf096..b6693eed94bc 100644 --- a/tests/Integration/Events/EventFakeTest.php +++ b/tests/Integration/Events/EventFakeTest.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Events\ShouldDispatchAfterCommit; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; @@ -16,10 +17,10 @@ class EventFakeTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); + use LazilyRefreshDatabase; + protected function afterRefreshingDatabase() + { Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); @@ -28,11 +29,9 @@ protected function setUp(): void }); } - protected function tearDown(): void + protected function beforeRefreshingDatabase() { Schema::dropIfExists('posts'); - - parent::tearDown(); } public function testNonFakedEventGetsProperlyDispatched() diff --git a/tests/Integration/Events/ListenerTest.php b/tests/Integration/Events/ListenerTest.php index 76cdcb55c691..490117eef174 100644 --- a/tests/Integration/Events/ListenerTest.php +++ b/tests/Integration/Events/ListenerTest.php @@ -14,7 +14,7 @@ protected function tearDown(): void ListenerTestListener::$ran = false; ListenerTestListenerAfterCommit::$ran = false; - m::close(); + parent::tearDown(); } public function testClassListenerRunsNormallyIfNoTransactions() diff --git a/tests/Integration/Events/ShouldDispatchAfterCommitEventTest.php b/tests/Integration/Events/ShouldDispatchAfterCommitEventTest.php index 6b11d4f9916e..5ec65c1ed338 100644 --- a/tests/Integration/Events/ShouldDispatchAfterCommitEventTest.php +++ b/tests/Integration/Events/ShouldDispatchAfterCommitEventTest.php @@ -5,7 +5,6 @@ use Illuminate\Contracts\Events\ShouldDispatchAfterCommit; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; -use Mockery as m; use Orchestra\Testbench\TestCase; class ShouldDispatchAfterCommitEventTest extends TestCase @@ -16,7 +15,7 @@ protected function tearDown(): void ShouldDispatchAfterCommitTestEvent::$ran = false; AnotherShouldDispatchAfterCommitTestEvent::$ran = false; - m::close(); + parent::tearDown(); } public function testEventIsDispatchedIfThereIsNoTransaction() diff --git a/tests/Integration/Filesystem/FilesystemTest.php b/tests/Integration/Filesystem/FilesystemTest.php index 8bd38fe309fe..50d8965c82c6 100644 --- a/tests/Integration/Filesystem/FilesystemTest.php +++ b/tests/Integration/Filesystem/FilesystemTest.php @@ -4,11 +4,10 @@ use Illuminate\Support\Facades\File; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\RequiresOperatingSystem; use Symfony\Component\Process\Process; -/** - * @requires OS Linux|Darwin - */ +#[RequiresOperatingSystem('Linux|DAR')] class FilesystemTest extends TestCase { protected $stubFile; diff --git a/tests/Integration/Filesystem/StorageTest.php b/tests/Integration/Filesystem/StorageTest.php index 4193a629e178..90ba8fbfe58e 100644 --- a/tests/Integration/Filesystem/StorageTest.php +++ b/tests/Integration/Filesystem/StorageTest.php @@ -5,11 +5,10 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\RequiresOperatingSystem; use Symfony\Component\Process\Process; -/** - * @requires OS Linux|Darwin - */ +#[RequiresOperatingSystem('Linux|DAR')] class StorageTest extends TestCase { protected $stubFile; diff --git a/tests/Integration/Foundation/MaintenanceModeTest.php b/tests/Integration/Foundation/MaintenanceModeTest.php index 493934b6dd4a..377bff02858f 100644 --- a/tests/Integration/Foundation/MaintenanceModeTest.php +++ b/tests/Integration/Foundation/MaintenanceModeTest.php @@ -19,16 +19,15 @@ class MaintenanceModeTest extends TestCase { protected function setUp(): void { + $this->beforeApplicationDestroyed(function () { + @unlink(storage_path('framework/down')); + }); + parent::setUp(); $this->withoutMiddleware(TestbenchPreventRequestsDuringMaintenance::class); } - protected function tearDown(): void - { - @unlink(storage_path('framework/down')); - } - public function testBasicMaintenanceModeResponse() { file_put_contents(storage_path('framework/down'), json_encode([ @@ -172,8 +171,6 @@ public function testCanCreateBypassCookies() Carbon::setTestNow(now()->addMonths(6)); $this->assertFalse(MaintenanceModeBypassCookie::isValid($cookie->getValue(), 'test-key')); - - Carbon::setTestNow(null); } public function testDispatchEventWhenMaintenanceModeIsEnabled() diff --git a/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php index 01e97f5b0cd4..2ccaa6775b94 100644 --- a/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php +++ b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php @@ -3,19 +3,22 @@ namespace Illuminate\Tests\Integration\Foundation\Testing\Concerns; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Foundation\Auth\User; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Schema; +use Orchestra\Testbench\Attributes\WithMigration; use Orchestra\Testbench\TestCase; +#[WithMigration] class InteractsWithAuthenticationTest extends TestCase { - protected function getEnvironmentSetUp($app) - { - $app['config']->set('auth.providers.users.model', AuthenticationTestUser::class); + use RefreshDatabase; + protected function defineEnvironment($app) + { $app['config']->set('auth.guards.api', [ 'driver' => 'token', 'provider' => 'users', @@ -23,20 +26,17 @@ protected function getEnvironmentSetUp($app) ]); } - protected function setUp(): void + protected function afterRefreshingDatabase() { - parent::setUp(); + Schema::table('users', function (Blueprint $table) { + $table->renameColumn('name', 'username'); + }); - Schema::create('users', function (Blueprint $table) { - $table->increments('id'); - $table->string('email'); - $table->string('username'); - $table->string('password'); - $table->string('remember_token')->default(null)->nullable(); + Schema::table('users', function (Blueprint $table) { $table->tinyInteger('is_active')->default(0); }); - AuthenticationTestUser::create([ + User::forceCreate([ 'username' => 'taylorotwell', 'email' => 'taylorotwell@laravel.com', 'password' => bcrypt('password'), @@ -50,7 +50,7 @@ public function testActingAsIsProperlyHandledForSessionAuth() return 'Hello '.$request->user()->username; })->middleware(['auth']); - $user = AuthenticationTestUser::where('username', '=', 'taylorotwell')->first(); + $user = User::where('username', '=', 'taylorotwell')->first(); $this->actingAs($user) ->get('/me') @@ -68,7 +68,7 @@ public function testActingAsIsProperlyHandledForAuthViaRequest() return $request->user(); }); - $user = AuthenticationTestUser::where('username', '=', 'taylorotwell')->first(); + $user = User::where('username', '=', 'taylorotwell')->first(); $this->actingAs($user, 'api') ->get('/me') @@ -76,25 +76,3 @@ public function testActingAsIsProperlyHandledForAuthViaRequest() ->assertSeeText('Hello taylorotwell'); } } - -class AuthenticationTestUser extends Authenticatable -{ - public $table = 'users'; - public $timestamps = false; - - /** - * The attributes that are mass assignable. - * - * @var string[] - */ - protected $guarded = []; - - /** - * The attributes that should be hidden for arrays. - * - * @var string[] - */ - protected $hidden = [ - 'password', 'remember_token', - ]; -} diff --git a/tests/Integration/Redis/PredisConnectionTest.php b/tests/Integration/Redis/PredisConnectionTest.php index e25dbbc8fe4e..2ec51d21521a 100644 --- a/tests/Integration/Redis/PredisConnectionTest.php +++ b/tests/Integration/Redis/PredisConnectionTest.php @@ -6,17 +6,14 @@ use Illuminate\Redis\Events\CommandExecuted; use Illuminate\Support\Facades\Event; use Mockery as m; +use Orchestra\Testbench\Attributes\WithConfig; use Orchestra\Testbench\TestCase; use Predis\Client; use Predis\Command\Argument\Search\SearchArguments; +#[WithConfig('database.redis.client', 'predis')] class PredisConnectionTest extends TestCase { - protected function defineEnvironment($app) - { - $app->get('config')->set('database.redis.client', 'predis'); - } - public function testPredisCanEmitEventWithArrayableArgumentObject() { if (! class_exists(SearchArguments::class)) { diff --git a/tests/Integration/Session/CookieSessionHandlerTest.php b/tests/Integration/Session/CookieSessionHandlerTest.php index e7307d71421a..896cf25cf5c5 100644 --- a/tests/Integration/Session/CookieSessionHandlerTest.php +++ b/tests/Integration/Session/CookieSessionHandlerTest.php @@ -20,7 +20,7 @@ public function testCookieSessionDriverCookiesCanExpireOnClose() $this->assertEquals(0, $sessionValueCookie->getExpiresTime()); } - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app['config']->set('app.key', Str::random(32)); $app['config']->set('session.driver', 'cookie'); diff --git a/tests/Integration/Session/SessionPersistenceTest.php b/tests/Integration/Session/SessionPersistenceTest.php index d911bdffae0e..6253b79eb766 100644 --- a/tests/Integration/Session/SessionPersistenceTest.php +++ b/tests/Integration/Session/SessionPersistenceTest.php @@ -31,7 +31,7 @@ public function testSessionIsPersistedEvenIfExceptionIsThrownFromRoute() $this->assertTrue($handler->written); } - protected function getEnvironmentSetUp($app) + protected function defineEnvironment($app) { $app->instance( ExceptionHandler::class,