From 7de85741d4856953d21114b84924b68e7a35da4e Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 3 Feb 2022 16:39:32 +0100 Subject: [PATCH 1/2] Fix Carbon::setTestNow usage. --- tests/Auth/AuthDatabaseTokenRepositoryTest.php | 8 -------- tests/Cache/CacheArrayStoreTest.php | 14 ++++++++------ tests/Cache/CacheFileStoreTest.php | 14 -------------- tests/Cache/CacheMemcachedStoreTest.php | 2 +- tests/Cache/CacheRepositoryTest.php | 8 ++------ tests/Console/Scheduling/FrequencyTest.php | 4 +++- tests/Database/DatabaseEloquentBuilderTest.php | 10 ++++------ .../Database/DatabaseEloquentIntegrationTest.php | 16 ++++------------ .../DatabaseEloquentIrregularPluralTest.php | 4 ++++ tests/Database/DatabaseEloquentModelTest.php | 8 -------- ...atabaseEloquentSoftDeletesIntegrationTest.php | 2 +- .../Database/DatabaseEloquentTimestampsTest.php | 3 ++- tests/Database/DatabaseSoftDeletingTest.php | 1 - tests/Integration/Cache/FileCacheLockTest.php | 2 -- .../Cache/MemcachedCacheLockTestCase.php | 4 ---- tests/Integration/Cache/NoLockTest.php | 2 -- tests/Integration/Cache/RedisCacheLockTest.php | 2 -- tests/Integration/Cookie/CookieTest.php | 1 - .../Database/EloquentBelongsToManyTest.php | 7 +++++++ .../Database/EloquentMorphManyTest.php | 2 -- .../Mail/SendingMailWithLocaleTest.php | 2 ++ .../SendingNotificationsWithLocaleTest.php | 2 ++ tests/Integration/Routing/UrlSigningTest.php | 7 +++++++ tests/Queue/DynamoDbFailedJobProviderTest.php | 2 +- tests/Queue/QueueWorkerTest.php | 4 ++++ tests/Queue/RedisQueueIntegrationTest.php | 5 +++-- tests/Session/ArraySessionHandlerTest.php | 10 +++++++--- tests/Support/SupportCarbonTest.php | 2 +- tests/Validation/ValidationValidatorTest.php | 5 ++++- 29 files changed, 67 insertions(+), 86 deletions(-) diff --git a/tests/Auth/AuthDatabaseTokenRepositoryTest.php b/tests/Auth/AuthDatabaseTokenRepositoryTest.php index 446139c0c7da..de45482a01f2 100755 --- a/tests/Auth/AuthDatabaseTokenRepositoryTest.php +++ b/tests/Auth/AuthDatabaseTokenRepositoryTest.php @@ -13,19 +13,11 @@ class AuthDatabaseTokenRepositoryTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - Carbon::setTestNow(Carbon::now()); - } - protected function tearDown(): void { parent::tearDown(); m::close(); - Carbon::setTestNow(null); } public function testCreateInsertsNewRecordIntoTable() diff --git a/tests/Cache/CacheArrayStoreTest.php b/tests/Cache/CacheArrayStoreTest.php index f273f3ad747c..31f1e4d26e63 100755 --- a/tests/Cache/CacheArrayStoreTest.php +++ b/tests/Cache/CacheArrayStoreTest.php @@ -9,6 +9,13 @@ class CacheArrayStoreTest extends TestCase { + protected function tearDown(): void + { + parent::tearDown(); + + Carbon::setTestNow(null); + } + public function testItemsCanBeSetAndRetrieved() { $store = new ArrayStore; @@ -37,7 +44,6 @@ public function testMultipleItemsCanBeSetAndRetrieved() public function testItemsCanExpire() { - Carbon::setTestNow(Carbon::now()); $store = new ArrayStore; $store->put('foo', 'bar', 10); @@ -45,7 +51,6 @@ public function testItemsCanExpire() $result = $store->get('foo'); $this->assertNull($result); - Carbon::setTestNow(null); } public function testStoreItemForeverProperlyStoresInArray() @@ -77,7 +82,6 @@ public function testNonExistingKeysCanBeIncremented() public function testExpiredKeysAreIncrementedLikeNonExistingKeys() { - Carbon::setTestNow(Carbon::now()); $store = new ArrayStore; $store->put('foo', 999, 10); @@ -85,7 +89,6 @@ public function testExpiredKeysAreIncrementedLikeNonExistingKeys() $result = $store->increment('foo'); $this->assertEquals(1, $result); - Carbon::setTestNow(null); } public function testValuesCanBeDecremented() @@ -134,7 +137,6 @@ public function testCannotAcquireLockTwice() public function testCanAcquireLockAgainAfterExpiry() { - Carbon::setTestNow(Carbon::now()); $store = new ArrayStore; $lock = $store->lock('foo', 10); $lock->acquire(); @@ -146,6 +148,7 @@ public function testCanAcquireLockAgainAfterExpiry() public function testLockExpirationLowerBoundary() { Carbon::setTestNow(Carbon::now()); + $store = new ArrayStore; $lock = $store->lock('foo', 10); $lock->acquire(); @@ -156,7 +159,6 @@ public function testLockExpirationLowerBoundary() public function testLockWithNoExpirationNeverExpires() { - Carbon::setTestNow(Carbon::now()); $store = new ArrayStore; $lock = $store->lock('foo'); $lock->acquire(); diff --git a/tests/Cache/CacheFileStoreTest.php b/tests/Cache/CacheFileStoreTest.php index e1f50801d6b7..cac7c29b4c01 100755 --- a/tests/Cache/CacheFileStoreTest.php +++ b/tests/Cache/CacheFileStoreTest.php @@ -11,20 +11,6 @@ class CacheFileStoreTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - Carbon::setTestNow(Carbon::now()); - } - - protected function tearDown(): void - { - parent::tearDown(); - - Carbon::setTestNow(null); - } - public function testNullIsReturnedIfFileDoesntExist() { $files = $this->mockFilesystem(); diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index f6f0cf17ab64..bbfbe2343118 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -66,7 +66,7 @@ public function testSetMethodProperlyCallsMemcache() $store = new MemcachedStore($memcache); $result = $store->put('foo', 'bar', 60); $this->assertTrue($result); - Carbon::setTestNow(); + Carbon::setTestNow(null); } public function testIncrementMethodProperlyCallsMemcache() diff --git a/tests/Cache/CacheRepositoryTest.php b/tests/Cache/CacheRepositoryTest.php index 86064250e80c..055456890206 100755 --- a/tests/Cache/CacheRepositoryTest.php +++ b/tests/Cache/CacheRepositoryTest.php @@ -23,7 +23,8 @@ class CacheRepositoryTest extends TestCase protected function tearDown(): void { m::close(); - Carbon::setTestNow(); + + Carbon::setTestNow(null); } public function testGetReturnsValueFromCache() @@ -96,11 +97,6 @@ public function testRememberMethodCallsPutAndReturnsDefault() }); $this->assertSame('bar', $result); - /* - * Use Carbon object... - */ - Carbon::setTestNow(Carbon::now()); - $repo = $this->getRepository(); $repo->getStore()->shouldReceive('get')->times(2)->andReturn(null); $repo->getStore()->shouldReceive('put')->once()->with('foo', 'bar', 602); diff --git a/tests/Console/Scheduling/FrequencyTest.php b/tests/Console/Scheduling/FrequencyTest.php index 5a14c37ce2e0..812a4b5b6f02 100644 --- a/tests/Console/Scheduling/FrequencyTest.php +++ b/tests/Console/Scheduling/FrequencyTest.php @@ -17,7 +17,7 @@ class FrequencyTest extends TestCase protected function setUp(): void { - Carbon::setTestNow(); + $this->event = new Event( m::mock(EventMutex::class), @@ -102,6 +102,8 @@ public function testLastDayOfMonth() Carbon::setTestNow('2020-10-10 10:10:10'); $this->assertSame('0 0 31 * *', $this->event->lastDayOfMonth()->getExpression()); + + Carbon::setTestNow(null); } public function testTwiceMonthly() diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 863344c4ec46..577d14607bac 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -26,6 +26,10 @@ class DatabaseEloquentBuilderTest extends TestCase { protected function tearDown(): void { + parent::tearDown(); + + Carbon::setTestNow(null); + m::close(); } @@ -1665,8 +1669,6 @@ public function testUpdate() $result = $builder->update(['foo' => 'bar']); $this->assertEquals(1, $result); - - Carbon::setTestNow(null); } public function testUpdateWithTimestampValue() @@ -1711,8 +1713,6 @@ public function testUpdateWithAlias() $result = $builder->from('table as alias')->update(['foo' => 'bar']); $this->assertEquals(1, $result); - - Carbon::setTestNow(null); } public function testUpsert() @@ -1736,8 +1736,6 @@ public function testUpsert() $result = $builder->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], ['email']); $this->assertEquals(2, $result); - - Carbon::setTestNow(null); } public function testWithCastsMethod() diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index ed3d1a011b37..5396078f5d58 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -155,6 +155,8 @@ protected function createSchema() */ protected function tearDown(): void { + parent::tearDown(); + foreach (['default', 'second_connection'] as $connection) { $this->schema($connection)->drop('users'); $this->schema($connection)->drop('friends'); @@ -165,6 +167,8 @@ protected function tearDown(): void Relation::morphMap([], false); Eloquent::unsetConnectionResolver(); + + Carbon::setTestNow(null); } /** @@ -1628,7 +1632,6 @@ public function testUpdatingChildModelTouchesParent() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - Carbon::setTestNow($before); } public function testMultiLevelTouchingWorks() @@ -1648,7 +1651,6 @@ public function testMultiLevelTouchingWorks() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching models related timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - Carbon::setTestNow($before); } public function testDeletingChildModelTouchesParentTimestamps() @@ -1667,7 +1669,6 @@ public function testDeletingChildModelTouchesParentTimestamps() $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - Carbon::setTestNow($before); } public function testTouchingChildModelUpdatesParentsTimestamps() @@ -1687,7 +1688,6 @@ public function testTouchingChildModelUpdatesParentsTimestamps() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - Carbon::setTestNow($before); } public function testTouchingChildModelRespectsParentNoTouching() @@ -1716,7 +1716,6 @@ public function testTouchingChildModelRespectsParentNoTouching() 'It is touching model own timestamps in withoutTouching scope, when it should not.' ); - Carbon::setTestNow($before); } public function testUpdatingChildPostRespectsNoTouchingDefinition() @@ -1738,7 +1737,6 @@ public function testUpdatingChildPostRespectsNoTouchingDefinition() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps when it should.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models relationships when it should be disabled.'); - Carbon::setTestNow($before); } public function testUpdatingModelInTheDisabledScopeTouchesItsOwnTimestamps() @@ -1760,7 +1758,6 @@ public function testUpdatingModelInTheDisabledScopeTouchesItsOwnTimestamps() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testDeletingChildModelRespectsTheNoTouchingRule() @@ -1781,7 +1778,6 @@ public function testDeletingChildModelRespectsTheNoTouchingRule() $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testRespectedMultiLevelTouchingChain() @@ -1803,7 +1799,6 @@ public function testRespectedMultiLevelTouchingChain() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testTouchesGreatParentEvenWhenParentIsInNoTouchScope() @@ -1825,7 +1820,6 @@ public function testTouchesGreatParentEvenWhenParentIsInNoTouchScope() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testCanNestCallsOfNoTouching() @@ -1849,7 +1843,6 @@ public function testCanNestCallsOfNoTouching() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testCanPassArrayOfModelsToIgnore() @@ -1871,7 +1864,6 @@ public function testCanPassArrayOfModelsToIgnore() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - Carbon::setTestNow($before); } public function testWhenBaseModelIsIgnoredAllChildModelsAreIgnored() diff --git a/tests/Database/DatabaseEloquentIrregularPluralTest.php b/tests/Database/DatabaseEloquentIrregularPluralTest.php index 9ca407db4564..7d2ce9490b43 100644 --- a/tests/Database/DatabaseEloquentIrregularPluralTest.php +++ b/tests/Database/DatabaseEloquentIrregularPluralTest.php @@ -55,9 +55,13 @@ public function createSchema() protected function tearDown(): void { + parent::tearDown(); + $this->schema()->drop('irregular_plural_tokens'); $this->schema()->drop('irregular_plural_humans'); $this->schema()->drop('irregular_plural_human_irregular_plural_token'); + + Carbon::setTestNow(null); } protected function schema() diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 1ff87c9bf215..2652450c87e4 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -42,13 +42,6 @@ class DatabaseEloquentModelTest extends TestCase { use InteractsWithTime; - protected function setUp(): void - { - parent::setUp(); - - Carbon::setTestNow(Carbon::now()); - } - protected function tearDown(): void { parent::tearDown(); @@ -2058,7 +2051,6 @@ public function testScopesMethod() $model = new EloquentModelStub; $this->addMockConnection($model); - Carbon::setTestNow(); $scopes = [ 'published', diff --git a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php index 35940d457e47..63808200e6e5 100644 --- a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php +++ b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php @@ -18,7 +18,7 @@ class DatabaseEloquentSoftDeletesIntegrationTest extends TestCase { protected function setUp(): void { - Carbon::setTestNow(Carbon::now()); + parent::setUp(); $db = new DB; diff --git a/tests/Database/DatabaseEloquentTimestampsTest.php b/tests/Database/DatabaseEloquentTimestampsTest.php index a75cb8c1cc72..463e54b60e24 100644 --- a/tests/Database/DatabaseEloquentTimestampsTest.php +++ b/tests/Database/DatabaseEloquentTimestampsTest.php @@ -11,6 +11,8 @@ class DatabaseEloquentTimestampsTest extends TestCase { protected function setUp(): void { + parent::setUp(); + $db = new DB; $db->addConnection([ @@ -22,7 +24,6 @@ protected function setUp(): void $db->setAsGlobal(); $this->createSchema(); - Carbon::setTestNow(Carbon::now()); } /** diff --git a/tests/Database/DatabaseSoftDeletingTest.php b/tests/Database/DatabaseSoftDeletingTest.php index 3b136b92670f..9eee030bbaf6 100644 --- a/tests/Database/DatabaseSoftDeletingTest.php +++ b/tests/Database/DatabaseSoftDeletingTest.php @@ -19,7 +19,6 @@ public function testDeletedAtIsAddedToCastsAsDefaultType() public function testDeletedAtIsCastToCarbonInstance() { - Carbon::setTestNow(Carbon::now()); $expected = Carbon::createFromFormat('Y-m-d H:i:s', '2018-12-29 13:59:39'); $model = new SoftDeletingModel(['deleted_at' => $expected->format('Y-m-d H:i:s')]); diff --git a/tests/Integration/Cache/FileCacheLockTest.php b/tests/Integration/Cache/FileCacheLockTest.php index b4654ba311c9..75916c5c47ae 100644 --- a/tests/Integration/Cache/FileCacheLockTest.php +++ b/tests/Integration/Cache/FileCacheLockTest.php @@ -37,8 +37,6 @@ public function testLocksCanBeAcquiredAndReleased() public function testLocksCanBlockForSeconds() { - Carbon::setTestNow(); - Cache::lock('foo')->forceRelease(); $this->assertSame('taylor', Cache::lock('foo', 10)->block(1, function () { return 'taylor'; diff --git a/tests/Integration/Cache/MemcachedCacheLockTestCase.php b/tests/Integration/Cache/MemcachedCacheLockTestCase.php index 50c0eeaa2746..2fa9172e0f87 100644 --- a/tests/Integration/Cache/MemcachedCacheLockTestCase.php +++ b/tests/Integration/Cache/MemcachedCacheLockTestCase.php @@ -24,8 +24,6 @@ public function testMemcachedLocksCanBeAcquiredAndReleased() public function testMemcachedLocksCanBlockForSeconds() { - Carbon::setTestNow(); - Cache::store('memcached')->lock('foo')->forceRelease(); $this->assertSame('taylor', Cache::store('memcached')->lock('foo', 10)->block(1, function () { return 'taylor'; @@ -47,8 +45,6 @@ public function testLocksThrowTimeoutIfBlockExpires() { $this->expectException(LockTimeoutException::class); - Carbon::setTestNow(); - Cache::store('memcached')->lock('foo')->release(); Cache::store('memcached')->lock('foo', 5)->get(); $this->assertSame('taylor', Cache::store('memcached')->lock('foo', 10)->block(1, function () { diff --git a/tests/Integration/Cache/NoLockTest.php b/tests/Integration/Cache/NoLockTest.php index 8662e3ccbb3b..a7efe02c8e7b 100644 --- a/tests/Integration/Cache/NoLockTest.php +++ b/tests/Integration/Cache/NoLockTest.php @@ -38,8 +38,6 @@ public function testLocksCanAlwaysBeAcquiredAndReleased() public function testLocksCanBlockForSeconds() { - Carbon::setTestNow(); - Cache::lock('foo')->forceRelease(); $this->assertSame('taylor', Cache::lock('foo', 10)->block(1, function () { return 'taylor'; diff --git a/tests/Integration/Cache/RedisCacheLockTest.php b/tests/Integration/Cache/RedisCacheLockTest.php index c131c0c23c2e..24beccdf3f6e 100644 --- a/tests/Integration/Cache/RedisCacheLockTest.php +++ b/tests/Integration/Cache/RedisCacheLockTest.php @@ -50,8 +50,6 @@ public function testRedisLockCanHaveASeparateConnection() public function testRedisLocksCanBlockForSeconds() { - Carbon::setTestNow(); - Cache::store('redis')->lock('foo')->forceRelease(); $this->assertSame('taylor', Cache::store('redis')->lock('foo', 10)->block(1, function () { return 'taylor'; diff --git a/tests/Integration/Cookie/CookieTest.php b/tests/Integration/Cookie/CookieTest.php index 543d0ffd4bfd..4b04773c0287 100644 --- a/tests/Integration/Cookie/CookieTest.php +++ b/tests/Integration/Cookie/CookieTest.php @@ -36,7 +36,6 @@ public function test_cookie_is_sent_back_with_proper_expire_time_with_respect_to return 'hello world'; })->middleware('web'); - Carbon::setTestNow(Carbon::now()); $response = $this->get('/'); $this->assertCount(2, $response->headers->getCookies()); $this->assertEquals(Carbon::now()->getTimestamp() + 60, ($response->headers->getCookies()[1])->getExpiresTime()); diff --git a/tests/Integration/Database/EloquentBelongsToManyTest.php b/tests/Integration/Database/EloquentBelongsToManyTest.php index e99a36d9b595..f70b3a8e75f2 100644 --- a/tests/Integration/Database/EloquentBelongsToManyTest.php +++ b/tests/Integration/Database/EloquentBelongsToManyTest.php @@ -15,6 +15,13 @@ class EloquentBelongsToManyTest extends DatabaseTestCase { + protected function tearDown(): void + { + parent::tearDown(); + + Carbon::setTestNow(null); + } + protected function defineDatabaseMigrationsAfterDatabaseRefreshed() { Schema::create('users', function (Blueprint $table) { diff --git a/tests/Integration/Database/EloquentMorphManyTest.php b/tests/Integration/Database/EloquentMorphManyTest.php index 04a22a565166..7f96ee02629c 100644 --- a/tests/Integration/Database/EloquentMorphManyTest.php +++ b/tests/Integration/Database/EloquentMorphManyTest.php @@ -26,8 +26,6 @@ protected function defineDatabaseMigrationsAfterDatabaseRefreshed() $table->string('commentable_type'); $table->timestamps(); }); - - Carbon::setTestNow(null); } public function testUpdateModelWithDefaultWithCount() diff --git a/tests/Integration/Mail/SendingMailWithLocaleTest.php b/tests/Integration/Mail/SendingMailWithLocaleTest.php index e9d1272a258f..abdf299c9fff 100644 --- a/tests/Integration/Mail/SendingMailWithLocaleTest.php +++ b/tests/Integration/Mail/SendingMailWithLocaleTest.php @@ -79,6 +79,8 @@ public function testMailIsSentWithLocaleUpdatedListenersCalled() ); $this->assertSame('en', Carbon::getLocale()); + + Carbon::setTestNow(null); } public function testLocaleIsSentWithModelPreferredLocale() diff --git a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php index cbd2a309a787..9b9862abfa51 100644 --- a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php +++ b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php @@ -145,6 +145,8 @@ public function testMailIsSentWithLocaleUpdatedListenersCalled() $this->assertTrue($this->app->isLocale('en')); $this->assertSame('en', Carbon::getLocale()); + + Carbon::setTestNow(null); } public function testLocaleIsSentWithNotifiablePreferredLocale() diff --git a/tests/Integration/Routing/UrlSigningTest.php b/tests/Integration/Routing/UrlSigningTest.php index 073d713b1532..532014386d8f 100644 --- a/tests/Integration/Routing/UrlSigningTest.php +++ b/tests/Integration/Routing/UrlSigningTest.php @@ -13,6 +13,13 @@ class UrlSigningTest extends TestCase { + protected function tearDown(): void + { + parent::tearDown(); + + Carbon::setTestNow(null); + } + public function testSigningUrl() { Route::get('/foo/{id}', function (Request $request, $id) { diff --git a/tests/Queue/DynamoDbFailedJobProviderTest.php b/tests/Queue/DynamoDbFailedJobProviderTest.php index 8ee85988a88d..dcd0cfe5f9d1 100644 --- a/tests/Queue/DynamoDbFailedJobProviderTest.php +++ b/tests/Queue/DynamoDbFailedJobProviderTest.php @@ -27,7 +27,7 @@ public function testCanProperlyLogFailedJob() return $uuid; }); - Carbon::setTestNow($now = CarbonImmutable::now()); + $now = CarbonImmutable::now(); $exception = new Exception('Something went wrong.'); diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index 28564c3c7720..8d698fd0c869 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -37,6 +37,10 @@ protected function setUp(): void protected function tearDown(): void { + parent::tearDown(); + + Carbon::setTestNow(null); + Container::setInstance(null); } diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index 18f543492052..17d2ec4d604c 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -30,15 +30,16 @@ class RedisQueueIntegrationTest extends TestCase protected function setUp(): void { - Carbon::setTestNow(Carbon::now()); parent::setUp(); + $this->setUpRedis(); } protected function tearDown(): void { - Carbon::setTestNow(null); parent::tearDown(); + + Carbon::setTestNow(null); $this->tearDownRedis(); m::close(); } diff --git a/tests/Session/ArraySessionHandlerTest.php b/tests/Session/ArraySessionHandlerTest.php index 3e93a2675592..1b757aae14b5 100644 --- a/tests/Session/ArraySessionHandlerTest.php +++ b/tests/Session/ArraySessionHandlerTest.php @@ -9,6 +9,13 @@ class ArraySessionHandlerTest extends TestCase { + protected function tearDown(): void + { + parent::tearDown(); + + Carbon::setTestNow(null); + } + public function test_it_implements_the_session_handler_interface() { $this->assertInstanceOf(SessionHandlerInterface::class, new ArraySessionHandler(10)); @@ -45,7 +52,6 @@ public function test_it_reads_data_from_an_almost_expired_session() Carbon::setTestNow(Carbon::now()->addMinutes(10)); $this->assertSame('bar', $handler->read('foo')); - Carbon::setTestNow(); } public function test_it_reads_data_from_an_expired_session() @@ -56,7 +62,6 @@ public function test_it_reads_data_from_an_expired_session() Carbon::setTestNow(Carbon::now()->addMinutes(10)->addSecond()); $this->assertSame('', $handler->read('foo')); - Carbon::setTestNow(); } public function test_it_reads_data_from_a_non_existing_session() @@ -109,6 +114,5 @@ public function test_it_cleans_up_old_sessions() $this->assertSame('', $handler->read('foo')); $this->assertSame('qux', $handler->read('baz')); - Carbon::setTestNow(); } } diff --git a/tests/Support/SupportCarbonTest.php b/tests/Support/SupportCarbonTest.php index a01ca35ec254..f32c12033c7c 100644 --- a/tests/Support/SupportCarbonTest.php +++ b/tests/Support/SupportCarbonTest.php @@ -25,7 +25,7 @@ protected function setUp(): void protected function tearDown(): void { - Carbon::setTestNow(); + Carbon::setTestNow(null); Carbon::serializeUsing(null); parent::tearDown(); diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 445daa95de60..d5b6d7893bdb 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -36,7 +36,8 @@ class ValidationValidatorTest extends TestCase { protected function tearDown(): void { - Carbon::setTestNow(); + parent::tearDown(); + m::close(); } @@ -4019,6 +4020,8 @@ public function testDateEqualsRespectsCarbonTestNowWhenParameterIsRelative() $v = new Validator($trans, ['x' => new Carbon('2018-01-01')], ['x' => 'date_equals:tomorrow']); $this->assertTrue($v->fails()); + + Carbon::setTestNow(null); } public function testBeforeAndAfter() From b320c7f32c131a2164071995ee09c11a5a5aa313 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 3 Feb 2022 16:54:49 +0100 Subject: [PATCH 2/2] Fix CS. --- tests/Console/Scheduling/FrequencyTest.php | 2 -- tests/Database/DatabaseEloquentIntegrationTest.php | 12 ------------ tests/Database/DatabaseEloquentModelTest.php | 1 - tests/Integration/Cache/FileCacheLockTest.php | 1 - .../Integration/Cache/MemcachedCacheLockTestCase.php | 1 - tests/Integration/Cache/NoLockTest.php | 1 - tests/Integration/Cache/RedisCacheLockTest.php | 1 - tests/Integration/Database/EloquentMorphManyTest.php | 1 - tests/Session/ArraySessionHandlerTest.php | 1 - 9 files changed, 21 deletions(-) diff --git a/tests/Console/Scheduling/FrequencyTest.php b/tests/Console/Scheduling/FrequencyTest.php index 812a4b5b6f02..e914db37ee02 100644 --- a/tests/Console/Scheduling/FrequencyTest.php +++ b/tests/Console/Scheduling/FrequencyTest.php @@ -17,8 +17,6 @@ class FrequencyTest extends TestCase protected function setUp(): void { - - $this->event = new Event( m::mock(EventMutex::class), 'php foo' diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 5396078f5d58..c4189668c4f7 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -1631,7 +1631,6 @@ public function testUpdatingChildModelTouchesParent() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - } public function testMultiLevelTouchingWorks() @@ -1650,7 +1649,6 @@ public function testMultiLevelTouchingWorks() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching models related timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - } public function testDeletingChildModelTouchesParentTimestamps() @@ -1668,7 +1666,6 @@ public function testDeletingChildModelTouchesParentTimestamps() $post->delete(); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - } public function testTouchingChildModelUpdatesParentsTimestamps() @@ -1687,7 +1684,6 @@ public function testTouchingChildModelUpdatesParentsTimestamps() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is not touching models related timestamps.'); - } public function testTouchingChildModelRespectsParentNoTouching() @@ -1715,7 +1711,6 @@ public function testTouchingChildModelRespectsParentNoTouching() $before->isSameDay($user->fresh()->updated_at), 'It is touching model own timestamps in withoutTouching scope, when it should not.' ); - } public function testUpdatingChildPostRespectsNoTouchingDefinition() @@ -1736,7 +1731,6 @@ public function testUpdatingChildPostRespectsNoTouchingDefinition() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is not touching model own timestamps when it should.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models relationships when it should be disabled.'); - } public function testUpdatingModelInTheDisabledScopeTouchesItsOwnTimestamps() @@ -1757,7 +1751,6 @@ public function testUpdatingModelInTheDisabledScopeTouchesItsOwnTimestamps() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testDeletingChildModelRespectsTheNoTouchingRule() @@ -1777,7 +1770,6 @@ public function testDeletingChildModelRespectsTheNoTouchingRule() }); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testRespectedMultiLevelTouchingChain() @@ -1798,7 +1790,6 @@ public function testRespectedMultiLevelTouchingChain() $this->assertTrue($future->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testTouchesGreatParentEvenWhenParentIsInNoTouchScope() @@ -1819,7 +1810,6 @@ public function testTouchesGreatParentEvenWhenParentIsInNoTouchScope() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($future->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testCanNestCallsOfNoTouching() @@ -1842,7 +1832,6 @@ public function testCanNestCallsOfNoTouching() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testCanPassArrayOfModelsToIgnore() @@ -1863,7 +1852,6 @@ public function testCanPassArrayOfModelsToIgnore() $this->assertTrue($before->isSameDay($post->fresh()->updated_at), 'It is touching models when it should be disabled.'); $this->assertTrue($before->isSameDay($user->fresh()->updated_at), 'It is touching models when it should be disabled.'); - } public function testWhenBaseModelIsIgnoredAllChildModelsAreIgnored() diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 2652450c87e4..0f152cbcf0b5 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -2051,7 +2051,6 @@ public function testScopesMethod() $model = new EloquentModelStub; $this->addMockConnection($model); - $scopes = [ 'published', 'category' => 'Laravel', diff --git a/tests/Integration/Cache/FileCacheLockTest.php b/tests/Integration/Cache/FileCacheLockTest.php index 75916c5c47ae..207d9032ea87 100644 --- a/tests/Integration/Cache/FileCacheLockTest.php +++ b/tests/Integration/Cache/FileCacheLockTest.php @@ -3,7 +3,6 @@ namespace Illuminate\Tests\Integration\Cache; use Exception; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Orchestra\Testbench\TestCase; diff --git a/tests/Integration/Cache/MemcachedCacheLockTestCase.php b/tests/Integration/Cache/MemcachedCacheLockTestCase.php index 2fa9172e0f87..7f3e93f8c7c0 100644 --- a/tests/Integration/Cache/MemcachedCacheLockTestCase.php +++ b/tests/Integration/Cache/MemcachedCacheLockTestCase.php @@ -3,7 +3,6 @@ namespace Illuminate\Tests\Integration\Cache; use Illuminate\Contracts\Cache\LockTimeoutException; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; /** diff --git a/tests/Integration/Cache/NoLockTest.php b/tests/Integration/Cache/NoLockTest.php index a7efe02c8e7b..9f1fc983b3aa 100644 --- a/tests/Integration/Cache/NoLockTest.php +++ b/tests/Integration/Cache/NoLockTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Cache; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Orchestra\Testbench\TestCase; diff --git a/tests/Integration/Cache/RedisCacheLockTest.php b/tests/Integration/Cache/RedisCacheLockTest.php index 24beccdf3f6e..d1434f0aa95f 100644 --- a/tests/Integration/Cache/RedisCacheLockTest.php +++ b/tests/Integration/Cache/RedisCacheLockTest.php @@ -4,7 +4,6 @@ use Exception; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Orchestra\Testbench\TestCase; diff --git a/tests/Integration/Database/EloquentMorphManyTest.php b/tests/Integration/Database/EloquentMorphManyTest.php index 7f96ee02629c..5464053bed89 100644 --- a/tests/Integration/Database/EloquentMorphManyTest.php +++ b/tests/Integration/Database/EloquentMorphManyTest.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; use Illuminate\Tests\Integration\Database\DatabaseTestCase; diff --git a/tests/Session/ArraySessionHandlerTest.php b/tests/Session/ArraySessionHandlerTest.php index 1b757aae14b5..e6d29714c31e 100644 --- a/tests/Session/ArraySessionHandlerTest.php +++ b/tests/Session/ArraySessionHandlerTest.php @@ -113,6 +113,5 @@ public function test_it_cleans_up_old_sessions() $this->assertSame(1, $handler->gc(300)); $this->assertSame('', $handler->read('foo')); $this->assertSame('qux', $handler->read('baz')); - } }