From 282534f39c6eae39caf4f96f003b0aca696a7973 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 28 Jun 2017 04:32:32 +0200 Subject: [PATCH] [5.5] Let Carbon be Macroable. (#19771) * Let Carbon be Macroable. * Require nesbot/carbon in illuminate/support and remove it everywhere else. * StyleCI fix. --- .../Passwords/DatabaseTokenRepository.php | 2 +- src/Illuminate/Auth/composer.json | 3 +- src/Illuminate/Cache/DatabaseStore.php | 2 +- src/Illuminate/Cache/FileStore.php | 2 +- src/Illuminate/Cache/MemcachedStore.php | 2 +- src/Illuminate/Cache/RateLimiter.php | 2 +- src/Illuminate/Cache/Repository.php | 2 +- src/Illuminate/Cache/composer.json | 3 +- src/Illuminate/Console/Scheduling/Event.php | 4 +- .../Console/Scheduling/ManagesFrequencies.php | 2 +- src/Illuminate/Console/composer.json | 1 - src/Illuminate/Cookie/CookieJar.php | 2 +- .../Eloquent/Concerns/HasAttributes.php | 6 +- .../Eloquent/Concerns/HasTimestamps.php | 4 +- src/Illuminate/Database/composer.json | 3 +- .../Foundation/Console/DownCommand.php | 2 +- .../Exceptions/MaintenanceModeException.php | 6 +- .../Http/Middleware/VerifyCsrfToken.php | 2 +- .../Messages/SlackAttachment.php | 2 +- .../Queue/Console/RestartCommand.php | 2 +- src/Illuminate/Queue/Console/WorkCommand.php | 2 +- src/Illuminate/Queue/DatabaseQueue.php | 2 +- .../Failed/DatabaseFailedJobProvider.php | 2 +- src/Illuminate/Queue/InteractsWithTime.php | 2 +- src/Illuminate/Queue/composer.json | 1 - .../Routing/Middleware/ThrottleRequests.php | 2 +- .../Session/CookieSessionHandler.php | 2 +- .../Session/DatabaseSessionHandler.php | 2 +- src/Illuminate/Session/FileSessionHandler.php | 2 +- .../Session/Middleware/StartSession.php | 2 +- src/Illuminate/Session/composer.json | 1 - src/Illuminate/Support/Carbon.php | 11 ++++ src/Illuminate/Support/composer.json | 3 +- .../Auth/AuthDatabaseTokenRepositoryTest.php | 2 +- tests/Cache/CacheFileStoreTest.php | 2 +- tests/Cache/CacheMemcachedStoreTest.php | 4 +- tests/Cache/CacheRepositoryTest.php | 2 +- tests/Console/ConsoleScheduledEventTest.php | 2 +- .../DatabaseEloquentIntegrationTest.php | 8 +-- tests/Database/DatabaseEloquentModelTest.php | 38 ++++++------ .../Database/DatabaseEloquentRelationTest.php | 2 +- ...baseEloquentSoftDeletesIntegrationTest.php | 2 +- .../DatabaseSoftDeletingTraitTest.php | 4 +- tests/Integration/Cache/CacheLockTest.php | 2 +- .../Database/EloquentModelTest.php | 2 +- .../NotificationSlackChannelTest.php | 4 +- .../QueueDatabaseQueueIntegrationTest.php | 2 +- tests/Queue/QueueRedisQueueTest.php | 2 +- tests/Queue/QueueSqsQueueTest.php | 2 +- tests/Queue/RedisQueueIntegrationTest.php | 2 +- tests/Support/SupportCarbonTest.php | 59 +++++++++++++++++++ tests/Validation/ValidationValidatorTest.php | 2 +- tests/bootstrap.php | 2 +- 53 files changed, 149 insertions(+), 84 deletions(-) create mode 100644 src/Illuminate/Support/Carbon.php create mode 100644 tests/Support/SupportCarbonTest.php diff --git a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php index aff32ca17b04..c4701759929d 100755 --- a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php +++ b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php @@ -2,8 +2,8 @@ namespace Illuminate\Auth\Passwords; -use Carbon\Carbon; use Illuminate\Support\Str; +use Illuminate\Support\Carbon; use Illuminate\Database\ConnectionInterface; use Illuminate\Contracts\Hashing\Hasher as HasherContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; diff --git a/src/Illuminate/Auth/composer.json b/src/Illuminate/Auth/composer.json index 148d184819b9..f3a41d953587 100644 --- a/src/Illuminate/Auth/composer.json +++ b/src/Illuminate/Auth/composer.json @@ -18,8 +18,7 @@ "illuminate/contracts": "5.5.*", "illuminate/http": "5.5.*", "illuminate/queue": "5.5.*", - "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20" + "illuminate/support": "5.5.*" }, "autoload": { "psr-4": { diff --git a/src/Illuminate/Cache/DatabaseStore.php b/src/Illuminate/Cache/DatabaseStore.php index 52fcd180411c..3428a4fb738f 100755 --- a/src/Illuminate/Cache/DatabaseStore.php +++ b/src/Illuminate/Cache/DatabaseStore.php @@ -4,7 +4,7 @@ use Closure; use Exception; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Cache\Store; use Illuminate\Database\ConnectionInterface; diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 90d49c0bc6af..a9a6cdc4a087 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -3,8 +3,8 @@ namespace Illuminate\Cache; use Exception; -use Carbon\Carbon; use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Cache\Store; use Illuminate\Filesystem\Filesystem; diff --git a/src/Illuminate/Cache/MemcachedStore.php b/src/Illuminate/Cache/MemcachedStore.php index ac95df3c6897..4311f3bcc8d4 100755 --- a/src/Illuminate/Cache/MemcachedStore.php +++ b/src/Illuminate/Cache/MemcachedStore.php @@ -3,8 +3,8 @@ namespace Illuminate\Cache; use Memcached; -use Carbon\Carbon; use ReflectionMethod; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Cache\Store; use Illuminate\Contracts\Cache\LockProvider; diff --git a/src/Illuminate/Cache/RateLimiter.php b/src/Illuminate/Cache/RateLimiter.php index 8a277fd4e506..c6460b8aa094 100644 --- a/src/Illuminate/Cache/RateLimiter.php +++ b/src/Illuminate/Cache/RateLimiter.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Cache\Repository as Cache; class RateLimiter diff --git a/src/Illuminate/Cache/Repository.php b/src/Illuminate/Cache/Repository.php index 8498d9f1a81e..0b81638960e4 100755 --- a/src/Illuminate/Cache/Repository.php +++ b/src/Illuminate/Cache/Repository.php @@ -5,8 +5,8 @@ use Closure; use DateTime; use ArrayAccess; -use Carbon\Carbon; use BadMethodCallException; +use Illuminate\Support\Carbon; use Illuminate\Cache\Events\CacheHit; use Illuminate\Contracts\Cache\Store; use Illuminate\Cache\Events\KeyWritten; diff --git a/src/Illuminate/Cache/composer.json b/src/Illuminate/Cache/composer.json index e1393ef09f2a..f81a218c707e 100755 --- a/src/Illuminate/Cache/composer.json +++ b/src/Illuminate/Cache/composer.json @@ -16,8 +16,7 @@ "require": { "php": ">=7.0", "illuminate/contracts": "5.5.*", - "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20" + "illuminate/support": "5.5.*" }, "autoload": { "psr-4": { diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index d48b93de5568..d1abcbd97a53 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -3,8 +3,8 @@ namespace Illuminate\Console\Scheduling; use Closure; -use Carbon\Carbon; use Cron\CronExpression; +use Illuminate\Support\Carbon; use GuzzleHttp\Client as HttpClient; use Illuminate\Contracts\Mail\Mailer; use Symfony\Component\Process\Process; @@ -629,7 +629,7 @@ public function getSummaryForDisplay() * @param \DateTime|string $currentTime * @param int $nth * @param bool $allowCurrentDate - * @return \Carbon\Carbon + * @return \Illuminate\Support\Carbon */ public function nextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) { diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 637134a849ad..58d3e303761b 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -2,7 +2,7 @@ namespace Illuminate\Console\Scheduling; -use Carbon\Carbon; +use Illuminate\Support\Carbon; trait ManagesFrequencies { diff --git a/src/Illuminate/Console/composer.json b/src/Illuminate/Console/composer.json index 09c55724a1a0..6e432e03e59f 100755 --- a/src/Illuminate/Console/composer.json +++ b/src/Illuminate/Console/composer.json @@ -17,7 +17,6 @@ "php": ">=7.0", "illuminate/contracts": "5.5.*", "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20", "symfony/console": "~3.3" }, "autoload": { diff --git a/src/Illuminate/Cookie/CookieJar.php b/src/Illuminate/Cookie/CookieJar.php index 1881bc31f1ac..2dcec7cc6306 100755 --- a/src/Illuminate/Cookie/CookieJar.php +++ b/src/Illuminate/Cookie/CookieJar.php @@ -2,8 +2,8 @@ namespace Illuminate\Cookie; -use Carbon\Carbon; use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; use Symfony\Component\HttpFoundation\Cookie; use Illuminate\Contracts\Cookie\QueueingFactory as JarContract; diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index e436550942dd..af8fdbc17894 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -2,11 +2,11 @@ namespace Illuminate\Database\Eloquent\Concerns; -use Carbon\Carbon; use LogicException; use DateTimeInterface; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Collection as BaseCollection; @@ -656,7 +656,7 @@ public function fromJson($value, $asObject = false) * Return a timestamp as DateTime object with time set to 00:00:00. * * @param mixed $value - * @return \Carbon\Carbon + * @return \Illuminate\Support\Carbon */ protected function asDate($value) { @@ -667,7 +667,7 @@ protected function asDate($value) * Return a timestamp as DateTime object. * * @param mixed $value - * @return \Carbon\Carbon + * @return \Illuminate\Support\Carbon */ protected function asDateTime($value) { diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php index ba640fe4b54d..294b22ade94f 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php @@ -2,7 +2,7 @@ namespace Illuminate\Database\Eloquent\Concerns; -use Carbon\Carbon; +use Illuminate\Support\Carbon; trait HasTimestamps { @@ -76,7 +76,7 @@ public function setUpdatedAt($value) /** * Get a fresh timestamp for the model. * - * @return \Carbon\Carbon + * @return \Illuminate\Support\Carbon */ public function freshTimestamp() { diff --git a/src/Illuminate/Database/composer.json b/src/Illuminate/Database/composer.json index 6849440a3e31..153abad646f2 100644 --- a/src/Illuminate/Database/composer.json +++ b/src/Illuminate/Database/composer.json @@ -18,8 +18,7 @@ "php": ">=7.0", "illuminate/container": "5.5.*", "illuminate/contracts": "5.5.*", - "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20" + "illuminate/support": "5.5.*" }, "autoload": { "psr-4": { diff --git a/src/Illuminate/Foundation/Console/DownCommand.php b/src/Illuminate/Foundation/Console/DownCommand.php index 358a5841d0ae..af754f85494b 100644 --- a/src/Illuminate/Foundation/Console/DownCommand.php +++ b/src/Illuminate/Foundation/Console/DownCommand.php @@ -2,7 +2,7 @@ namespace Illuminate\Foundation\Console; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Console\Command; class DownCommand extends Command diff --git a/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php b/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php index 6ee1de62f77f..6d5a2ab71f27 100644 --- a/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php +++ b/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php @@ -3,7 +3,7 @@ namespace Illuminate\Foundation\Http\Exceptions; use Exception; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; class MaintenanceModeException extends ServiceUnavailableHttpException @@ -11,7 +11,7 @@ class MaintenanceModeException extends ServiceUnavailableHttpException /** * When the application was put in maintenance mode. * - * @var \Carbon\Carbon + * @var \Illuminate\Support\Carbon */ public $wentDownAt; @@ -25,7 +25,7 @@ class MaintenanceModeException extends ServiceUnavailableHttpException /** * When the application should next be available. * - * @var \Carbon\Carbon + * @var \Illuminate\Support\Carbon */ public $willBeAvailableAt; diff --git a/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php b/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php index 3a3944ec2afb..2e4337c91d88 100644 --- a/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php +++ b/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php @@ -3,7 +3,7 @@ namespace Illuminate\Foundation\Http\Middleware; use Closure; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Foundation\Application; use Symfony\Component\HttpFoundation\Cookie; use Illuminate\Contracts\Encryption\Encrypter; diff --git a/src/Illuminate/Notifications/Messages/SlackAttachment.php b/src/Illuminate/Notifications/Messages/SlackAttachment.php index 377bcb7633e2..a0a84abf7894 100644 --- a/src/Illuminate/Notifications/Messages/SlackAttachment.php +++ b/src/Illuminate/Notifications/Messages/SlackAttachment.php @@ -2,7 +2,7 @@ namespace Illuminate\Notifications\Messages; -use Carbon\Carbon; +use Illuminate\Support\Carbon; class SlackAttachment { diff --git a/src/Illuminate/Queue/Console/RestartCommand.php b/src/Illuminate/Queue/Console/RestartCommand.php index 4d9b58781846..41db41c08edf 100644 --- a/src/Illuminate/Queue/Console/RestartCommand.php +++ b/src/Illuminate/Queue/Console/RestartCommand.php @@ -2,7 +2,7 @@ namespace Illuminate\Queue\Console; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Console\Command; class RestartCommand extends Command diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index c430881d8477..12b7d98fc0ae 100644 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -2,8 +2,8 @@ namespace Illuminate\Queue\Console; -use Carbon\Carbon; use Illuminate\Queue\Worker; +use Illuminate\Support\Carbon; use Illuminate\Console\Command; use Illuminate\Contracts\Queue\Job; use Illuminate\Queue\WorkerOptions; diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 28c032ef7411..014defb3ce49 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -2,7 +2,7 @@ namespace Illuminate\Queue; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Database\Connection; use Illuminate\Queue\Jobs\DatabaseJob; use Illuminate\Queue\Jobs\DatabaseJobRecord; diff --git a/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php b/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php index 8312e541410b..e50a3613a53c 100644 --- a/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php +++ b/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php @@ -2,7 +2,7 @@ namespace Illuminate\Queue\Failed; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Database\ConnectionResolverInterface; class DatabaseFailedJobProvider implements FailedJobProviderInterface diff --git a/src/Illuminate/Queue/InteractsWithTime.php b/src/Illuminate/Queue/InteractsWithTime.php index 92a881f0b339..b89d282d9d5a 100644 --- a/src/Illuminate/Queue/InteractsWithTime.php +++ b/src/Illuminate/Queue/InteractsWithTime.php @@ -2,8 +2,8 @@ namespace Illuminate\Queue; -use Carbon\Carbon; use DateTimeInterface; +use Illuminate\Support\Carbon; trait InteractsWithTime { diff --git a/src/Illuminate/Queue/composer.json b/src/Illuminate/Queue/composer.json index 59410f41d4b9..c8d582ac8799 100644 --- a/src/Illuminate/Queue/composer.json +++ b/src/Illuminate/Queue/composer.json @@ -21,7 +21,6 @@ "illuminate/database": "5.5.*", "illuminate/filesystem": "5.5.*", "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20", "symfony/debug": "~3.3", "symfony/process": "~3.3" }, diff --git a/src/Illuminate/Routing/Middleware/ThrottleRequests.php b/src/Illuminate/Routing/Middleware/ThrottleRequests.php index 5d0af90d1f38..c435930c97c6 100644 --- a/src/Illuminate/Routing/Middleware/ThrottleRequests.php +++ b/src/Illuminate/Routing/Middleware/ThrottleRequests.php @@ -3,7 +3,7 @@ namespace Illuminate\Routing\Middleware; use Closure; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Cache\RateLimiter; use Symfony\Component\HttpFoundation\Response; diff --git a/src/Illuminate/Session/CookieSessionHandler.php b/src/Illuminate/Session/CookieSessionHandler.php index 95b7bcc02a84..be93e7667164 100755 --- a/src/Illuminate/Session/CookieSessionHandler.php +++ b/src/Illuminate/Session/CookieSessionHandler.php @@ -2,8 +2,8 @@ namespace Illuminate\Session; -use Carbon\Carbon; use SessionHandlerInterface; +use Illuminate\Support\Carbon; use Symfony\Component\HttpFoundation\Request; use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar; diff --git a/src/Illuminate/Session/DatabaseSessionHandler.php b/src/Illuminate/Session/DatabaseSessionHandler.php index b095a24cd4b1..ae0e1ee56c77 100644 --- a/src/Illuminate/Session/DatabaseSessionHandler.php +++ b/src/Illuminate/Session/DatabaseSessionHandler.php @@ -2,9 +2,9 @@ namespace Illuminate\Session; -use Carbon\Carbon; use Illuminate\Support\Arr; use SessionHandlerInterface; +use Illuminate\Support\Carbon; use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\QueryException; use Illuminate\Database\ConnectionInterface; diff --git a/src/Illuminate/Session/FileSessionHandler.php b/src/Illuminate/Session/FileSessionHandler.php index 4f72525804a0..6e472f80bff5 100644 --- a/src/Illuminate/Session/FileSessionHandler.php +++ b/src/Illuminate/Session/FileSessionHandler.php @@ -2,8 +2,8 @@ namespace Illuminate\Session; -use Carbon\Carbon; use SessionHandlerInterface; +use Illuminate\Support\Carbon; use Symfony\Component\Finder\Finder; use Illuminate\Filesystem\Filesystem; diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index ca523b934614..e3bcc769c24a 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -3,9 +3,9 @@ namespace Illuminate\Session\Middleware; use Closure; -use Carbon\Carbon; use Illuminate\Support\Arr; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; use Illuminate\Session\SessionManager; use Illuminate\Contracts\Session\Session; use Illuminate\Session\CookieSessionHandler; diff --git a/src/Illuminate/Session/composer.json b/src/Illuminate/Session/composer.json index 6ab7b122b6c8..a854c506b2b4 100755 --- a/src/Illuminate/Session/composer.json +++ b/src/Illuminate/Session/composer.json @@ -18,7 +18,6 @@ "illuminate/contracts": "5.5.*", "illuminate/filesystem": "5.5.*", "illuminate/support": "5.5.*", - "nesbot/carbon": "~1.20", "symfony/finder": "~3.3", "symfony/http-foundation": "~3.3" }, diff --git a/src/Illuminate/Support/Carbon.php b/src/Illuminate/Support/Carbon.php new file mode 100644 index 000000000000..cd96db351d77 --- /dev/null +++ b/src/Illuminate/Support/Carbon.php @@ -0,0 +1,11 @@ +=7.0", "ext-mbstring": "*", "doctrine/inflector": "~1.0", - "illuminate/contracts": "5.5.*" + "illuminate/contracts": "5.5.*", + "nesbot/carbon": "^1.20" }, "replace": { "tightenco/collect": "self.version" diff --git a/tests/Auth/AuthDatabaseTokenRepositoryTest.php b/tests/Auth/AuthDatabaseTokenRepositoryTest.php index a2cf05519a9b..ee3c05ca2b3d 100755 --- a/tests/Auth/AuthDatabaseTokenRepositoryTest.php +++ b/tests/Auth/AuthDatabaseTokenRepositoryTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Auth; use Mockery as m; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Auth\Passwords\DatabaseTokenRepository; diff --git a/tests/Cache/CacheFileStoreTest.php b/tests/Cache/CacheFileStoreTest.php index f7ee0e885eb5..298a89d11e9f 100755 --- a/tests/Cache/CacheFileStoreTest.php +++ b/tests/Cache/CacheFileStoreTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Cache; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use Illuminate\Cache\FileStore; use PHPUnit\Framework\TestCase; use Illuminate\Contracts\Filesystem\FileNotFoundException; diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index 334c24e29513..5bbebf0a25d7 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -63,12 +63,12 @@ public function testSetMethodProperlyCallsMemcache() $this->markTestSkipped('Memcached module not installed'); } - \Carbon\Carbon::setTestNow($now = \Carbon\Carbon::now()); + \Illuminate\Support\Carbon::setTestNow($now = \Illuminate\Support\Carbon::now()); $memcache = $this->getMockBuilder('Memcached')->setMethods(['set'])->getMock(); $memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo($now->timestamp + 60)); $store = new MemcachedStore($memcache); $store->put('foo', 'bar', 1); - \Carbon\Carbon::setTestNow(); + \Illuminate\Support\Carbon::setTestNow(); } public function testIncrementMethodProperlyCallsMemcache() diff --git a/tests/Cache/CacheRepositoryTest.php b/tests/Cache/CacheRepositoryTest.php index 1018cea2fef0..fc7114097697 100755 --- a/tests/Cache/CacheRepositoryTest.php +++ b/tests/Cache/CacheRepositoryTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Cache; use Mockery as m; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; class CacheRepositoryTest extends TestCase diff --git a/tests/Console/ConsoleScheduledEventTest.php b/tests/Console/ConsoleScheduledEventTest.php index 2cc685de730a..4e2d83d90302 100644 --- a/tests/Console/ConsoleScheduledEventTest.php +++ b/tests/Console/ConsoleScheduledEventTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Console; use Mockery as m; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Console\Scheduling\Event; diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index c0608f6fd576..cfd15ccbe6f9 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -569,8 +569,8 @@ public function testHasOnSelfReferencingBelongsToRelationship() public function testAggregatedValuesOfDatetimeField() { - EloquentTestUser::create(['id' => 1, 'email' => 'test1@test.test', 'created_at' => '2016-08-10 09:21:00', 'updated_at' => \Carbon\Carbon::now()]); - EloquentTestUser::create(['id' => 2, 'email' => 'test2@test.test', 'created_at' => '2016-08-01 12:00:00', 'updated_at' => \Carbon\Carbon::now()]); + EloquentTestUser::create(['id' => 1, 'email' => 'test1@test.test', 'created_at' => '2016-08-10 09:21:00', 'updated_at' => \Illuminate\Support\Carbon::now()]); + EloquentTestUser::create(['id' => 2, 'email' => 'test2@test.test', 'created_at' => '2016-08-01 12:00:00', 'updated_at' => \Illuminate\Support\Carbon::now()]); $this->assertEquals('2016-08-10 09:21:00', EloquentTestUser::max('created_at')); $this->assertEquals('2016-08-01 12:00:00', EloquentTestUser::min('created_at')); @@ -1090,8 +1090,8 @@ public function testIsAfterRetrievingTheSameModel() public function testFreshMethodOnModel() { - $now = \Carbon\Carbon::now(); - \Carbon\Carbon::setTestNow($now); + $now = \Illuminate\Support\Carbon::now(); + \Illuminate\Support\Carbon::setTestNow($now); $storedUser1 = EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); $storedUser1->newQuery()->update(['email' => 'dev@mathieutu.ovh', 'name' => 'Mathieu TUDISCO']); diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index f820bfddb4b4..09cebab956f8 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -6,11 +6,11 @@ use stdClass; use Exception; use Mockery as m; -use Carbon\Carbon; use LogicException; use ReflectionClass; use DateTimeImmutable; use DateTimeInterface; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; @@ -33,7 +33,7 @@ public function tearDown() Carbon::setTestNow(null); \Illuminate\Database\Eloquent\Model::unsetEventDispatcher(); - \Carbon\Carbon::resetToStringFormat(); + \Illuminate\Support\Carbon::resetToStringFormat(); } public function testAttributeManipulation() @@ -352,8 +352,8 @@ public function testTimestampsAreReturnedAsObjects() 'updated_at' => '2012-12-05', ]); - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); - $this->assertInstanceOf('Carbon\Carbon', $model->updated_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->updated_at); } public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps() @@ -365,15 +365,15 @@ public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps() 'updated_at' => Carbon::now()->getTimestamp(), ]); - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); - $this->assertInstanceOf('Carbon\Carbon', $model->updated_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->updated_at); } public function testTimestampsAreReturnedAsObjectsOnCreate() { $timestamps = [ - 'created_at' => \Carbon\Carbon::now(), - 'updated_at' => \Carbon\Carbon::now(), + 'created_at' => \Illuminate\Support\Carbon::now(), + 'updated_at' => \Illuminate\Support\Carbon::now(), ]; $model = new EloquentDateModelStub; \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface')); @@ -381,15 +381,15 @@ public function testTimestampsAreReturnedAsObjectsOnCreate() $mockConnection->shouldReceive('getQueryGrammar')->andReturn($mockConnection); $mockConnection->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s'); $instance = $model->newInstance($timestamps); - $this->assertInstanceOf('Carbon\Carbon', $instance->updated_at); - $this->assertInstanceOf('Carbon\Carbon', $instance->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $instance->updated_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $instance->created_at); } public function testDateTimeAttributesReturnNullIfSetToNull() { $timestamps = [ - 'created_at' => \Carbon\Carbon::now(), - 'updated_at' => \Carbon\Carbon::now(), + 'created_at' => \Illuminate\Support\Carbon::now(), + 'updated_at' => \Illuminate\Support\Carbon::now(), ]; $model = new EloquentDateModelStub; \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface')); @@ -406,26 +406,26 @@ public function testTimestampsAreCreatedFromStringsAndIntegers() { $model = new EloquentDateModelStub; $model->created_at = '2013-05-22 00:00:00'; - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = Carbon::now()->getTimestamp(); - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = 0; - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = '2012-01-01'; - $this->assertInstanceOf('Carbon\Carbon', $model->created_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); } public function testFromDateTime() { $model = new EloquentModelStub; - $value = \Carbon\Carbon::parse('2015-04-17 22:59:01'); + $value = \Illuminate\Support\Carbon::parse('2015-04-17 22:59:01'); $this->assertEquals('2015-04-17 22:59:01', $model->fromDateTime($value)); $value = new DateTime('2015-04-17 22:59:01'); @@ -1446,8 +1446,8 @@ public function testModelAttributesAreCastedWhenPresentInCastsArray() $this->assertEquals(['foo' => 'bar'], $model->arrayAttribute); $this->assertEquals(['foo' => 'bar'], $model->jsonAttribute); $this->assertEquals('{"foo":"bar"}', $model->jsonAttributeValue()); - $this->assertInstanceOf('Carbon\Carbon', $model->dateAttribute); - $this->assertInstanceOf('Carbon\Carbon', $model->datetimeAttribute); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->dateAttribute); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->datetimeAttribute); $this->assertEquals('1969-07-20', $model->dateAttribute->toDateString()); $this->assertEquals('1969-07-20 22:56:00', $model->datetimeAttribute->toDateTimeString()); $this->assertEquals(-14173440, $model->timestampAttribute); diff --git a/tests/Database/DatabaseEloquentRelationTest.php b/tests/Database/DatabaseEloquentRelationTest.php index eecd74523476..e69bbdfabaa8 100755 --- a/tests/Database/DatabaseEloquentRelationTest.php +++ b/tests/Database/DatabaseEloquentRelationTest.php @@ -36,7 +36,7 @@ public function testTouchMethodUpdatesRelatedTimestamps() $relation = new HasOne($builder, $parent, 'foreign_key', 'id'); $related->shouldReceive('getTable')->andReturn('table'); $related->shouldReceive('getUpdatedAtColumn')->andReturn('updated_at'); - $now = \Carbon\Carbon::now(); + $now = \Illuminate\Support\Carbon::now(); $related->shouldReceive('freshTimestampString')->andReturn($now); $builder->shouldReceive('update')->once()->with(['updated_at' => $now]); diff --git a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php index 15014df0e703..a2bff93c468c 100644 --- a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php +++ b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Database; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; use Illuminate\Pagination\Paginator; diff --git a/tests/Database/DatabaseSoftDeletingTraitTest.php b/tests/Database/DatabaseSoftDeletingTraitTest.php index 9a16ab35908c..9efae44a130b 100644 --- a/tests/Database/DatabaseSoftDeletingTraitTest.php +++ b/tests/Database/DatabaseSoftDeletingTraitTest.php @@ -25,7 +25,7 @@ public function testDeleteSetsSoftDeletedColumn() ]); $model->delete(); - $this->assertInstanceOf('Carbon\Carbon', $model->deleted_at); + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->deleted_at); } public function testRestore() @@ -91,7 +91,7 @@ public function fireModelEvent() public function freshTimestamp() { - return \Carbon\Carbon::now(); + return \Illuminate\Support\Carbon::now(); } public function fromDateTime() diff --git a/tests/Integration/Cache/CacheLockTest.php b/tests/Integration/Cache/CacheLockTest.php index 898d7c4ba33a..9f5967a4ec0e 100644 --- a/tests/Integration/Cache/CacheLockTest.php +++ b/tests/Integration/Cache/CacheLockTest.php @@ -1,6 +1,6 @@ fill([ - 'nullable_date' => $now = \Carbon\Carbon::now(), + 'nullable_date' => $now = \Illuminate\Support\Carbon::now(), ]); $this->assertTrue($user->isDirty('nullable_date')); diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 3800c02745b6..996914e61ef2 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -176,7 +176,7 @@ public function toSlack($notifiable) ->to('#ghost-talk') ->content('Content') ->attachment(function ($attachment) { - $timestamp = Mockery::mock('Carbon\Carbon'); + $timestamp = Mockery::mock(\Illuminate\Support\Carbon::class); $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); $attachment->title('Laravel', 'https://laravel.com') ->content('Attachment Content') @@ -202,7 +202,7 @@ public function toSlack($notifiable) ->to('#ghost-talk') ->content('Content') ->attachment(function ($attachment) { - $timestamp = Mockery::mock('Carbon\Carbon'); + $timestamp = Mockery::mock(\Illuminate\Support\Carbon::class); $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); $attachment->title('Laravel', 'https://laravel.com') ->content('Attachment Content') diff --git a/tests/Queue/QueueDatabaseQueueIntegrationTest.php b/tests/Queue/QueueDatabaseQueueIntegrationTest.php index 495ea7848aa5..f4fa2dd327dd 100644 --- a/tests/Queue/QueueDatabaseQueueIntegrationTest.php +++ b/tests/Queue/QueueDatabaseQueueIntegrationTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Queue; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Queue\DatabaseQueue; diff --git a/tests/Queue/QueueRedisQueueTest.php b/tests/Queue/QueueRedisQueueTest.php index 99cc844de580..0ad436ff3042 100644 --- a/tests/Queue/QueueRedisQueueTest.php +++ b/tests/Queue/QueueRedisQueueTest.php @@ -42,7 +42,7 @@ public function testDelayedPushProperlyPushesJobOntoRedis() public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis() { - $date = \Carbon\Carbon::now(); + $date = \Illuminate\Support\Carbon::now(); $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['availableAt', 'getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Contracts\Redis\Factory'), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $queue->expects($this->once())->method('availableAt')->with($date)->will($this->returnValue(2)); diff --git a/tests/Queue/QueueSqsQueueTest.php b/tests/Queue/QueueSqsQueueTest.php index 1ae3122330b2..63a006d45c63 100755 --- a/tests/Queue/QueueSqsQueueTest.php +++ b/tests/Queue/QueueSqsQueueTest.php @@ -71,7 +71,7 @@ public function testPopProperlyPopsJobOffOfSqs() public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs() { - $now = \Carbon\Carbon::now(); + $now = \Illuminate\Support\Carbon::now(); $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['createPayload', 'secondsUntil', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock(); $queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->mockedData)->will($this->returnValue($this->mockedPayload)); $queue->expects($this->once())->method('secondsUntil')->with($now)->will($this->returnValue(5)); diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index 9f7c1aa5cdae..31566d026eb2 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Queue; use Mockery as m; -use Carbon\Carbon; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Queue\RedisQueue; use Illuminate\Container\Container; diff --git a/tests/Support/SupportCarbonTest.php b/tests/Support/SupportCarbonTest.php new file mode 100644 index 000000000000..a1be282516d9 --- /dev/null +++ b/tests/Support/SupportCarbonTest.php @@ -0,0 +1,59 @@ +diffInYears($dt, $abs) / 10); + }); + + $this->assertSame(2, Carbon::now()->diffInDecades(Carbon::now()->addYears(25))); + } + + public function testCarbonIsMacroableWhenCalledStatically() + { + Carbon::macro('twoDaysAgoAtNoon', function () { + return Carbon::now()->subDays(2)->setTime(12, 0, 0); + }); + + $this->assertSame('2017-06-25 12:00:00', Carbon::twoDaysAgoAtNoon()->toDateTimeString()); + } + + /** + * @expectedException \BadMethodCallException + * @expectedExceptionMessage Method nonExistingStaticMacro does not exist. + */ + public function testCarbonRaisesExceptionWhenStaticMacroIsNotFound() + { + Carbon::nonExistingStaticMacro(); + } + + /** + * @expectedException \BadMethodCallException + * @expectedExceptionMessage Method nonExistingMacro does not exist. + */ + public function testCarbonRaisesExceptionWhenMacroIsNotFound() + { + Carbon::now()->nonExistingMacro(); + } +} diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index c440b84866a0..5e7d276c0ca0 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -4,8 +4,8 @@ use DateTime; use Mockery as m; -use Carbon\Carbon; use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Validation\Validator; use Illuminate\Validation\Rules\Exists; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1b463b11b9d0..bc3941498e01 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,7 +14,7 @@ require __DIR__.'/../vendor/autoload.php'; -use Carbon\Carbon; +use Illuminate\Support\Carbon; /* |--------------------------------------------------------------------------