diff --git a/CHANGELOG-5.5.md b/CHANGELOG-5.5.md index 2ad507c901bd..dc612357c81c 100644 --- a/CHANGELOG-5.5.md +++ b/CHANGELOG-5.5.md @@ -8,14 +8,14 @@ - ⚠️ Removed deprecated `Str::quickRandom()` method ([2ef257a](https://github.com/laravel/framework/pull/17048/commits/2ef257a4197b7e6efeb0d6ac4a3958f82b7fed39)) - Removed `build` scripts ([7c16b15](https://github.com/laravel/framework/pull/17048/commits/7c16b154ede10ff9a37756e32d7dddf317524634)) - Support callable/invokable objects in `Pipeline` ([#18264](https://github.com/laravel/framework/pull/18264)) -- Support for `Responsable` objects ([c0c89fd](https://github.com/laravel/framework/commit/c0c89fd73cebf9ed56e6c5e69ad35106df03d9db), [1229b7f](https://github.com/laravel/framework/commit/1229b7f45d3f574d7e0262cc2d5aec80ccbb1626), [#19614](https://github.com/laravel/framework/pull/19614)) +- Support for `Responsable` objects ([c0c89fd](https://github.com/laravel/framework/commit/c0c89fd73cebf9ed56e6c5e69ad35106df03d9db), [1229b7f](https://github.com/laravel/framework/commit/1229b7f45d3f574d7e0262cc2d5aec80ccbb1626), [#19614](https://github.com/laravel/framework/pull/19614), [ef0e37d](https://github.com/laravel/framework/commit/ef0e37d44182ac5043b5459bb25b1861e8e036df)) - ⚠️ Prevent access to protected properties using array access on `Model` and `Fluent` ([#18403](https://github.com/laravel/framework/pull/18403)) - ⚠️ Extend `MessageBag` interface from `Arrayable` ([#19768](https://github.com/laravel/framework/pull/19768)) - Added `isNotEmpty()` method to message bags and paginators ([#19944](https://github.com/laravel/framework/pull/19944)) - Return the collection iterator from `AbstractPaginator::getIterator()` ([#20098](https://github.com/laravel/framework/pull/20098)) - Throw `RuntimeException` when app key is missing ([#19145](https://github.com/laravel/framework/pull/19145), [8adbaa7](https://github.com/laravel/framework/commit/8adbaa714d37bb7214f29b12c52354900a1c6dc5)) - Autoload package providers ([#19420](https://github.com/laravel/framework/pull/19420), [a5a0f3e](https://github.com/laravel/framework/commit/a5a0f3e7b82a1a4dc00037c5463a31d42c94903a), [2954091](https://github.com/laravel/framework/commit/295409189af589c6389d01e9d55f5568741149ee), [#19455](https://github.com/laravel/framework/pull/19455), [#19561](https://github.com/laravel/framework/pull/19561), [#19646](https://github.com/laravel/framework/pull/19646)) -- Use Symfony 3.3 components ([4db7031](https://github.com/laravel/framework/commit/4db70311b1b3813359b250d3f5a58743fa436453), [67a5367](https://github.com/laravel/framework/commit/67a536758d1636935ab5502bb6faedd73b30810f)) +- Upgraded to Symfony 3.3 components ([4db7031](https://github.com/laravel/framework/commit/4db70311b1b3813359b250d3f5a58743fa436453), [67a5367](https://github.com/laravel/framework/commit/67a536758d1636935ab5502bb6faedd73b30810f)) - Support registering macros using classes ([#19782](https://github.com/laravel/framework/pull/19782), [353adbd](https://github.com/laravel/framework/commit/353adbd696e36764227e39980272d38147899d14)) - Made `Carbon` macroable ([#19771](https://github.com/laravel/framework/pull/19771)) - ⚠️ Moved `InteractsWithTime` to `Illuminate\Support` ([#20119](https://github.com/laravel/framework/pull/20119), [#20206](https://github.com/laravel/framework/pull/20206)) @@ -36,6 +36,8 @@ - Generate `make:policy` with real user model namespace ([#20047](https://github.com/laravel/framework/pull/20047)) - Added `Kernel::load()` to auto register a directory of commands ([2e7ddca](https://github.com/laravel/framework/commit/2e7ddca682214ea5ffd21aadc93d33b7a2805e94), [d607b9c](https://github.com/laravel/framework/commit/d607b9c670d9c7f7c749cda0a12a1dc6f55da6e4)) - ⚠️ Removed `array` type hint from `Command::table()` ([#20120](https://github.com/laravel/framework/pull/20120)) +- Support loading multiple paths in `Kernel::load()` ([#20251](https://github.com/laravel/framework/pull/20251)) +- Added `CommandStarting` and `CommandFinished` events ([#20298](https://github.com/laravel/framework/pull/20298)) ### Assets - Added frontend preset commands (_too many commits, sorry_) @@ -61,9 +63,10 @@ ### Broadcasting - ⚠️ Use `AccessDeniedHttpException` instead if `HttpException` ([#19611](https://github.com/laravel/framework/pull/19611)) -- ⚠️ Upgraded to Pusher v3 ([#20016](https://github.com/laravel/framework/pull/20016)) +- ⚠️ Upgraded to Pusher SDK v3 ([#20016](https://github.com/laravel/framework/pull/20016)) ### Cache +- ⚠️ PSR-16 compliance ([#20194](https://github.com/laravel/framework/pull/20194)) - Don't encrypt database cache values ([f0c72ec](https://github.com/laravel/framework/commit/f0c72ec9bcbdecb7e6267f7ec8f7ecbf8169a388)) - Added support cache locks ([4e6b2e4](https://github.com/laravel/framework/commit/4e6b2e4ecbbec5a4b265f4d5a57ad1399227cf12), [045e6f2](https://github.com/laravel/framework/commit/045e6f25a860763942c928c4e6d8857d59741486), [#19669](https://github.com/laravel/framework/pull/19669)) - Accept `DatetimeInterface` and `DateInterval` in cache repository ([#20034](https://github.com/laravel/framework/pull/20034)) @@ -83,7 +86,7 @@ - ⚠️ Removed `Controller::missingMethod()` ([bf5d221](https://github.com/laravel/framework/commit/bf5d221037d9857a74020f2623839e282035a420)) ### Database -- ⚠️ Added `dropAllTables()` to schema builder ([#18484](https://github.com/laravel/framework/pull/18484), [d910bc8](https://github.com/laravel/framework/commit/d910bc8039f3cec2d906797818984e825601a3f5), [#19644](https://github.com/laravel/framework/pull/19644), [#19645](https://github.com/laravel/framework/pull/19645)) +- ⚠️ Added `dropAllTables()` to schema builder ([#18484](https://github.com/laravel/framework/pull/18484), [d910bc8](https://github.com/laravel/framework/commit/d910bc8039f3cec2d906797818984e825601a3f5), [#19644](https://github.com/laravel/framework/pull/19644), [#19645](https://github.com/laravel/framework/pull/19645), [#20239](https://github.com/laravel/framework/pull/20239)) - Added precision to `dateTime` and `timestamp` column types ([#18847](https://github.com/laravel/framework/pull/18847), [f85f6db](https://github.com/laravel/framework/commit/f85f6db7c00a43ae45d963d089458477cf3e44b3), [#18962](https://github.com/laravel/framework/pull/18962)) - Pass page number to `chunk()` callback ([#19316](https://github.com/laravel/framework/pull/19316)) - Improve memory usage in `chunk()` and `chunkById()` ([#19345](https://github.com/laravel/framework/pull/19345), [#19369](https://github.com/laravel/framework/pull/19369), [#19368](https://github.com/laravel/framework/pull/19368)) @@ -114,6 +117,7 @@ - Added `Relation::get()` method ([#20052](https://github.com/laravel/framework/pull/20052)) - Added `hasChanges()`, `wasChanged()`, `getChanges()` and `syncChanges()` ([#20129](https://github.com/laravel/framework/pull/20129), [#20130](https://github.com/laravel/framework/pull/20130)) - Better exception message when calling non existing methods on models ([#20196](https://github.com/laravel/framework/pull/20196), [91c1f03](https://github.com/laravel/framework/commit/91c1f03be2835f5b15998ead9f47f37d5397c0cc)) +- Added support for connections on model factories ([#20191](https://github.com/laravel/framework/pull/20191)) ### Encryption - Use `openssl_cipher_iv_length()` in `Encrypter` ([#18684](https://github.com/laravel/framework/pull/18684)) @@ -134,7 +138,7 @@ - Changed how exceptions are logged ([#19698](https://github.com/laravel/framework/pull/19698), [f1971c2](https://github.com/laravel/framework/commit/f1971c2242e4882440162fe504126a1475f7f2b4)) - ⚠️ Return `HttpException` with code `413` from `PostTooLargeException` ([#19773](https://github.com/laravel/framework/pull/19773)) - Support custom logger channel names ([#20133](https://github.com/laravel/framework/pull/20133)) -- ⚠️ Unify exception formatting ([#20173](https://github.com/laravel/framework/pull/20173), [#20067](https://github.com/laravel/framework/pull/20067), [#20167](https://github.com/laravel/framework/pull/20167), [87485e6](https://github.com/laravel/framework/commit/87485e681ca658978f8a131fd0b783ac8c8bab61), [b7e231b](https://github.com/laravel/framework/commit/b7e231b99aecb95a26ec89e5fe73346d4fad7fdc), [5dfe72d](https://github.com/laravel/framework/commit/5dfe72d790ef68cbacd329a351e4706b30422acd), [#20177](https://github.com/laravel/framework/pull/20177)) +- ⚠️ Unify exception formatting ([#20173](https://github.com/laravel/framework/pull/20173), [#20067](https://github.com/laravel/framework/pull/20067), [#20167](https://github.com/laravel/framework/pull/20167), [87485e6](https://github.com/laravel/framework/commit/87485e681ca658978f8a131fd0b783ac8c8bab61), [b7e231b](https://github.com/laravel/framework/commit/b7e231b99aecb95a26ec89e5fe73346d4fad7fdc), [5dfe72d](https://github.com/laravel/framework/commit/5dfe72d790ef68cbacd329a351e4706b30422acd), [#20177](https://github.com/laravel/framework/pull/20177), [b3b3eb1](https://github.com/laravel/framework/commit/b3b3eb1b974dd9f126d0ea7c279092c0b050628a)) - Added default `Handler::unauthenticated()` method ([11b0de0](https://github.com/laravel/framework/commit/11b0de0485632d5712f7fb59071a4acbc4af2bdc)) ### Events @@ -184,7 +188,8 @@ - Accept `DatetimeInterface` and `DateInterval` in queue ([#20102](https://github.com/laravel/framework/pull/20102), [92e2aff](https://github.com/laravel/framework/commit/92e2aff2fd9569fedf3164ef9a1a834e553a6881)) ### Redis -- Removed `PhpRedisConnection::proxyToEval()` method ([#17360](https://github.com/laravel/framework/pull/17360)) +- ⚠️ Several improvements on `PhpRedisConnection` ([#20269](https://github.com/laravel/framework/pull/20269), [#20316](https://github.com/laravel/framework/pull/20316)) +- ⚠️ Removed `PhpRedisConnection::proxyToEval()` method ([#17360](https://github.com/laravel/framework/pull/17360)) ### Requests - ⚠️ Made `Request::has()` work like `Collection::has()` ([#18715](https://github.com/laravel/framework/pull/18715)) @@ -201,6 +206,7 @@ - Made `Request::routeIs()` work like `Request()::fullUrlIs()` ([#19267](https://github.com/laravel/framework/pull/19267), [bfc5321](https://github.com/laravel/framework/commit/bfc53213f67d50444d3db078737990fa14081d1b), [#19334](https://github.com/laravel/framework/pull/19334)) - Added `Request::hasAny()` method ([#19367](https://github.com/laravel/framework/pull/19367)) - ⚠️ Throw validation exception from `ValidatesRequests` without formatting response ([#19929](https://github.com/laravel/framework/pull/19929), [6d33675](https://github.com/laravel/framework/commit/6d33675691aae86c71454b731ceed847256b9dac), [ec88362](https://github.com/laravel/framework/commit/ec88362ee06ad418db93eb0e19f6d285eed7e701), [c264807](https://github.com/laravel/framework/commit/c2648070eb2108b0f9a4189bfbabea195282b963)) +- Added `Request::post()` method ([#20238](https://github.com/laravel/framework/pull/20238)) ### Routing - Support fluent resource options ([#18767](https://github.com/laravel/framework/pull/18767), [bb02fb2](https://github.com/laravel/framework/commit/bb02fb27387a8aeb2a47da1fe5ff2e086920b744)) @@ -219,7 +225,7 @@ - ⚠️ Ensure `Arrayable` objects are also morphed by `Response` ([#17868](https://github.com/laravel/framework/pull/17868)) - Added `SameSite` support to `CookieJar` ([#18040](https://github.com/laravel/framework/pull/18040), [#18059](https://github.com/laravel/framework/pull/18059), [e69d722](https://github.com/laravel/framework/commit/e69d72296cfd9969db569b950721461a521100c4)) - Accept `HeaderBag` in `ResponseTrait::withHeaders()` ([#18161](https://github.com/laravel/framework/pull/18161)) -- ⚠️ Reset response content-type in `Response::setContent()` ([#18314](https://github.com/laravel/framework/pull/18314)) +- ⚠️ Reset response content-type in `Response::setContent()` ([#18314](https://github.com/laravel/framework/pull/18314), [#20313](https://github.com/laravel/framework/pull/20313)) - ⚠️ Always retrieve the real original content ([#20002](https://github.com/laravel/framework/pull/20002)) ### Service Container @@ -240,7 +246,7 @@ ### Testing - ⚠️ Switched to PHPUnit 6 ([#17755](https://github.com/laravel/framework/pull/17755), [#17864](https://github.com/laravel/framework/pull/17864)) - ⚠️ Renamed authentication assertion methods ([#17924](https://github.com/laravel/framework/pull/17924), [494a177](https://github.com/laravel/framework/commit/494a1774f217f0cd6b4efade63e200e3ac65f201)) -- ⚠️ Unify database testing traits into `RefreshDatabase` trait ([79c6f67](https://github.com/laravel/framework/commit/79c6f6774eecf77aef8ed5e2f270551a6f378f1d), [0322e32](https://github.com/laravel/framework/commit/0322e3226196a435db436e2a00c035be892c2466)) +- ⚠️ Unify database testing traits into `RefreshDatabase` trait ([79c6f67](https://github.com/laravel/framework/commit/79c6f6774eecf77aef8ed5e2f270551a6f378f1d), [0322e32](https://github.com/laravel/framework/commit/0322e3226196a435db436e2a00c035be892c2466), [#20308](https://github.com/laravel/framework/pull/20308)) - ⚠️ Changed Blade tests namespace to `Illuminate\Tests\View\Blade` ([#19675](https://github.com/laravel/framework/pull/19675)) - Added integration tests for the framework itself ([182027d](https://github.com/laravel/framework/commit/182027d3290e9a2e1bd9e2d52c125177ef6c6af6), [#18438](https://github.com/laravel/framework/pull/18438), [#18780](https://github.com/laravel/framework/pull/18780), [#19001](https://github.com/laravel/framework/pull/19001), [#20073](https://github.com/laravel/framework/pull/20073)) - Allow disabling of specific middleware ([#18673](https://github.com/laravel/framework/pull/18673)) diff --git a/src/Illuminate/Translation/LoaderInterface.php b/src/Illuminate/Contracts/Translation/Loader.php similarity index 90% rename from src/Illuminate/Translation/LoaderInterface.php rename to src/Illuminate/Contracts/Translation/Loader.php index cbebebfc68e9..feecc47d1b65 100755 --- a/src/Illuminate/Translation/LoaderInterface.php +++ b/src/Illuminate/Contracts/Translation/Loader.php @@ -1,8 +1,8 @@ performInsert($query); + + if (! $this->getConnectionName() && + $connection = $query->getConnection()) { + $this->setConnection($connection->getName()); + } } // If the model is successfully saved, we need to do a few more things once @@ -558,11 +563,11 @@ protected function finishSave(array $options) { $this->fireModelEvent('saved', false); - $this->syncOriginal(); - - if ($options['touch'] ?? true) { + if ($this->isDirty() && ($options['touch'] ?? true)) { $this->touchOwners(); } + + $this->syncOriginal(); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php index a7bba5fca783..5f35bc48d602 100755 --- a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php @@ -548,7 +548,7 @@ protected function typeDate(Fluent $column) */ protected function typeDateTime(Fluent $column) { - return "datetime($column->precision)"; + return $column->precision ? "datetime($column->precision)" : 'datetime'; } /** @@ -559,7 +559,7 @@ protected function typeDateTime(Fluent $column) */ protected function typeDateTimeTz(Fluent $column) { - return "datetime($column->precision)"; + return $this->typeDateTime($column); } /** @@ -593,10 +593,12 @@ protected function typeTimeTz(Fluent $column) protected function typeTimestamp(Fluent $column) { if ($column->useCurrent) { - return "timestamp($column->precision) default CURRENT_TIMESTAMP"; + return $column->precision + ? "timestamp($column->precision) default CURRENT_TIMESTAMP" + : 'timestamp default CURRENT_TIMESTAMP'; } - return "timestamp($column->precision)"; + return $column->precision ? "timestamp($column->precision)" : 'timestamp'; } /** @@ -607,11 +609,7 @@ protected function typeTimestamp(Fluent $column) */ protected function typeTimestampTz(Fluent $column) { - if ($column->useCurrent) { - return "timestamp($column->precision) default CURRENT_TIMESTAMP"; - } - - return "timestamp($column->precision)"; + return $this->typeTimestamp($column); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index 12dda7f84bcf..0270cf2bd477 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -468,7 +468,7 @@ protected function typeDate(Fluent $column) */ protected function typeDateTime(Fluent $column) { - return "datetime2($column->precision)"; + return $column->precision ? "datetime2($column->precision)" : 'datetime'; } /** @@ -479,7 +479,7 @@ protected function typeDateTime(Fluent $column) */ protected function typeDateTimeTz(Fluent $column) { - return "datetimeoffset($column->precision)"; + return $column->precision ? "datetimeoffset($column->precision)" : 'datetimeoffset'; } /** @@ -513,10 +513,12 @@ protected function typeTimeTz(Fluent $column) protected function typeTimestamp(Fluent $column) { if ($column->useCurrent) { - return "datetime2($column->precision) default CURRENT_TIMESTAMP"; + return $column->precision + ? "datetime2($column->precision) default CURRENT_TIMESTAMP" + : 'datetime default CURRENT_TIMESTAMP'; } - return "datetime2($column->precision)"; + return $column->precision ? "datetime2($column->precision)" : 'datetime'; } /** @@ -530,7 +532,9 @@ protected function typeTimestamp(Fluent $column) protected function typeTimestampTz(Fluent $column) { if ($column->useCurrent) { - return "datetimeoffset($column->precision) default CURRENT_TIMESTAMP"; + return $column->precision + ? "datetimeoffset($column->precision) default CURRENT_TIMESTAMP" + : 'datetimeoffset default CURRENT_TIMESTAMP'; } return "datetimeoffset($column->precision)"; diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 2c501831c08a..1a51e53e8f19 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -363,6 +363,7 @@ protected function whoopsHandler() $files = new Filesystem; $handler->handleUnconditionally(true); + $handler->setApplicationPaths( array_flip(Arr::except( array_flip($files->directories(base_path())), [base_path('vendor')] diff --git a/src/Illuminate/Translation/ArrayLoader.php b/src/Illuminate/Translation/ArrayLoader.php index 5e0b2d077b64..b853fc750a23 100644 --- a/src/Illuminate/Translation/ArrayLoader.php +++ b/src/Illuminate/Translation/ArrayLoader.php @@ -2,7 +2,9 @@ namespace Illuminate\Translation; -class ArrayLoader implements LoaderInterface +use Illuminate\Contracts\Translation\Loader; + +class ArrayLoader implements Loader { /** * All of the translation messages. diff --git a/src/Illuminate/Translation/FileLoader.php b/src/Illuminate/Translation/FileLoader.php index 9d45c06a0508..a42397ec1b78 100755 --- a/src/Illuminate/Translation/FileLoader.php +++ b/src/Illuminate/Translation/FileLoader.php @@ -3,8 +3,9 @@ namespace Illuminate\Translation; use Illuminate\Filesystem\Filesystem; +use Illuminate\Contracts\Translation\Loader; -class FileLoader implements LoaderInterface +class FileLoader implements Loader { /** * The filesystem instance. diff --git a/src/Illuminate/Translation/Translator.php b/src/Illuminate/Translation/Translator.php index fd509f15cb3f..db4aec2848e4 100755 --- a/src/Illuminate/Translation/Translator.php +++ b/src/Illuminate/Translation/Translator.php @@ -7,6 +7,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Collection; use Illuminate\Support\Traits\Macroable; +use Illuminate\Contracts\Translation\Loader; use Illuminate\Support\NamespacedItemResolver; use Illuminate\Contracts\Translation\Translator as TranslatorContract; @@ -17,7 +18,7 @@ class Translator extends NamespacedItemResolver implements TranslatorContract /** * The loader implementation. * - * @var \Illuminate\Translation\LoaderInterface + * @var \Illuminate\Contracts\Translation\Loader */ protected $loader; @@ -52,11 +53,11 @@ class Translator extends NamespacedItemResolver implements TranslatorContract /** * Create a new translator instance. * - * @param \Illuminate\Translation\LoaderInterface $loader + * @param \Illuminate\Contracts\Translation\Loader $loader * @param string $locale * @return void */ - public function __construct(LoaderInterface $loader, $locale) + public function __construct(Loader $loader, $locale) { $this->loader = $loader; $this->locale = $locale; @@ -406,7 +407,7 @@ public function setSelector(MessageSelector $selector) /** * Get the language line loader implementation. * - * @return \Illuminate\Translation\LoaderInterface + * @return \Illuminate\Contracts\Translation\Loader */ public function getLoader() { diff --git a/src/Illuminate/View/Engines/EngineResolver.php b/src/Illuminate/View/Engines/EngineResolver.php index 3a9f2e19460b..66b6e64a2b64 100755 --- a/src/Illuminate/View/Engines/EngineResolver.php +++ b/src/Illuminate/View/Engines/EngineResolver.php @@ -41,7 +41,7 @@ public function register($engine, Closure $resolver) * Resolver an engine instance by name. * * @param string $engine - * @return \Illuminate\View\Engines\EngineInterface + * @return \Illuminate\Contracts\View\Engine * @throws \InvalidArgumentException */ public function resolve($engine) diff --git a/src/Illuminate/View/Engines/FileEngine.php b/src/Illuminate/View/Engines/FileEngine.php index e9ec85d8feaa..360b54381a8f 100644 --- a/src/Illuminate/View/Engines/FileEngine.php +++ b/src/Illuminate/View/Engines/FileEngine.php @@ -2,7 +2,9 @@ namespace Illuminate\View\Engines; -class FileEngine implements EngineInterface +use Illuminate\Contracts\View\Engine; + +class FileEngine implements Engine { /** * Get the evaluated contents of the view. diff --git a/src/Illuminate/View/Engines/PhpEngine.php b/src/Illuminate/View/Engines/PhpEngine.php index 1b2a3837c3b9..4209e58bdd85 100755 --- a/src/Illuminate/View/Engines/PhpEngine.php +++ b/src/Illuminate/View/Engines/PhpEngine.php @@ -4,9 +4,10 @@ use Exception; use Throwable; +use Illuminate\Contracts\View\Engine; use Symfony\Component\Debug\Exception\FatalThrowableError; -class PhpEngine implements EngineInterface +class PhpEngine implements Engine { /** * Get the evaluated contents of the view. diff --git a/src/Illuminate/View/Factory.php b/src/Illuminate/View/Factory.php index 238e0c679f9a..6418a653f453 100755 --- a/src/Illuminate/View/Factory.php +++ b/src/Illuminate/View/Factory.php @@ -248,7 +248,7 @@ public function exists($view) * Get the appropriate view engine for the given path. * * @param string $path - * @return \Illuminate\View\Engines\EngineInterface + * @return \Illuminate\Contracts\View\Engine * * @throws \InvalidArgumentException */ diff --git a/src/Illuminate/View/View.php b/src/Illuminate/View/View.php index 592f4292f657..496eb6cbd198 100755 --- a/src/Illuminate/View/View.php +++ b/src/Illuminate/View/View.php @@ -8,9 +8,9 @@ use BadMethodCallException; use Illuminate\Support\Str; use Illuminate\Support\MessageBag; +use Illuminate\Contracts\View\Engine; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Renderable; -use Illuminate\View\Engines\EngineInterface; use Illuminate\Contracts\Support\MessageProvider; use Illuminate\Contracts\View\View as ViewContract; @@ -26,7 +26,7 @@ class View implements ArrayAccess, ViewContract /** * The engine implementation. * - * @var \Illuminate\View\Engines\EngineInterface + * @var \Illuminate\Contracts\View\Engine */ protected $engine; @@ -55,13 +55,13 @@ class View implements ArrayAccess, ViewContract * Create a new view instance. * * @param \Illuminate\View\Factory $factory - * @param \Illuminate\View\Engines\EngineInterface $engine + * @param \Illuminate\Contracts\View\Engine $engine * @param string $view * @param string $path * @param mixed $data * @return void */ - public function __construct(Factory $factory, EngineInterface $engine, $view, $path, $data = []) + public function __construct(Factory $factory, Engine $engine, $view, $path, $data = []) { $this->view = $view; $this->path = $path; @@ -287,7 +287,7 @@ public function getFactory() /** * Get the view's rendering engine. * - * @return \Illuminate\View\Engines\EngineInterface + * @return \Illuminate\Contracts\View\Engine */ public function getEngine() { diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index a8214ecda1ac..3faa6e473670 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -476,6 +476,7 @@ public function testInsertProcess() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -494,6 +495,7 @@ public function testInsertProcess() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insert')->once()->with(['name' => 'taylor']); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); $model->setIncrementing(false); @@ -515,6 +517,7 @@ public function testInsertIsCancelledIfCreatingEventReturnsFalse() { $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true); @@ -542,6 +545,7 @@ public function testPushNoRelations() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -558,6 +562,7 @@ public function testPushEmptyOneRelation() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -576,6 +581,7 @@ public function testPushOneRelation() $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2); + $query->shouldReceive('getConnection')->once(); $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $related1->expects($this->once())->method('updateTimestamps'); $related1->name = 'related1'; @@ -584,6 +590,7 @@ public function testPushOneRelation() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -605,6 +612,7 @@ public function testPushEmptyManyRelation() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -623,6 +631,7 @@ public function testPushManyRelation() $related1 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2); + $query->shouldReceive('getConnection')->once(); $related1->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $related1->expects($this->once())->method('updateTimestamps'); $related1->name = 'related1'; @@ -631,6 +640,7 @@ public function testPushManyRelation() $related2 = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'related2'], 'id')->andReturn(3); + $query->shouldReceive('getConnection')->once(); $related2->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $related2->expects($this->once())->method('updateTimestamps'); $related2->name = 'related2'; @@ -639,6 +649,7 @@ public function testPushManyRelation() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $model->expects($this->once())->method('updateTimestamps'); @@ -1621,6 +1632,7 @@ public function testIntKeyTypePreserved() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn(1); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $this->assertTrue($model->save()); @@ -1632,6 +1644,7 @@ public function testStringKeyTypePreserved() $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentKeyTypeModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'refresh'])->getMock(); $query = m::mock('Illuminate\Database\Eloquent\Builder'); $query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id'); + $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query)); $this->assertTrue($model->save()); diff --git a/tests/Database/DatabaseMySqlSchemaGrammarTest.php b/tests/Database/DatabaseMySqlSchemaGrammarTest.php index fe04a8a62f53..da2ab2ce2fbf 100755 --- a/tests/Database/DatabaseMySqlSchemaGrammarTest.php +++ b/tests/Database/DatabaseMySqlSchemaGrammarTest.php @@ -584,19 +584,29 @@ public function testAddingDateTime() $blueprint = new Blueprint('users'); $blueprint->dateTime('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` datetime not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->dateTime('foo', 1); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` datetime(0) not null', $statements[0]); + $this->assertEquals('alter table `users` add `foo` datetime(1) not null', $statements[0]); } public function testAddingDateTimeTz() { $blueprint = new Blueprint('users'); - $blueprint->dateTimeTz('foo'); + $blueprint->dateTimeTz('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` datetime(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->dateTimeTz('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` datetime(0) not null', $statements[0]); + $this->assertEquals('alter table `users` add `foo` datetime not null', $statements[0]); } public function testAddingTime() @@ -604,7 +614,6 @@ public function testAddingTime() $blueprint = new Blueprint('users'); $blueprint->time('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertCount(1, $statements); $this->assertEquals('alter table `users` add `foo` time not null', $statements[0]); } @@ -622,61 +631,91 @@ public function testAddingTimeTz() public function testAddingTimeStamp() { $blueprint = new Blueprint('users'); - $blueprint->timestamp('foo'); + $blueprint->timestamp('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` timestamp(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestamp('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` timestamp(0) not null', $statements[0]); + $this->assertEquals('alter table `users` add `foo` timestamp not null', $statements[0]); } public function testAddingTimeStampWithDefault() { $blueprint = new Blueprint('users'); - $blueprint->timestamp('foo')->default('2015-07-22 11:43:17'); + $blueprint->timestamp('foo', 1)->default('2015-07-22 11:43:17'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` timestamp(1) not null default \'2015-07-22 11:43:17\'', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestamp('foo')->default('2015-07-22 11:43:17'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` timestamp(0) not null default \'2015-07-22 11:43:17\'', $statements[0]); + $this->assertEquals('alter table `users` add `foo` timestamp not null default \'2015-07-22 11:43:17\'', $statements[0]); } public function testAddingTimeStampTz() { $blueprint = new Blueprint('users'); - $blueprint->timestampTz('foo'); + $blueprint->timestampTz('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` timestamp(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestampTz('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` timestamp(0) not null', $statements[0]); + $this->assertEquals('alter table `users` add `foo` timestamp not null', $statements[0]); } public function testAddingTimeStampTzWithDefault() { $blueprint = new Blueprint('users'); - $blueprint->timestampTz('foo')->default('2015-07-22 11:43:17'); + $blueprint->timestampTz('foo', 1)->default('2015-07-22 11:43:17'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `foo` timestamp(1) not null default \'2015-07-22 11:43:17\'', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestampTz('foo')->default('2015-07-22 11:43:17'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `foo` timestamp(0) not null default \'2015-07-22 11:43:17\'', $statements[0]); + $this->assertEquals('alter table `users` add `foo` timestamp not null default \'2015-07-22 11:43:17\'', $statements[0]); } public function testAddingTimeStamps() { $blueprint = new Blueprint('users'); - $blueprint->timestamps(); + $blueprint->timestamps(1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `created_at` timestamp(1) null, add `updated_at` timestamp(1) null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestamps(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `created_at` timestamp(0) null, add `updated_at` timestamp(0) null', $statements[0]); + $this->assertEquals('alter table `users` add `created_at` timestamp null, add `updated_at` timestamp null', $statements[0]); } public function testAddingTimeStampsTz() { $blueprint = new Blueprint('users'); - $blueprint->timestampsTz(); + $blueprint->timestampsTz(1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table `users` add `created_at` timestamp(1) null, add `updated_at` timestamp(1) null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestampsTz(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table `users` add `created_at` timestamp(0) null, add `updated_at` timestamp(0) null', $statements[0]); + $this->assertEquals('alter table `users` add `created_at` timestamp null, add `updated_at` timestamp null', $statements[0]); } public function testAddingRememberToken() diff --git a/tests/Database/DatabaseSchemaBlueprintTest.php b/tests/Database/DatabaseSchemaBlueprintTest.php index 5f917f519f6d..e262604d092a 100755 --- a/tests/Database/DatabaseSchemaBlueprintTest.php +++ b/tests/Database/DatabaseSchemaBlueprintTest.php @@ -64,7 +64,7 @@ public function testDefaultCurrentTimestamp() $connection = m::mock('Illuminate\Database\Connection'); $blueprint = clone $base; - $this->assertEquals(['alter table `users` add `created` timestamp(0) default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new MySqlGrammar)); + $this->assertEquals(['alter table `users` add `created` timestamp default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new MySqlGrammar)); $blueprint = clone $base; $this->assertEquals(['alter table "users" add column "created" timestamp(0) without time zone default CURRENT_TIMESTAMP(0) not null'], $blueprint->toSql($connection, new PostgresGrammar)); @@ -73,7 +73,7 @@ public function testDefaultCurrentTimestamp() $this->assertEquals(['alter table "users" add column "created" datetime default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new SQLiteGrammar)); $blueprint = clone $base; - $this->assertEquals(['alter table "users" add "created" datetime2(0) default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new SqlServerGrammar)); + $this->assertEquals(['alter table "users" add "created" datetime default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new SqlServerGrammar)); } public function testUnsignedDecimalTable() diff --git a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php index 12e851f72e2f..024e374668fa 100755 --- a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php +++ b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php @@ -442,21 +442,31 @@ public function testAddingDate() public function testAddingDateTime() { $blueprint = new Blueprint('users'); - $blueprint->dateTime('foo'); + $blueprint->dateTime('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table "users" add "foo" datetime2(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->dateTime('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "foo" datetime2(0) not null', $statements[0]); + $this->assertEquals('alter table "users" add "foo" datetime not null', $statements[0]); } public function testAddingDateTimeTz() { $blueprint = new Blueprint('users'); - $blueprint->dateTimeTz('foo'); + $blueprint->dateTimeTz('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table "users" add "foo" datetimeoffset(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->dateTimeTz('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "foo" datetimeoffset(0) not null', $statements[0]); + $this->assertEquals('alter table "users" add "foo" datetimeoffset not null', $statements[0]); } public function testAddingTime() @@ -482,11 +492,16 @@ public function testAddingTimeTz() public function testAddingTimeStamp() { $blueprint = new Blueprint('users'); - $blueprint->timestamp('foo'); + $blueprint->timestamp('foo', 1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table "users" add "foo" datetime2(1) not null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestamp('foo'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "foo" datetime2(0) not null', $statements[0]); + $this->assertEquals('alter table "users" add "foo" datetime not null', $statements[0]); } public function testAddingTimeStampTz() @@ -502,11 +517,16 @@ public function testAddingTimeStampTz() public function testAddingTimeStamps() { $blueprint = new Blueprint('users'); - $blueprint->timestamps(); + $blueprint->timestamps(1); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table "users" add "created_at" datetime2(1) null, "updated_at" datetime2(1) null', $statements[0]); + $blueprint = new Blueprint('users'); + $blueprint->timestamps(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertEquals('alter table "users" add "created_at" datetime2(0) null, "updated_at" datetime2(0) null', $statements[0]); + $this->assertEquals('alter table "users" add "created_at" datetime null, "updated_at" datetime null', $statements[0]); } public function testAddingTimeStampsTz() diff --git a/tests/Integration/Database/EloquentBelongsToManyTest.php b/tests/Integration/Database/EloquentBelongsToManyTest.php index 6bc9b827d0c1..6c968443f621 100644 --- a/tests/Integration/Database/EloquentBelongsToManyTest.php +++ b/tests/Integration/Database/EloquentBelongsToManyTest.php @@ -457,8 +457,10 @@ public function touching_parent() Carbon::createFromFormat('Y-m-d H:i:s', '2017-10-10 10:10:10') ); - $tag->update(['name' => str_random('asd')]); + $tag->update(['name' => $tag->name]); + $this->assertNotEquals('2017-10-10 10:10:10', $post->fresh()->updated_at->toDateTimeString()); + $tag->update(['name' => str_random()]); $this->assertEquals('2017-10-10 10:10:10', $post->fresh()->updated_at->toDateTimeString()); } diff --git a/tests/Integration/Database/EloquentModelConnectionsTest.php b/tests/Integration/Database/EloquentModelConnectionsTest.php new file mode 100644 index 000000000000..fda43f3855b4 --- /dev/null +++ b/tests/Integration/Database/EloquentModelConnectionsTest.php @@ -0,0 +1,139 @@ +set('app.debug', 'true'); + + $app['config']->set('database.default', 'conn1'); + + $app['config']->set('database.connections.conn1', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + + $app['config']->set('database.connections.conn2', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } + + public function setUp() + { + parent::setUp(); + + Schema::create('parent', function ($table) { + $table->increments('id'); + $table->string('name'); + }); + + Schema::create('child', function ($table) { + $table->increments('id'); + $table->string('name'); + $table->integer('parent_id'); + }); + + Schema::connection('conn2')->create('parent', function ($table) { + $table->increments('id'); + $table->string('name'); + }); + + Schema::connection('conn2')->create('child', function ($table) { + $table->increments('id'); + $table->string('name'); + $table->integer('parent_id'); + }); + } + + public function test_child_obeys_parent_connection() + { + $parent1 = ParentModel::create(['name' => str_random()]); + $parent1->children()->create(['name' => 'childOnConn1']); + $parents1 = ParentModel::with('children')->get(); + $this->assertEquals('childOnConn1', ChildModel::on('conn1')->first()->name); + $this->assertEquals('childOnConn1', $parent1->children()->first()->name); + $this->assertEquals('childOnConn1', $parents1[0]->children[0]->name); + + $parent2 = ParentModel::on('conn2')->create(['name' => str_random()]); + $parent2->children()->create(['name' => 'childOnConn2']); + $parents2 = ParentModel::on('conn2')->with('children')->get(); + $this->assertEquals('childOnConn2', ChildModel::on('conn2')->first()->name); + $this->assertEquals('childOnConn2', $parent2->children()->first()->name); + $this->assertEquals('childOnConn2', $parents2[0]->children[0]->name); + } + + public function test_child_uses_its_own_connection_if_set() + { + $parent1 = ParentModel::create(['name' => str_random()]); + $parent1->childrenDefaultConn2()->create(['name' => 'childAlwaysOnConn2']); + $parents1 = ParentModel::with('childrenDefaultConn2')->get(); + $this->assertEquals('childAlwaysOnConn2', ChildModelDefaultConn2::first()->name); + $this->assertEquals('childAlwaysOnConn2', $parent1->childrenDefaultConn2()->first()->name); + $this->assertEquals('childAlwaysOnConn2', $parents1[0]->childrenDefaultConn2[0]->name); + $this->assertEquals('childAlwaysOnConn2', $parents1[0]->childrenDefaultConn2[0]->name); + } + + public function test_child_uses_its_own_connection_if_set_even_if_parent_explicit_connection() + { + $parent1 = ParentModel::on('conn1')->create(['name' => str_random()]); + $parent1->childrenDefaultConn2()->create(['name' => 'childAlwaysOnConn2']); + $parents1 = ParentModel::on('conn1')->with('childrenDefaultConn2')->get(); + $this->assertEquals('childAlwaysOnConn2', ChildModelDefaultConn2::first()->name); + $this->assertEquals('childAlwaysOnConn2', $parent1->childrenDefaultConn2()->first()->name); + $this->assertEquals('childAlwaysOnConn2', $parents1[0]->childrenDefaultConn2[0]->name); + } +} + +class ParentModel extends Model +{ + public $table = 'parent'; + public $timestamps = false; + protected $guarded = ['id']; + + public function children() + { + return $this->hasMany(ChildModel::class, 'parent_id'); + } + + public function childrenDefaultConn2() + { + return $this->hasMany(ChildModelDefaultConn2::class, 'parent_id'); + } +} + +class ChildModel extends Model +{ + public $table = 'child'; + public $timestamps = false; + protected $guarded = ['id']; + + public function parent() + { + return $this->belongsTo(ParentModel::class, 'parent_id'); + } +} + +class ChildModelDefaultConn2 extends Model +{ + public $connection = 'conn2'; + public $table = 'child'; + public $timestamps = false; + protected $guarded = ['id']; + + public function parent() + { + return $this->belongsTo(ParentModel::class, 'parent_id'); + } +} diff --git a/tests/Translation/TranslationTranslatorTest.php b/tests/Translation/TranslationTranslatorTest.php index 38d410529311..101c3b4fd165 100755 --- a/tests/Translation/TranslationTranslatorTest.php +++ b/tests/Translation/TranslationTranslatorTest.php @@ -159,6 +159,6 @@ public function testGetJsonForNonExistingReturnsSameKeyAndReplaces() protected function getLoader() { - return m::mock('Illuminate\Translation\LoaderInterface'); + return m::mock(\Illuminate\Contracts\Translation\Loader::class); } } diff --git a/tests/View/ViewFactoryTest.php b/tests/View/ViewFactoryTest.php index 71246203e31a..b7bb7992d233 100755 --- a/tests/View/ViewFactoryTest.php +++ b/tests/View/ViewFactoryTest.php @@ -20,7 +20,7 @@ public function testMakeCreatesNewViewInstanceWithProperPathAndEngine() $factory = $this->getFactory(); $factory->getFinder()->shouldReceive('find')->once()->with('view')->andReturn('path.php'); - $factory->getEngineResolver()->shouldReceive('resolve')->once()->with('php')->andReturn($engine = m::mock('Illuminate\View\Engines\EngineInterface')); + $factory->getEngineResolver()->shouldReceive('resolve')->once()->with('php')->andReturn($engine = m::mock(\Illuminate\Contracts\View\Engine::class)); $factory->getFinder()->shouldReceive('addExtension')->once()->with('php'); $factory->setDispatcher(new \Illuminate\Events\Dispatcher); $factory->creator('view', function ($view) { @@ -83,7 +83,7 @@ public function testEnvironmentAddsExtensionWithCustomResolver() $factory->getFinder()->shouldReceive('addExtension')->once()->with('foo'); $factory->getEngineResolver()->shouldReceive('register')->once()->with('bar', $resolver); $factory->getFinder()->shouldReceive('find')->once()->with('view')->andReturn('path.foo'); - $factory->getEngineResolver()->shouldReceive('resolve')->once()->with('bar')->andReturn($engine = m::mock(\Illuminate\View\Engines\EngineInterface::class)); + $factory->getEngineResolver()->shouldReceive('resolve')->once()->with('bar')->andReturn($engine = m::mock(\Illuminate\Contracts\View\Engine::class)); $factory->getDispatcher()->shouldReceive('dispatch'); $factory->addExtension('foo', 'bar', $resolver); @@ -409,7 +409,7 @@ public function testMakeWithSlashAndDot() { $factory = $this->getFactory(); $factory->getFinder()->shouldReceive('find')->twice()->with('foo.bar')->andReturn('path.php'); - $factory->getEngineResolver()->shouldReceive('resolve')->twice()->with('php')->andReturn(m::mock(\Illuminate\View\Engines\EngineInterface::class)); + $factory->getEngineResolver()->shouldReceive('resolve')->twice()->with('php')->andReturn(m::mock(\Illuminate\Contracts\View\Engine::class)); $factory->getDispatcher()->shouldReceive('dispatch'); $factory->make('foo/bar'); $factory->make('foo.bar'); @@ -419,7 +419,7 @@ public function testNamespacedViewNamesAreNormalizedProperly() { $factory = $this->getFactory(); $factory->getFinder()->shouldReceive('find')->twice()->with('vendor/package::foo.bar')->andReturn('path.php'); - $factory->getEngineResolver()->shouldReceive('resolve')->twice()->with('php')->andReturn(m::mock(\Illuminate\View\Engines\EngineInterface::class)); + $factory->getEngineResolver()->shouldReceive('resolve')->twice()->with('php')->andReturn(m::mock(\Illuminate\Contracts\View\Engine::class)); $factory->getDispatcher()->shouldReceive('dispatch'); $factory->make('vendor/package::foo/bar'); $factory->make('vendor/package::foo.bar'); diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php index 6117191d241f..fd203d713baa 100755 --- a/tests/View/ViewTest.php +++ b/tests/View/ViewTest.php @@ -70,7 +70,7 @@ public function testRenderSectionsReturnsEnvironmentSections() { $view = m::mock('Illuminate\View\View[render]', [ m::mock('Illuminate\View\Factory'), - m::mock('Illuminate\View\Engines\EngineInterface'), + m::mock(\Illuminate\Contracts\View\Engine::class), 'view', 'path', [], @@ -224,7 +224,7 @@ protected function getView($data = []) { return new View( m::mock('Illuminate\View\Factory'), - m::mock('Illuminate\View\Engines\EngineInterface'), + m::mock(\Illuminate\Contracts\View\Engine::class), 'view', 'path', $data