From f7fc225b8004f56218ea3b527705b3f26442c2e6 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Mon, 18 Feb 2019 01:50:51 +0200 Subject: [PATCH 01/78] [5.8] Make `register` method in the ServiceProvider as part of the contract In the https://github.com/laravel/framework/pull/27067 pr was added DeferrableProvider service provider. This Pr will add pretty the same thing. In case, if it will be accepted then I will add documentation for this. ---------------- Also i thing will be good to add diferent contract for the: - method `boot` - property `singletons` and `bindings` --- src/Illuminate/Auth/AuthServiceProvider.php | 3 ++- .../Auth/Passwords/PasswordResetServiceProvider.php | 3 ++- .../Broadcasting/BroadcastServiceProvider.php | 3 ++- src/Illuminate/Bus/BusServiceProvider.php | 3 ++- src/Illuminate/Cache/CacheServiceProvider.php | 3 ++- .../Contracts/Support/RegistrableProvider.php | 13 +++++++++++++ src/Illuminate/Cookie/CookieServiceProvider.php | 3 ++- src/Illuminate/Database/DatabaseServiceProvider.php | 3 ++- .../Database/MigrationServiceProvider.php | 3 ++- .../Encryption/EncryptionServiceProvider.php | 3 ++- src/Illuminate/Events/EventServiceProvider.php | 3 ++- .../Filesystem/FilesystemServiceProvider.php | 3 ++- src/Illuminate/Foundation/Application.php | 9 ++++++++- .../Foundation/Providers/ArtisanServiceProvider.php | 3 ++- .../Providers/ComposerServiceProvider.php | 3 ++- .../Providers/FormRequestServiceProvider.php | 10 ---------- .../Providers/FoundationServiceProvider.php | 3 ++- src/Illuminate/Hashing/HashServiceProvider.php | 3 ++- src/Illuminate/Log/LogServiceProvider.php | 3 ++- src/Illuminate/Mail/MailServiceProvider.php | 3 ++- .../Notifications/NotificationServiceProvider.php | 3 ++- .../Pagination/PaginationServiceProvider.php | 3 ++- src/Illuminate/Pipeline/PipelineServiceProvider.php | 3 ++- src/Illuminate/Queue/QueueServiceProvider.php | 3 ++- src/Illuminate/Redis/RedisServiceProvider.php | 3 ++- src/Illuminate/Routing/RoutingServiceProvider.php | 3 ++- src/Illuminate/Session/SessionServiceProvider.php | 3 ++- src/Illuminate/Support/AggregateServiceProvider.php | 4 +++- .../Translation/TranslationServiceProvider.php | 3 ++- .../Validation/ValidationServiceProvider.php | 3 ++- src/Illuminate/View/ViewServiceProvider.php | 3 ++- 31 files changed, 78 insertions(+), 39 deletions(-) create mode 100644 src/Illuminate/Contracts/Support/RegistrableProvider.php diff --git a/src/Illuminate/Auth/AuthServiceProvider.php b/src/Illuminate/Auth/AuthServiceProvider.php index 2820beb48a9e..c54506c46319 100755 --- a/src/Illuminate/Auth/AuthServiceProvider.php +++ b/src/Illuminate/Auth/AuthServiceProvider.php @@ -4,10 +4,11 @@ use Illuminate\Auth\Access\Gate; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; -class AuthServiceProvider extends ServiceProvider +class AuthServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php b/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php index 8df49f5041e7..c19e46d7cab1 100755 --- a/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php +++ b/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class PasswordResetServiceProvider extends ServiceProvider implements DeferrableProvider +class PasswordResetServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Broadcasting/BroadcastServiceProvider.php b/src/Illuminate/Broadcasting/BroadcastServiceProvider.php index 56628ef22502..eb639bf1751e 100644 --- a/src/Illuminate/Broadcasting/BroadcastServiceProvider.php +++ b/src/Illuminate/Broadcasting/BroadcastServiceProvider.php @@ -4,10 +4,11 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory; use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract; -class BroadcastServiceProvider extends ServiceProvider implements DeferrableProvider +class BroadcastServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Bus/BusServiceProvider.php b/src/Illuminate/Bus/BusServiceProvider.php index d41fe6a0b0fb..4f3a3814528a 100644 --- a/src/Illuminate/Bus/BusServiceProvider.php +++ b/src/Illuminate/Bus/BusServiceProvider.php @@ -4,11 +4,12 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract; use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract; -class BusServiceProvider extends ServiceProvider implements DeferrableProvider +class BusServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Cache/CacheServiceProvider.php b/src/Illuminate/Cache/CacheServiceProvider.php index 8b6e929d2323..ab74b231a4a7 100755 --- a/src/Illuminate/Cache/CacheServiceProvider.php +++ b/src/Illuminate/Cache/CacheServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class CacheServiceProvider extends ServiceProvider implements DeferrableProvider +class CacheServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Contracts/Support/RegistrableProvider.php b/src/Illuminate/Contracts/Support/RegistrableProvider.php new file mode 100644 index 000000000000..9b0e8b79851d --- /dev/null +++ b/src/Illuminate/Contracts/Support/RegistrableProvider.php @@ -0,0 +1,13 @@ +resolveProvider($provider); } - if (method_exists($provider, 'register')) { + /** + * @deprecated 'register' method will not be trigger for the run `register` method. Please use + * RegistrableProvider contract. In 5.9 will be removed register triggering by `register` method + */ + $shouldRegister = method_exists($provider, 'register'); + + if ($provider instanceof RegistrableProvider || $shouldRegister) { $provider->register(); } diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index eaddeb605077..64d8a1a41535 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -30,6 +30,7 @@ use Illuminate\Foundation\Console\RouteCacheCommand; use Illuminate\Foundation\Console\RouteClearCommand; use Illuminate\Console\Scheduling\ScheduleRunCommand; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Foundation\Console\ChannelMakeCommand; use Illuminate\Foundation\Console\ConfigCacheCommand; use Illuminate\Foundation\Console\ConfigClearCommand; @@ -73,7 +74,7 @@ use Illuminate\Database\Console\Migrations\RefreshCommand as MigrateRefreshCommand; use Illuminate\Database\Console\Migrations\RollbackCommand as MigrateRollbackCommand; -class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvider +class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * The commands to be registered. diff --git a/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php b/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php index 6b05c256d4aa..a786c1836c95 100755 --- a/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php @@ -5,8 +5,9 @@ use Illuminate\Support\Composer; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class ComposerServiceProvider extends ServiceProvider implements DeferrableProvider +class ComposerServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php index 7028d333c014..c152c73a285c 100644 --- a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php @@ -9,16 +9,6 @@ class FormRequestServiceProvider extends ServiceProvider { - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } - /** * Bootstrap the application services. * diff --git a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php index fc0088542324..b6ef753494d1 100644 --- a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php @@ -5,8 +5,9 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\URL; use Illuminate\Support\AggregateServiceProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class FoundationServiceProvider extends AggregateServiceProvider +class FoundationServiceProvider extends AggregateServiceProvider implements RegistrableProvider { /** * The provider class names. diff --git a/src/Illuminate/Hashing/HashServiceProvider.php b/src/Illuminate/Hashing/HashServiceProvider.php index 123b25fa8f0a..b224bb603fc0 100755 --- a/src/Illuminate/Hashing/HashServiceProvider.php +++ b/src/Illuminate/Hashing/HashServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class HashServiceProvider extends ServiceProvider implements DeferrableProvider +class HashServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Log/LogServiceProvider.php b/src/Illuminate/Log/LogServiceProvider.php index cd0739211932..52d7e2c3bc5e 100644 --- a/src/Illuminate/Log/LogServiceProvider.php +++ b/src/Illuminate/Log/LogServiceProvider.php @@ -3,8 +3,9 @@ namespace Illuminate\Log; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class LogServiceProvider extends ServiceProvider +class LogServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Mail/MailServiceProvider.php b/src/Illuminate/Mail/MailServiceProvider.php index 0f9e0feb969b..c9a5633ae74d 100755 --- a/src/Illuminate/Mail/MailServiceProvider.php +++ b/src/Illuminate/Mail/MailServiceProvider.php @@ -8,8 +8,9 @@ use Swift_DependencyContainer; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class MailServiceProvider extends ServiceProvider implements DeferrableProvider +class MailServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Notifications/NotificationServiceProvider.php b/src/Illuminate/Notifications/NotificationServiceProvider.php index e8909f4551e0..36eac379ce58 100644 --- a/src/Illuminate/Notifications/NotificationServiceProvider.php +++ b/src/Illuminate/Notifications/NotificationServiceProvider.php @@ -3,10 +3,11 @@ namespace Illuminate\Notifications; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Notifications\Factory as FactoryContract; use Illuminate\Contracts\Notifications\Dispatcher as DispatcherContract; -class NotificationServiceProvider extends ServiceProvider +class NotificationServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Boot the application services. diff --git a/src/Illuminate/Pagination/PaginationServiceProvider.php b/src/Illuminate/Pagination/PaginationServiceProvider.php index ed58ccf6b985..0b9bbb4a6218 100755 --- a/src/Illuminate/Pagination/PaginationServiceProvider.php +++ b/src/Illuminate/Pagination/PaginationServiceProvider.php @@ -3,8 +3,9 @@ namespace Illuminate\Pagination; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class PaginationServiceProvider extends ServiceProvider +class PaginationServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Bootstrap any application services. diff --git a/src/Illuminate/Pipeline/PipelineServiceProvider.php b/src/Illuminate/Pipeline/PipelineServiceProvider.php index e0c633e1abd5..ed2d05e384d7 100644 --- a/src/Illuminate/Pipeline/PipelineServiceProvider.php +++ b/src/Illuminate/Pipeline/PipelineServiceProvider.php @@ -4,9 +4,10 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Pipeline\Hub as PipelineHubContract; -class PipelineServiceProvider extends ServiceProvider implements DeferrableProvider +class PipelineServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Queue/QueueServiceProvider.php b/src/Illuminate/Queue/QueueServiceProvider.php index a20b0bcaf28e..0f78109aa0f9 100755 --- a/src/Illuminate/Queue/QueueServiceProvider.php +++ b/src/Illuminate/Queue/QueueServiceProvider.php @@ -14,9 +14,10 @@ use Illuminate\Queue\Failed\NullFailedJobProvider; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Queue\Connectors\BeanstalkdConnector; +use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Queue\Failed\DatabaseFailedJobProvider; -class QueueServiceProvider extends ServiceProvider implements DeferrableProvider +class QueueServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Redis/RedisServiceProvider.php b/src/Illuminate/Redis/RedisServiceProvider.php index 46fe1bc18fed..846c334ae7e5 100755 --- a/src/Illuminate/Redis/RedisServiceProvider.php +++ b/src/Illuminate/Redis/RedisServiceProvider.php @@ -5,8 +5,9 @@ use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class RedisServiceProvider extends ServiceProvider implements DeferrableProvider +class RedisServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Routing/RoutingServiceProvider.php b/src/Illuminate/Routing/RoutingServiceProvider.php index 8eea5ca5ecea..be75ee94f070 100755 --- a/src/Illuminate/Routing/RoutingServiceProvider.php +++ b/src/Illuminate/Routing/RoutingServiceProvider.php @@ -6,12 +6,13 @@ use Psr\Http\Message\ResponseInterface; use Zend\Diactoros\Response as PsrResponse; use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Contracts\Support\RegistrableProvider; use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; use Illuminate\Contracts\View\Factory as ViewFactoryContract; use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract; -class RoutingServiceProvider extends ServiceProvider +class RoutingServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Session/SessionServiceProvider.php b/src/Illuminate/Session/SessionServiceProvider.php index c858506240cd..61eebdbb979c 100755 --- a/src/Illuminate/Session/SessionServiceProvider.php +++ b/src/Illuminate/Session/SessionServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Session\Middleware\StartSession; +use Illuminate\Contracts\Support\RegistrableProvider; -class SessionServiceProvider extends ServiceProvider +class SessionServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Support/AggregateServiceProvider.php b/src/Illuminate/Support/AggregateServiceProvider.php index d7425c5c2586..02bc78f5a01f 100644 --- a/src/Illuminate/Support/AggregateServiceProvider.php +++ b/src/Illuminate/Support/AggregateServiceProvider.php @@ -2,7 +2,9 @@ namespace Illuminate\Support; -class AggregateServiceProvider extends ServiceProvider +use Illuminate\Contracts\Support\RegistrableProvider; + +class AggregateServiceProvider extends ServiceProvider implements RegistrableProvider { /** * The provider class names. diff --git a/src/Illuminate/Translation/TranslationServiceProvider.php b/src/Illuminate/Translation/TranslationServiceProvider.php index dea13c2cbb1a..c0c71d37f140 100755 --- a/src/Illuminate/Translation/TranslationServiceProvider.php +++ b/src/Illuminate/Translation/TranslationServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class TranslationServiceProvider extends ServiceProvider implements DeferrableProvider +class TranslationServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Validation/ValidationServiceProvider.php b/src/Illuminate/Validation/ValidationServiceProvider.php index 0228ad64d61d..c971d9bfd009 100755 --- a/src/Illuminate/Validation/ValidationServiceProvider.php +++ b/src/Illuminate/Validation/ValidationServiceProvider.php @@ -4,8 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class ValidationServiceProvider extends ServiceProvider implements DeferrableProvider +class ValidationServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/View/ViewServiceProvider.php b/src/Illuminate/View/ViewServiceProvider.php index fa88136a71b8..c41a6d2ce2de 100755 --- a/src/Illuminate/View/ViewServiceProvider.php +++ b/src/Illuminate/View/ViewServiceProvider.php @@ -8,8 +8,9 @@ use Illuminate\View\Engines\CompilerEngine; use Illuminate\View\Engines\EngineResolver; use Illuminate\View\Compilers\BladeCompiler; +use Illuminate\Contracts\Support\RegistrableProvider; -class ViewServiceProvider extends ServiceProvider +class ViewServiceProvider extends ServiceProvider implements RegistrableProvider { /** * Register the service provider. From 2729c5520f909db7d84a3aeee3af078626e7d25a Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Fri, 25 Jan 2019 09:12:10 -0600 Subject: [PATCH 02/78] initial support of pivot classes in M2M updates --- .../Concerns/InteractsWithPivotTable.php | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 1984ec690611..032bf9580fc3 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -209,12 +209,21 @@ public function updateExistingPivot($id, array $attributes, $touch = true) */ public function attach($id, array $attributes = [], $touch = true) { - // Here we will insert the attachment records into the pivot table. Once we have - // inserted the records, we will touch the relationships if necessary and the - // function will return. We can parse the IDs before inserting the records. - $this->newPivotStatement()->insert($this->formatAttachRecords( - $this->parseIds($id), $attributes - )); + if ($this->using) { + $records = $this->formatAttachRecords( + $this->parseIds($id), $attributes + ); + foreach ($records as $record) { + $this->newPivot($record, false)->save(); + } + } else { + // Here we will insert the attachment records into the pivot table. Once we have + // inserted the records, we will touch the relationships if necessary and the + // function will return. We can parse the IDs before inserting the records. + $this->newPivotStatement()->insert($this->formatAttachRecords( + $this->parseIds($id), $attributes + )); + } if ($touch) { $this->touchIfTouching(); @@ -355,26 +364,33 @@ protected function hasPivotColumn($column) */ public function detach($ids = null, $touch = true) { - $query = $this->newPivotQuery(); + if ($this->using) { + $results = 0; + foreach ($this->parseIds($ids) as $id) { + $results += $this->newPivot([$this->relatedPivotKey => $id], true)->delete(); + } + } else { + $query = $this->newPivotQuery(); - // If associated IDs were passed to the method we will only delete those - // associations, otherwise all of the association ties will be broken. - // We'll return the numbers of affected rows when we do the deletes. - if (! is_null($ids)) { - $ids = $this->parseIds($ids); + // If associated IDs were passed to the method we will only delete those + // associations, otherwise all of the association ties will be broken. + // We'll return the numbers of affected rows when we do the deletes. + if (! is_null($ids)) { + $ids = $this->parseIds($ids); - if (empty($ids)) { - return 0; + if (empty($ids)) { + return 0; + } + + $query->whereIn($this->relatedPivotKey, (array) $ids); } - $query->whereIn($this->relatedPivotKey, (array) $ids); + // Once we have all of the conditions set on the statement, we are ready + // to run the delete on the pivot table. Then, if the touch parameter + // is true, we will go ahead and touch all related models to sync. + $results = $query->delete(); } - // Once we have all of the conditions set on the statement, we are ready - // to run the delete on the pivot table. Then, if the touch parameter - // is true, we will go ahead and touch all related models to sync. - $results = $query->delete(); - if ($touch) { $this->touchIfTouching(); } From 43600abd3e00084992c96886df7b5ed45db79c96 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 28 Jan 2019 10:05:29 -0600 Subject: [PATCH 03/78] more support for using user Pivot classes when interacting with M2M relationships --- .../Eloquent/Relations/Concerns/AsPivot.php | 29 ++++++++++++++++--- .../Concerns/InteractsWithPivotTable.php | 18 +++++++++++- .../Database/Eloquent/Relations/Pivot.php | 2 ++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index 7fe75e6d4be5..5ce66e7c42c0 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -2,6 +2,7 @@ namespace Illuminate\Database\Eloquent\Relations\Concerns; +use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; @@ -57,7 +58,11 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist $instance->exists = $exists; - $instance->timestamps = $instance->hasTimestampAttributes(); + // If this is a subclassed Pivot class, treat it as a model and respect + // the $timestamps property + if (get_class($instance) === Pivot::class) { + $instance->timestamps = $instance->hasTimestampAttributes(); + } return $instance; } @@ -77,7 +82,12 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex $instance->setRawAttributes($attributes, true); - $instance->timestamps = $instance->hasTimestampAttributes(); + // If this is a subclassed Pivot class, treat it as a model and respect + // the $timestamps property + if (get_class($instance) === Pivot::class) { + $instance->timestamps = $instance->hasTimestampAttributes(); + } + return $instance; } @@ -110,11 +120,22 @@ protected function setKeysForSaveQuery(Builder $query) */ public function delete() { + // support for pivot classes that container a non-composite primary key if (isset($this->attributes[$this->getKeyName()])) { - return parent::delete(); + return (int) parent::delete(); + } + + if ($this->fireModelEvent('deleting') === false) { + return 0; } - return $this->getDeleteQuery()->delete(); + $this->touchOwners(); + + $this->getDeleteQuery()->delete(); + + $this->fireModelEvent('deleted', false); + + return 1; } /** diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 032bf9580fc3..793bdde82cd4 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -184,6 +184,19 @@ protected function attachNew(array $records, array $current, $touch = true) */ public function updateExistingPivot($id, array $attributes, $touch = true) { + if ($this->using) { + $updated = $this->newPivot([ + $this->foreignPivotKey => $this->parent->getKey(), + $this->relatedPivotKey => $this->parseId($id) + ], true)->fill($attributes)->save(); + + if ($touch) { + $this->touchIfTouching(); + } + + return (int) $updated; + } + if (in_array($this->updatedAt(), $this->pivotColumns)) { $attributes = $this->addTimestampsToAttachment($attributes, true); } @@ -367,7 +380,10 @@ public function detach($ids = null, $touch = true) if ($this->using) { $results = 0; foreach ($this->parseIds($ids) as $id) { - $results += $this->newPivot([$this->relatedPivotKey => $id], true)->delete(); + $results += $this->newPivot([ + $this->foreignPivotKey => $this->parent->getKey(), + $this->relatedPivotKey => $id + ], true)->delete(); } } else { $query = $this->newPivotQuery(); diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 2ec8235156bb..95799b8505af 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -9,6 +9,8 @@ class Pivot extends Model { use AsPivot; + public $incrementing = false; + /** * The attributes that aren't mass assignable. * From bd01af8e2a5a375eae83ed6266750f7e9df00502 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 28 Jan 2019 11:28:00 -0600 Subject: [PATCH 04/78] style fixes --- .../Database/Eloquent/Relations/Concerns/AsPivot.php | 2 +- .../Eloquent/Relations/Concerns/InteractsWithPivotTable.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index 5ce66e7c42c0..ca267de579b9 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -2,10 +2,10 @@ namespace Illuminate\Database\Eloquent\Relations\Concerns; -use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\Pivot; trait AsPivot { diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 793bdde82cd4..2cd6abc9f9e0 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -187,7 +187,7 @@ public function updateExistingPivot($id, array $attributes, $touch = true) if ($this->using) { $updated = $this->newPivot([ $this->foreignPivotKey => $this->parent->getKey(), - $this->relatedPivotKey => $this->parseId($id) + $this->relatedPivotKey => $this->parseId($id), ], true)->fill($attributes)->save(); if ($touch) { @@ -382,7 +382,7 @@ public function detach($ids = null, $touch = true) foreach ($this->parseIds($ids) as $id) { $results += $this->newPivot([ $this->foreignPivotKey => $this->parent->getKey(), - $this->relatedPivotKey => $id + $this->relatedPivotKey => $id, ], true)->delete(); } } else { From c1d8944b90575ce01a15c340c325624a6cc6b3b6 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 28 Jan 2019 12:46:20 -0600 Subject: [PATCH 05/78] tests added --- .../Database/Eloquent/Relations/Pivot.php | 2 ++ .../DatabaseEloquentIntegrationTest.php | 9 +++++++++ tests/Database/DatabaseEloquentPivotTest.php | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 95799b8505af..cf9377e90bde 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -11,6 +11,8 @@ class Pivot extends Model public $incrementing = false; + public $timestamps = false; + /** * The attributes that aren't mass assignable. * diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index ba92c0444e0c..1e254967dc88 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -6,6 +6,8 @@ use RuntimeException; use InvalidArgumentException; use Illuminate\Support\Carbon; +use Illuminate\Tests\Integration\Database\EloquentCollectionFreshTest; +use Illuminate\Tests\Integration\Database\EloquentDeleteTest; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\QueryException; @@ -1522,6 +1524,9 @@ public function testCanPassArrayOfModelsToIgnore() public function testWhenBaseModelIsIgnoredAllChildModelsAreIgnored() { + // force loading of User model since it exists in a non-autoloadable place + class_exists(EloquentCollectionFreshTest::class); + $this->assertFalse(Model::isIgnoringTouch()); $this->assertFalse(User::isIgnoringTouch()); @@ -1536,6 +1541,10 @@ public function testWhenBaseModelIsIgnoredAllChildModelsAreIgnored() public function testChildModelsAreIgnored() { + // force loading of User, Post model since it exists in a non-autoloadable place + class_exists(EloquentCollectionFreshTest::class); + class_exists(EloquentDeleteTest::class); + $this->assertFalse(Model::isIgnoringTouch()); $this->assertFalse(User::isIgnoringTouch()); $this->assertFalse(Post::isIgnoringTouch()); diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index 5f461ea5111e..3f9ed92a6b1d 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -2,6 +2,10 @@ namespace Illuminate\Tests\Database; +use Illuminate\Database\Connection; +use Illuminate\Database\ConnectionResolverInterface; +use Illuminate\Database\Grammar; +use Illuminate\Database\Query\Processors\Processor; use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; @@ -17,6 +21,8 @@ protected function tearDown(): void public function testPropertiesAreSetCorrectly() { $parent = m::mock(Model::class.'[getConnectionName]'); + $this->addMockConnection($parent); + $parent->shouldReceive('getConnectionName')->twice()->andReturn('connection'); $parent->getConnection()->getQueryGrammar()->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s'); $parent->setDateFormat('Y-m-d H:i:s'); @@ -151,6 +157,17 @@ public function testPivotModelWithoutParentReturnsModelTimestampColumns() $this->assertEquals($model->getCreatedAtColumn(), $pivotWithoutParent->getCreatedAtColumn()); $this->assertEquals($model->getUpdatedAtColumn(), $pivotWithoutParent->getUpdatedAtColumn()); } + + protected function addMockConnection($model) + { + $model->setConnectionResolver($resolver = m::mock(ConnectionResolverInterface::class)); + $resolver->shouldReceive('connection')->andReturn($connection = m::mock(Connection::class)); + $connection->shouldReceive('getQueryGrammar')->andReturn(m::mock(Grammar::class)); + // $connection->shouldReceive('getPostProcessor')->andReturn($processor = m::mock(Processor::class)); + // $connection->shouldReceive('query')->andReturnUsing(function () use ($connection, $grammar, $processor) { + // return new BaseBuilder($connection, $grammar, $processor); + // }); + } } class DatabaseEloquentPivotTestDateStub extends Pivot From 25c276ce97004aa686589fafe1df6be0ed64e498 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Fri, 15 Feb 2019 12:38:29 -0600 Subject: [PATCH 06/78] added pivot event integration tests --- .../Eloquent/Relations/Concerns/AsPivot.php | 17 ++- .../Database/Eloquent/Relations/Pivot.php | 2 - tests/Database/DatabaseEloquentPivotTest.php | 74 ++++++++-- .../Database/EloquentPivotEventsTest.php | 126 ++++++++++++++++++ 4 files changed, 195 insertions(+), 24 deletions(-) create mode 100644 tests/Integration/Database/EloquentPivotEventsTest.php diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index ca267de579b9..e99ccccb7722 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -43,6 +43,9 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist { $instance = new static; + // if this factory was presented valid timestamp columns, set th e + $instance->timestamps = $instance->hasTimestampAttributes($attributes); + // The pivot model is a "dynamic" model since we will set the tables dynamically // for the instance. This allows it work for any intermediate tables for the // many to many relationship that are defined by this developer's classes. @@ -58,12 +61,6 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist $instance->exists = $exists; - // If this is a subclassed Pivot class, treat it as a model and respect - // the $timestamps property - if (get_class($instance) === Pivot::class) { - $instance->timestamps = $instance->hasTimestampAttributes(); - } - return $instance; } @@ -214,13 +211,15 @@ public function setPivotKeys($foreignKey, $relatedKey) } /** - * Determine if the pivot model has timestamp attributes. + * Determine if the pivot model has timestamp attributes in either a provided + * array of attributes or the currently tracked attributes inside the model. * + * @param $attributes array|null Optional, * @return bool */ - public function hasTimestampAttributes() + public function hasTimestampAttributes($attributes = null) { - return array_key_exists($this->getCreatedAtColumn(), $this->attributes); + return array_key_exists($this->getCreatedAtColumn(), $attributes ?? $this->attributes); } /** diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index cf9377e90bde..95799b8505af 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -11,8 +11,6 @@ class Pivot extends Model public $incrementing = false; - public $timestamps = false; - /** * The attributes that aren't mass assignable. * diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index 3f9ed92a6b1d..ec8d5f069147 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -21,8 +21,6 @@ protected function tearDown(): void public function testPropertiesAreSetCorrectly() { $parent = m::mock(Model::class.'[getConnectionName]'); - $this->addMockConnection($parent); - $parent->shouldReceive('getConnectionName')->twice()->andReturn('connection'); $parent->getConnection()->getQueryGrammar()->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s'); $parent->setDateFormat('Y-m-d H:i:s'); @@ -125,7 +123,8 @@ public function testDeleteMethodDeletesModelByKeys() $query->shouldReceive('delete')->once()->andReturn(true); $pivot->expects($this->once())->method('newQueryWithoutRelationships')->will($this->returnValue($query)); - $this->assertTrue($pivot->delete()); + $rowsAffected = $pivot->delete(); + $this->assertEquals(1, $rowsAffected); } public function testPivotModelTableNameIsSingular() @@ -158,16 +157,10 @@ public function testPivotModelWithoutParentReturnsModelTimestampColumns() $this->assertEquals($model->getUpdatedAtColumn(), $pivotWithoutParent->getUpdatedAtColumn()); } - protected function addMockConnection($model) - { - $model->setConnectionResolver($resolver = m::mock(ConnectionResolverInterface::class)); - $resolver->shouldReceive('connection')->andReturn($connection = m::mock(Connection::class)); - $connection->shouldReceive('getQueryGrammar')->andReturn(m::mock(Grammar::class)); - // $connection->shouldReceive('getPostProcessor')->andReturn($processor = m::mock(Processor::class)); - // $connection->shouldReceive('query')->andReturnUsing(function () use ($connection, $grammar, $processor) { - // return new BaseBuilder($connection, $grammar, $processor); - // }); - } + // public function testPivotModelWillFireEvents() + // { + // + // } } class DatabaseEloquentPivotTestDateStub extends Pivot @@ -206,3 +199,58 @@ class DummyModel extends Model { // } +// +// class DummyModelWithExtendedPivot extends Model +// { +// public function +// } +// +// class DatabaseEloquentPivotWithEvents extends Pivot +// { +// public $eventsCalled = []; +// +// public static function boot() +// { +// parent::boot(); +// +// static::creating(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::created(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::updating(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::updated(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::saving(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::saved(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::deleting(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// +// static::deleted(function ($model) { +// // $model->eventsCalled[] +// return true; +// }); +// } +// } \ No newline at end of file diff --git a/tests/Integration/Database/EloquentPivotEventsTest.php b/tests/Integration/Database/EloquentPivotEventsTest.php new file mode 100644 index 000000000000..5c2404b1632b --- /dev/null +++ b/tests/Integration/Database/EloquentPivotEventsTest.php @@ -0,0 +1,126 @@ +increments('id'); + $table->string('email'); + $table->timestamps(); + }); + + Schema::create('projects', function ($table) { + $table->increments('id'); + $table->string('name'); + $table->timestamps(); + }); + + Schema::create('project_users', function ($table) { + $table->integer('user_id'); + $table->integer('project_id'); + $table->string('role')->nullable(); + }); + } + + public function test_pivot_will_trigger_events_to_be_fired() + { + $user = PivotEventsTestUser::forceCreate(['email' => 'taylor@laravel.com']); + $user2 = PivotEventsTestUser::forceCreate(['email' => 'ralph@ralphschindler.com']); + $project = PivotEventsTestProject::forceCreate(['name' => 'Test Project']); + + $project->collaborators()->attach($user); + $this->assertEquals(['saving', 'creating', 'created', 'saved'], PivotEventsTestCollaborator::$eventsCalled); + + PivotEventsTestCollaborator::$eventsCalled = []; + $project->collaborators()->sync([$user2->id]); + $this->assertEquals(['deleting', 'deleted', 'saving', 'creating', 'created', 'saved'], PivotEventsTestCollaborator::$eventsCalled); + + PivotEventsTestCollaborator::$eventsCalled = []; + $project->collaborators()->sync([$user->id => ['role' => 'owner'], $user2->id => ['role' => 'contributor']]); + $this->assertEquals(['saving', 'creating', 'created', 'saved', 'saving', 'updating', 'updated', 'saved'], PivotEventsTestCollaborator::$eventsCalled); + } +} + +class PivotEventsTestUser extends Model +{ + public $table = 'users'; +} + +class PivotEventsTestProject extends Model +{ + public $table = 'projects'; + + public function collaborators() + { + return $this->belongsToMany( + PivotEventsTestUser::class, 'project_users', 'project_id', 'user_id' + )->using(PivotEventsTestCollaborator::class); + } +} + +class PivotEventsTestCollaborator extends Pivot +{ + public $table = 'project_users'; + + public static $eventsCalled = []; + + public static function boot() + { + parent::boot(); + + static::creating(function ($model) { + static::$eventsCalled[] = 'creating'; + return true; + }); + + static::created(function ($model) { + static::$eventsCalled[] = 'created'; + return true; + }); + + static::updating(function ($model) { + static::$eventsCalled[] = 'updating'; + return true; + }); + + static::updated(function ($model) { + static::$eventsCalled[] = 'updated'; + return true; + }); + + static::saving(function ($model) { + static::$eventsCalled[] = 'saving'; + return true; + }); + + static::saved(function ($model) { + static::$eventsCalled[] = 'saved'; + return true; + }); + + static::deleting(function ($model) { + static::$eventsCalled[] = 'deleting'; + return true; + }); + + static::deleted(function ($model) { + static::$eventsCalled[] = 'deleted'; + return true; + }); + } +} From a638e10864c2a5453c0b7e9414feb846b9a295bf Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 18 Feb 2019 10:01:31 -0600 Subject: [PATCH 07/78] handle setting timestamps property in AsPivot::fromRawAttributes, cleanup tests --- .../Eloquent/Relations/Concerns/AsPivot.php | 7 +- .../DatabaseEloquentIntegrationTest.php | 7 -- tests/Database/DatabaseEloquentPivotTest.php | 64 ------------------- 3 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index e99ccccb7722..8974885e0639 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -77,14 +77,11 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex { $instance = static::fromAttributes($parent, [], $table, $exists); - $instance->setRawAttributes($attributes, true); - // If this is a subclassed Pivot class, treat it as a model and respect // the $timestamps property - if (get_class($instance) === Pivot::class) { - $instance->timestamps = $instance->hasTimestampAttributes(); - } + $instance->timestamps = $instance->hasTimestampAttributes($attributes); + $instance->setRawAttributes($attributes, true); return $instance; } diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 1e254967dc88..9ef59048b4d0 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -1524,9 +1524,6 @@ public function testCanPassArrayOfModelsToIgnore() public function testWhenBaseModelIsIgnoredAllChildModelsAreIgnored() { - // force loading of User model since it exists in a non-autoloadable place - class_exists(EloquentCollectionFreshTest::class); - $this->assertFalse(Model::isIgnoringTouch()); $this->assertFalse(User::isIgnoringTouch()); @@ -1541,10 +1538,6 @@ class_exists(EloquentCollectionFreshTest::class); public function testChildModelsAreIgnored() { - // force loading of User, Post model since it exists in a non-autoloadable place - class_exists(EloquentCollectionFreshTest::class); - class_exists(EloquentDeleteTest::class); - $this->assertFalse(Model::isIgnoringTouch()); $this->assertFalse(User::isIgnoringTouch()); $this->assertFalse(Post::isIgnoringTouch()); diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index ec8d5f069147..4f09aba25ee7 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -2,10 +2,6 @@ namespace Illuminate\Tests\Database; -use Illuminate\Database\Connection; -use Illuminate\Database\ConnectionResolverInterface; -use Illuminate\Database\Grammar; -use Illuminate\Database\Query\Processors\Processor; use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; @@ -156,11 +152,6 @@ public function testPivotModelWithoutParentReturnsModelTimestampColumns() $this->assertEquals($model->getCreatedAtColumn(), $pivotWithoutParent->getCreatedAtColumn()); $this->assertEquals($model->getUpdatedAtColumn(), $pivotWithoutParent->getUpdatedAtColumn()); } - - // public function testPivotModelWillFireEvents() - // { - // - // } } class DatabaseEloquentPivotTestDateStub extends Pivot @@ -199,58 +190,3 @@ class DummyModel extends Model { // } -// -// class DummyModelWithExtendedPivot extends Model -// { -// public function -// } -// -// class DatabaseEloquentPivotWithEvents extends Pivot -// { -// public $eventsCalled = []; -// -// public static function boot() -// { -// parent::boot(); -// -// static::creating(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::created(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::updating(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::updated(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::saving(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::saved(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::deleting(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// -// static::deleted(function ($model) { -// // $model->eventsCalled[] -// return true; -// }); -// } -// } \ No newline at end of file From 5d8c183039d564b3036e3ec8e3a91ee20e016601 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 18 Feb 2019 10:49:17 -0600 Subject: [PATCH 08/78] style fixes --- .../Database/Eloquent/Relations/Concerns/AsPivot.php | 10 +++++----- tests/Database/DatabaseEloquentIntegrationTest.php | 2 -- .../Integration/Database/EloquentPivotEventsTest.php | 11 ----------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index 8974885e0639..0b747fc35e16 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -5,7 +5,6 @@ use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Relations\Pivot; trait AsPivot { @@ -43,7 +42,8 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist { $instance = new static; - // if this factory was presented valid timestamp columns, set th e + // if this factory was presented valid timestamp columns, set the $timestamps + // property accordingly $instance->timestamps = $instance->hasTimestampAttributes($attributes); // The pivot model is a "dynamic" model since we will set the tables dynamically @@ -77,8 +77,8 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex { $instance = static::fromAttributes($parent, [], $table, $exists); - // If this is a subclassed Pivot class, treat it as a model and respect - // the $timestamps property + // if this factory was presented valid timestamp columns, set the $timestamps + // property accordingly $instance->timestamps = $instance->hasTimestampAttributes($attributes); $instance->setRawAttributes($attributes, true); @@ -211,7 +211,7 @@ public function setPivotKeys($foreignKey, $relatedKey) * Determine if the pivot model has timestamp attributes in either a provided * array of attributes or the currently tracked attributes inside the model. * - * @param $attributes array|null Optional, + * @param $attributes array|null Options attributes to check instead of properties * @return bool */ public function hasTimestampAttributes($attributes = null) diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 9ef59048b4d0..ba92c0444e0c 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -6,8 +6,6 @@ use RuntimeException; use InvalidArgumentException; use Illuminate\Support\Carbon; -use Illuminate\Tests\Integration\Database\EloquentCollectionFreshTest; -use Illuminate\Tests\Integration\Database\EloquentDeleteTest; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\QueryException; diff --git a/tests/Integration/Database/EloquentPivotEventsTest.php b/tests/Integration/Database/EloquentPivotEventsTest.php index 5c2404b1632b..a81ce022d683 100644 --- a/tests/Integration/Database/EloquentPivotEventsTest.php +++ b/tests/Integration/Database/EloquentPivotEventsTest.php @@ -2,12 +2,9 @@ namespace Illuminate\Tests\Integration\Database; -use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Pivot; -use Illuminate\Database\Eloquent\Relations\MorphPivot; -use Illuminate\Database\Eloquent\Collection as DatabaseCollection; /** * @group integration @@ -85,42 +82,34 @@ public static function boot() static::creating(function ($model) { static::$eventsCalled[] = 'creating'; - return true; }); static::created(function ($model) { static::$eventsCalled[] = 'created'; - return true; }); static::updating(function ($model) { static::$eventsCalled[] = 'updating'; - return true; }); static::updated(function ($model) { static::$eventsCalled[] = 'updated'; - return true; }); static::saving(function ($model) { static::$eventsCalled[] = 'saving'; - return true; }); static::saved(function ($model) { static::$eventsCalled[] = 'saved'; - return true; }); static::deleting(function ($model) { static::$eventsCalled[] = 'deleting'; - return true; }); static::deleted(function ($model) { static::$eventsCalled[] = 'deleted'; - return true; }); } } From aa411cc4dd4f97623666a36d704609d8e557f347 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Mon, 18 Feb 2019 20:37:54 +0200 Subject: [PATCH 09/78] Revert "[5.8] Make `register` method in the ServiceProvider as part of the contract In the https://github.com/laravel/framework/pull/27067 pr was added DeferrableProvider service provider. This Pr will add pretty the same thing. In case, if it will be accepted then I will add documentation for this." This reverts commit f7fc225 --- src/Illuminate/Auth/AuthServiceProvider.php | 3 +-- .../Auth/Passwords/PasswordResetServiceProvider.php | 3 +-- .../Broadcasting/BroadcastServiceProvider.php | 3 +-- src/Illuminate/Bus/BusServiceProvider.php | 3 +-- src/Illuminate/Cache/CacheServiceProvider.php | 3 +-- .../Contracts/Support/RegistrableProvider.php | 13 ------------- src/Illuminate/Cookie/CookieServiceProvider.php | 3 +-- src/Illuminate/Database/DatabaseServiceProvider.php | 3 +-- .../Database/MigrationServiceProvider.php | 3 +-- .../Encryption/EncryptionServiceProvider.php | 3 +-- src/Illuminate/Events/EventServiceProvider.php | 3 +-- .../Filesystem/FilesystemServiceProvider.php | 3 +-- src/Illuminate/Foundation/Application.php | 9 +-------- .../Foundation/Providers/ArtisanServiceProvider.php | 3 +-- .../Providers/ComposerServiceProvider.php | 3 +-- .../Providers/FormRequestServiceProvider.php | 10 ++++++++++ .../Providers/FoundationServiceProvider.php | 3 +-- src/Illuminate/Hashing/HashServiceProvider.php | 3 +-- src/Illuminate/Log/LogServiceProvider.php | 3 +-- src/Illuminate/Mail/MailServiceProvider.php | 3 +-- .../Notifications/NotificationServiceProvider.php | 3 +-- .../Pagination/PaginationServiceProvider.php | 3 +-- src/Illuminate/Pipeline/PipelineServiceProvider.php | 3 +-- src/Illuminate/Queue/QueueServiceProvider.php | 3 +-- src/Illuminate/Redis/RedisServiceProvider.php | 3 +-- src/Illuminate/Routing/RoutingServiceProvider.php | 3 +-- src/Illuminate/Session/SessionServiceProvider.php | 3 +-- src/Illuminate/Support/AggregateServiceProvider.php | 4 +--- .../Translation/TranslationServiceProvider.php | 3 +-- .../Validation/ValidationServiceProvider.php | 3 +-- src/Illuminate/View/ViewServiceProvider.php | 3 +-- 31 files changed, 39 insertions(+), 78 deletions(-) delete mode 100644 src/Illuminate/Contracts/Support/RegistrableProvider.php diff --git a/src/Illuminate/Auth/AuthServiceProvider.php b/src/Illuminate/Auth/AuthServiceProvider.php index c54506c46319..2820beb48a9e 100755 --- a/src/Illuminate/Auth/AuthServiceProvider.php +++ b/src/Illuminate/Auth/AuthServiceProvider.php @@ -4,11 +4,10 @@ use Illuminate\Auth\Access\Gate; use Illuminate\Support\ServiceProvider; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; -class AuthServiceProvider extends ServiceProvider implements RegistrableProvider +class AuthServiceProvider extends ServiceProvider { /** * Register the service provider. diff --git a/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php b/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php index c19e46d7cab1..8df49f5041e7 100755 --- a/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php +++ b/src/Illuminate/Auth/Passwords/PasswordResetServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class PasswordResetServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class PasswordResetServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Broadcasting/BroadcastServiceProvider.php b/src/Illuminate/Broadcasting/BroadcastServiceProvider.php index eb639bf1751e..56628ef22502 100644 --- a/src/Illuminate/Broadcasting/BroadcastServiceProvider.php +++ b/src/Illuminate/Broadcasting/BroadcastServiceProvider.php @@ -4,11 +4,10 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory; use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract; -class BroadcastServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class BroadcastServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Bus/BusServiceProvider.php b/src/Illuminate/Bus/BusServiceProvider.php index 4f3a3814528a..d41fe6a0b0fb 100644 --- a/src/Illuminate/Bus/BusServiceProvider.php +++ b/src/Illuminate/Bus/BusServiceProvider.php @@ -4,12 +4,11 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract; use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract; -class BusServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class BusServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Cache/CacheServiceProvider.php b/src/Illuminate/Cache/CacheServiceProvider.php index ab74b231a4a7..8b6e929d2323 100755 --- a/src/Illuminate/Cache/CacheServiceProvider.php +++ b/src/Illuminate/Cache/CacheServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class CacheServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class CacheServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Contracts/Support/RegistrableProvider.php b/src/Illuminate/Contracts/Support/RegistrableProvider.php deleted file mode 100644 index 9b0e8b79851d..000000000000 --- a/src/Illuminate/Contracts/Support/RegistrableProvider.php +++ /dev/null @@ -1,13 +0,0 @@ -resolveProvider($provider); } - /** - * @deprecated 'register' method will not be trigger for the run `register` method. Please use - * RegistrableProvider contract. In 5.9 will be removed register triggering by `register` method - */ - $shouldRegister = method_exists($provider, 'register'); - - if ($provider instanceof RegistrableProvider || $shouldRegister) { + if (method_exists($provider, 'register')) { $provider->register(); } diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index 64d8a1a41535..eaddeb605077 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -30,7 +30,6 @@ use Illuminate\Foundation\Console\RouteCacheCommand; use Illuminate\Foundation\Console\RouteClearCommand; use Illuminate\Console\Scheduling\ScheduleRunCommand; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Foundation\Console\ChannelMakeCommand; use Illuminate\Foundation\Console\ConfigCacheCommand; use Illuminate\Foundation\Console\ConfigClearCommand; @@ -74,7 +73,7 @@ use Illuminate\Database\Console\Migrations\RefreshCommand as MigrateRefreshCommand; use Illuminate\Database\Console\Migrations\RollbackCommand as MigrateRollbackCommand; -class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvider { /** * The commands to be registered. diff --git a/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php b/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php index a786c1836c95..6b05c256d4aa 100755 --- a/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php @@ -5,9 +5,8 @@ use Illuminate\Support\Composer; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class ComposerServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class ComposerServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php index c152c73a285c..7028d333c014 100644 --- a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php @@ -9,6 +9,16 @@ class FormRequestServiceProvider extends ServiceProvider { + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + /** * Bootstrap the application services. * diff --git a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php index b6ef753494d1..fc0088542324 100644 --- a/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php @@ -5,9 +5,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\URL; use Illuminate\Support\AggregateServiceProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class FoundationServiceProvider extends AggregateServiceProvider implements RegistrableProvider +class FoundationServiceProvider extends AggregateServiceProvider { /** * The provider class names. diff --git a/src/Illuminate/Hashing/HashServiceProvider.php b/src/Illuminate/Hashing/HashServiceProvider.php index b224bb603fc0..123b25fa8f0a 100755 --- a/src/Illuminate/Hashing/HashServiceProvider.php +++ b/src/Illuminate/Hashing/HashServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class HashServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class HashServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Log/LogServiceProvider.php b/src/Illuminate/Log/LogServiceProvider.php index 52d7e2c3bc5e..cd0739211932 100644 --- a/src/Illuminate/Log/LogServiceProvider.php +++ b/src/Illuminate/Log/LogServiceProvider.php @@ -3,9 +3,8 @@ namespace Illuminate\Log; use Illuminate\Support\ServiceProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class LogServiceProvider extends ServiceProvider implements RegistrableProvider +class LogServiceProvider extends ServiceProvider { /** * Register the service provider. diff --git a/src/Illuminate/Mail/MailServiceProvider.php b/src/Illuminate/Mail/MailServiceProvider.php index c9a5633ae74d..0f9e0feb969b 100755 --- a/src/Illuminate/Mail/MailServiceProvider.php +++ b/src/Illuminate/Mail/MailServiceProvider.php @@ -8,9 +8,8 @@ use Swift_DependencyContainer; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class MailServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class MailServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Notifications/NotificationServiceProvider.php b/src/Illuminate/Notifications/NotificationServiceProvider.php index 36eac379ce58..e8909f4551e0 100644 --- a/src/Illuminate/Notifications/NotificationServiceProvider.php +++ b/src/Illuminate/Notifications/NotificationServiceProvider.php @@ -3,11 +3,10 @@ namespace Illuminate\Notifications; use Illuminate\Support\ServiceProvider; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Notifications\Factory as FactoryContract; use Illuminate\Contracts\Notifications\Dispatcher as DispatcherContract; -class NotificationServiceProvider extends ServiceProvider implements RegistrableProvider +class NotificationServiceProvider extends ServiceProvider { /** * Boot the application services. diff --git a/src/Illuminate/Pagination/PaginationServiceProvider.php b/src/Illuminate/Pagination/PaginationServiceProvider.php index 0b9bbb4a6218..ed58ccf6b985 100755 --- a/src/Illuminate/Pagination/PaginationServiceProvider.php +++ b/src/Illuminate/Pagination/PaginationServiceProvider.php @@ -3,9 +3,8 @@ namespace Illuminate\Pagination; use Illuminate\Support\ServiceProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class PaginationServiceProvider extends ServiceProvider implements RegistrableProvider +class PaginationServiceProvider extends ServiceProvider { /** * Bootstrap any application services. diff --git a/src/Illuminate/Pipeline/PipelineServiceProvider.php b/src/Illuminate/Pipeline/PipelineServiceProvider.php index ed2d05e384d7..e0c633e1abd5 100644 --- a/src/Illuminate/Pipeline/PipelineServiceProvider.php +++ b/src/Illuminate/Pipeline/PipelineServiceProvider.php @@ -4,10 +4,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Contracts\Pipeline\Hub as PipelineHubContract; -class PipelineServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class PipelineServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Queue/QueueServiceProvider.php b/src/Illuminate/Queue/QueueServiceProvider.php index 0f78109aa0f9..a20b0bcaf28e 100755 --- a/src/Illuminate/Queue/QueueServiceProvider.php +++ b/src/Illuminate/Queue/QueueServiceProvider.php @@ -14,10 +14,9 @@ use Illuminate\Queue\Failed\NullFailedJobProvider; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Queue\Connectors\BeanstalkdConnector; -use Illuminate\Contracts\Support\RegistrableProvider; use Illuminate\Queue\Failed\DatabaseFailedJobProvider; -class QueueServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class QueueServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Redis/RedisServiceProvider.php b/src/Illuminate/Redis/RedisServiceProvider.php index 846c334ae7e5..46fe1bc18fed 100755 --- a/src/Illuminate/Redis/RedisServiceProvider.php +++ b/src/Illuminate/Redis/RedisServiceProvider.php @@ -5,9 +5,8 @@ use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class RedisServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class RedisServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Routing/RoutingServiceProvider.php b/src/Illuminate/Routing/RoutingServiceProvider.php index be75ee94f070..8eea5ca5ecea 100755 --- a/src/Illuminate/Routing/RoutingServiceProvider.php +++ b/src/Illuminate/Routing/RoutingServiceProvider.php @@ -6,13 +6,12 @@ use Psr\Http\Message\ResponseInterface; use Zend\Diactoros\Response as PsrResponse; use Psr\Http\Message\ServerRequestInterface; -use Illuminate\Contracts\Support\RegistrableProvider; use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; use Illuminate\Contracts\View\Factory as ViewFactoryContract; use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract; -class RoutingServiceProvider extends ServiceProvider implements RegistrableProvider +class RoutingServiceProvider extends ServiceProvider { /** * Register the service provider. diff --git a/src/Illuminate/Session/SessionServiceProvider.php b/src/Illuminate/Session/SessionServiceProvider.php index 61eebdbb979c..c858506240cd 100755 --- a/src/Illuminate/Session/SessionServiceProvider.php +++ b/src/Illuminate/Session/SessionServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Session\Middleware\StartSession; -use Illuminate\Contracts\Support\RegistrableProvider; -class SessionServiceProvider extends ServiceProvider implements RegistrableProvider +class SessionServiceProvider extends ServiceProvider { /** * Register the service provider. diff --git a/src/Illuminate/Support/AggregateServiceProvider.php b/src/Illuminate/Support/AggregateServiceProvider.php index 02bc78f5a01f..d7425c5c2586 100644 --- a/src/Illuminate/Support/AggregateServiceProvider.php +++ b/src/Illuminate/Support/AggregateServiceProvider.php @@ -2,9 +2,7 @@ namespace Illuminate\Support; -use Illuminate\Contracts\Support\RegistrableProvider; - -class AggregateServiceProvider extends ServiceProvider implements RegistrableProvider +class AggregateServiceProvider extends ServiceProvider { /** * The provider class names. diff --git a/src/Illuminate/Translation/TranslationServiceProvider.php b/src/Illuminate/Translation/TranslationServiceProvider.php index c0c71d37f140..dea13c2cbb1a 100755 --- a/src/Illuminate/Translation/TranslationServiceProvider.php +++ b/src/Illuminate/Translation/TranslationServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class TranslationServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class TranslationServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/Validation/ValidationServiceProvider.php b/src/Illuminate/Validation/ValidationServiceProvider.php index c971d9bfd009..0228ad64d61d 100755 --- a/src/Illuminate/Validation/ValidationServiceProvider.php +++ b/src/Illuminate/Validation/ValidationServiceProvider.php @@ -4,9 +4,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class ValidationServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class ValidationServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider. diff --git a/src/Illuminate/View/ViewServiceProvider.php b/src/Illuminate/View/ViewServiceProvider.php index c41a6d2ce2de..fa88136a71b8 100755 --- a/src/Illuminate/View/ViewServiceProvider.php +++ b/src/Illuminate/View/ViewServiceProvider.php @@ -8,9 +8,8 @@ use Illuminate\View\Engines\CompilerEngine; use Illuminate\View\Engines\EngineResolver; use Illuminate\View\Compilers\BladeCompiler; -use Illuminate\Contracts\Support\RegistrableProvider; -class ViewServiceProvider extends ServiceProvider implements RegistrableProvider +class ViewServiceProvider extends ServiceProvider { /** * Register the service provider. From 6a3b9530f8fc0e945187425ea78920da8a89a9b9 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Mon, 18 Feb 2019 20:42:13 +0200 Subject: [PATCH 10/78] [5.8] Add `register` method to the ServiceProvider --- src/Illuminate/Foundation/Application.php | 4 +--- .../Support/Providers/AuthServiceProvider.php | 8 -------- .../Support/Providers/EventServiceProvider.php | 8 -------- .../Support/Providers/RouteServiceProvider.php | 10 ---------- src/Illuminate/Support/ServiceProvider.php | 10 ++++++++++ tests/Foundation/FoundationApplicationTest.php | 4 ++-- 6 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 27500fad1bbe..ebeea45f3b84 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -594,9 +594,7 @@ public function register($provider, $force = false) $provider = $this->resolveProvider($provider); } - if (method_exists($provider, 'register')) { - $provider->register(); - } + $provider->register(); // If there are bindings / singletons set as properties on the provider we // will spin through them and register them with the application, which diff --git a/src/Illuminate/Foundation/Support/Providers/AuthServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/AuthServiceProvider.php index 4fc90b7dec72..ac32319cfa34 100644 --- a/src/Illuminate/Foundation/Support/Providers/AuthServiceProvider.php +++ b/src/Illuminate/Foundation/Support/Providers/AuthServiceProvider.php @@ -26,14 +26,6 @@ public function registerPolicies() } } - /** - * {@inheritdoc} - */ - public function register() - { - // - } - /** * Get the policies defined on the provider. * diff --git a/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php index 307f2cefa0a1..5b2664771a85 100644 --- a/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php +++ b/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php @@ -39,14 +39,6 @@ public function boot() } } - /** - * {@inheritdoc} - */ - public function register() - { - // - } - /** * Get the events and handlers. * diff --git a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php index e535fc697798..c86ad8c6e7d4 100644 --- a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php +++ b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php @@ -88,16 +88,6 @@ protected function loadRoutes() } } - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } - /** * Pass dynamic methods onto the router instance. * diff --git a/src/Illuminate/Support/ServiceProvider.php b/src/Illuminate/Support/ServiceProvider.php index 30de0f4fc3f9..fb98d376a079 100755 --- a/src/Illuminate/Support/ServiceProvider.php +++ b/src/Illuminate/Support/ServiceProvider.php @@ -273,6 +273,16 @@ public function commands($commands) }); } + /** + * Register services. + * + * @return void + */ + public function register() + { + // + } + /** * Get the services provided by the provider. * diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 6b79e4186818..3ad5ad8d8eb2 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -75,11 +75,11 @@ public function testSingletonsAreCreatedWhenServiceProviderIsRegistered() $this->assertSame($instance, $app->make(AbstractClass::class)); } - public function testServiceProvidersAreCorrectlyRegisteredWhenRegisterMethodIsNotPresent() + public function testServiceProvidersAreCorrectlyRegisteredWhenRegisterMethodIsNotFilled() { $provider = m::mock(ServiceProvider::class); $class = get_class($provider); - $provider->shouldReceive('register')->never(); + $provider->shouldReceive('register')->once(); $app = new Application; $app->register($provider); From 0ba72abcbc1e5a86866f68e44bc3286c0168e0bf Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 18 Feb 2019 19:16:25 -0600 Subject: [PATCH 11/78] altered AsPivot::delete() to return affected rows from builder --- .../Database/Eloquent/Relations/Concerns/AsPivot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index 0b747fc35e16..b77d7db80d82 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -125,11 +125,11 @@ public function delete() $this->touchOwners(); - $this->getDeleteQuery()->delete(); + $affectedRows = $this->getDeleteQuery()->delete(); $this->fireModelEvent('deleted', false); - return 1; + return $affectedRows; } /** From d428e3e7fd9ceb462d578b99971814ef15028ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Xu=C3=A2n=20Qu=E1=BB=B3nh?= Date: Thu, 21 Feb 2019 21:25:33 +0700 Subject: [PATCH 12/78] Dislay message when no route was round --- src/Illuminate/Foundation/Console/RouteListCommand.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 9fb99a59bde7..32e37ebd3a9b 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -67,11 +67,15 @@ public function __construct(Router $router) */ public function handle() { - if (count($this->routes) === 0) { + if (empty($this->routes)) { return $this->error("Your application doesn't have any routes."); } - $this->displayRoutes($this->getRoutes()); + if (empty($routes = $this->getRoutes())) { + return $this->info('Could not find any matched routes.'); + } + + $this->displayRoutes($routes); } /** From d194182acb817e683182235d42ab1895d998049f Mon Sep 17 00:00:00 2001 From: Axel Pardemann Date: Thu, 21 Feb 2019 19:48:12 -0600 Subject: [PATCH 13/78] Set the queue name correctly when queing mailables using Mail::queue A queue name and the queue manager where being used indistinctly so the call errored as it expected an \Illuminate\Contracts\Queue\Factory and not a string. --- src/Illuminate/Mail/Mailer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/Mailer.php b/src/Illuminate/Mail/Mailer.php index bda44d62561d..9ee3e90ee219 100755 --- a/src/Illuminate/Mail/Mailer.php +++ b/src/Illuminate/Mail/Mailer.php @@ -380,7 +380,11 @@ public function queue($view, $queue = null) throw new InvalidArgumentException('Only mailables may be queued.'); } - return $view->queue(is_null($queue) ? $this->queue : $queue); + if (is_string($queue)) { + $view->onQueue($queue); + } + + return $view->queue($this->queue); } /** From d89f412e0a4521fa37d3a1f4c832f7790416237c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 22 Feb 2019 18:35:45 +0800 Subject: [PATCH 14/78] [5.7] Add support for Pheanstalk 3.x and 4.x Signed-off-by: Mior Muhammad Zaki --- composer.json | 4 ++-- src/Illuminate/Queue/BeanstalkdQueue.php | 7 ++++++- src/Illuminate/Queue/Connectors/BeanstalkdConnector.php | 9 +++++++++ src/Illuminate/Queue/composer.json | 2 +- tests/Queue/QueueBeanstalkdQueueTest.php | 8 +++++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 0a7a7b86247d..feee84087c3f 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,7 @@ "mockery/mockery": "^1.0", "moontoast/math": "^1.1", "orchestra/testbench-core": "3.7.*", - "pda/pheanstalk": "^3.0", + "pda/pheanstalk": "^3.0|^4.0", "phpunit/phpunit": "^7.5", "predis/predis": "^1.1.1", "symfony/css-selector": "^4.1", @@ -128,7 +128,7 @@ "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).", "moontoast/math": "Required to use ordered UUIDs (^1.1).", "nexmo/client": "Required to use the Nexmo transport (^1.0).", - "pda/pheanstalk": "Required to use the beanstalk queue driver (^3.0).", + "pda/pheanstalk": "Required to use the beanstalk queue driver (^3.0|^4.0).", "predis/predis": "Required to use the redis cache and queue drivers (^1.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0).", "symfony/css-selector": "Required to use some of the crawler integration testing tools (^4.1).", diff --git a/src/Illuminate/Queue/BeanstalkdQueue.php b/src/Illuminate/Queue/BeanstalkdQueue.php index 28f7f306ffad..c013f5e1f1e4 100755 --- a/src/Illuminate/Queue/BeanstalkdQueue.php +++ b/src/Illuminate/Queue/BeanstalkdQueue.php @@ -5,6 +5,7 @@ use Pheanstalk\Pheanstalk; use Pheanstalk\Job as PheanstalkJob; use Illuminate\Queue\Jobs\BeanstalkdJob; +use Pheanstalk\Contract\PheanstalkInterface; use Illuminate\Contracts\Queue\Queue as QueueContract; class BeanstalkdQueue extends Queue implements QueueContract @@ -117,7 +118,11 @@ public function pop($queue = null) { $queue = $this->getQueue($queue); - $job = $this->pheanstalk->watchOnly($queue)->reserve(0); + $this->pheanstalk->watchOnly($queue); + + $job = interface_exists(PheanstalkInterface::class) + ? $this->pheanstalk->reserveWithTimeout(0) + : $this->pheanstalk->reserve(0); if ($job instanceof PheanstalkJob) { return new BeanstalkdJob( diff --git a/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php b/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php index 1f65d7b2361d..46fc746a6cd5 100755 --- a/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php +++ b/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php @@ -5,6 +5,7 @@ use Pheanstalk\Connection; use Pheanstalk\Pheanstalk; use Illuminate\Queue\BeanstalkdQueue; +use Pheanstalk\Contract\PheanstalkInterface; class BeanstalkdConnector implements ConnectorInterface { @@ -29,6 +30,14 @@ public function connect(array $config) */ protected function pheanstalk(array $config) { + if (interface_exists(PheanstalkInterface::class)) { + return Pheanstalk::create( + $config['host'], + $config['port'] ?? Pheanstalk::DEFAULT_PORT, + $config['timeout'] ?? Connection::DEFAULT_CONNECT_TIMEOUT + ); + } + return new Pheanstalk( $config['host'], $config['port'] ?? Pheanstalk::DEFAULT_PORT, diff --git a/src/Illuminate/Queue/composer.json b/src/Illuminate/Queue/composer.json index 8ef7982f42f1..c27e2ecad48f 100644 --- a/src/Illuminate/Queue/composer.json +++ b/src/Illuminate/Queue/composer.json @@ -40,7 +40,7 @@ "ext-posix": "Required to use all features of the queue worker.", "aws/aws-sdk-php": "Required to use the SQS queue driver (^3.0).", "illuminate/redis": "Required to use the Redis queue driver (5.7.*).", - "pda/pheanstalk": "Required to use the Beanstalk queue driver (^3.0)." + "pda/pheanstalk": "Required to use the Beanstalk queue driver (^3.0|^4.0)." }, "config": { "sort-packages": true diff --git a/tests/Queue/QueueBeanstalkdQueueTest.php b/tests/Queue/QueueBeanstalkdQueueTest.php index 6ab139bc3dfe..2fc88a8d8b0d 100755 --- a/tests/Queue/QueueBeanstalkdQueueTest.php +++ b/tests/Queue/QueueBeanstalkdQueueTest.php @@ -9,6 +9,7 @@ use Illuminate\Container\Container; use Illuminate\Queue\BeanstalkdQueue; use Illuminate\Queue\Jobs\BeanstalkdJob; +use Pheanstalk\Contract\PheanstalkInterface; class QueueBeanstalkdQueueTest extends TestCase { @@ -48,7 +49,12 @@ public function testPopProperlyPopsJobOffOfBeanstalkd() $pheanstalk = $queue->getPheanstalk(); $pheanstalk->shouldReceive('watchOnly')->once()->with('default')->andReturn($pheanstalk); $job = m::mock(Job::class); - $pheanstalk->shouldReceive('reserve')->once()->andReturn($job); + + if (interface_exists(PheanstalkInterface::class)) { + $pheanstalk->shouldReceive('reserveWithTimeout')->once()->andReturn($job); + } else { + $pheanstalk->shouldReceive('reserve')->once()->andReturn($job); + } $result = $queue->pop(); From 8cfb90fc06c3166f89ffe0e23c30d49a6453fac2 Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Fri, 22 Feb 2019 11:27:29 +0330 Subject: [PATCH 15/78] fix failing tests on windows --- tests/Integration/Mail/RenderingMailWithLocaleTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Mail/RenderingMailWithLocaleTest.php b/tests/Integration/Mail/RenderingMailWithLocaleTest.php index 3e03084778f5..6d0730d79f28 100644 --- a/tests/Integration/Mail/RenderingMailWithLocaleTest.php +++ b/tests/Integration/Mail/RenderingMailWithLocaleTest.php @@ -31,14 +31,14 @@ public function testMailableRendersInDefaultLocale() { $mail = new RenderedTestMail; - $this->assertStringContainsString("name\n", $mail->render()); + $this->assertStringContainsString('name'.PHP_EOL, $mail->render()); } public function testMailableRendersInSelectedLocale() { $mail = (new RenderedTestMail)->locale('es'); - $this->assertStringContainsString("nombre\n", $mail->render()); + $this->assertStringContainsString('nombre'.PHP_EOL, $mail->render()); } public function testMailableRendersInAppSelectedLocale() @@ -47,7 +47,7 @@ public function testMailableRendersInAppSelectedLocale() $mail = new RenderedTestMail; - $this->assertStringContainsString("nombre\n", $mail->render()); + $this->assertStringContainsString('nombre'.PHP_EOL, $mail->render()); } } From e70162b405a767d10b43e597c3de4753c9b87d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Xu=C3=A2n=20Qu=E1=BB=B3nh?= Date: Fri, 22 Feb 2019 07:59:32 +0700 Subject: [PATCH 16/78] Move str tests --- tests/Support/SupportHelpersTest.php | 116 --------------------------- tests/Support/SupportStrTest.php | 28 +++++++ 2 files changed, 28 insertions(+), 116 deletions(-) diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 1716c7bf9483..9ea0865546af 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -209,48 +209,6 @@ public function testArrayFlatten() $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten([['#foo', '#bar'], ['#baz']])); } - public function testStrIs() - { - $this->assertTrue(Str::is('*.dev', 'localhost.dev')); - $this->assertTrue(Str::is('a', 'a')); - $this->assertTrue(Str::is('/', '/')); - $this->assertTrue(Str::is('*dev*', 'localhost.dev')); - $this->assertTrue(Str::is('foo?bar', 'foo?bar')); - $this->assertFalse(Str::is('*something', 'foobar')); - $this->assertFalse(Str::is('foo', 'bar')); - $this->assertFalse(Str::is('foo.*', 'foobar')); - $this->assertFalse(Str::is('foo.ar', 'foobar')); - $this->assertFalse(Str::is('foo?bar', 'foobar')); - $this->assertFalse(Str::is('foo?bar', 'fobar')); - - $this->assertTrue(Str::is([ - '*.dev', - '*oc*', - ], 'localhost.dev')); - - $this->assertFalse(Str::is([ - '/', - 'a*', - ], 'localhost.dev')); - - $this->assertFalse(Str::is([], 'localhost.dev')); - } - - public function testStrRandom() - { - $result = Str::random(20); - $this->assertIsString($result); - $this->assertEquals(20, strlen($result)); - } - - public function testStartsWith() - { - $this->assertTrue(Str::startsWith('jason', 'jas')); - $this->assertTrue(Str::startsWith('jason', ['jas'])); - $this->assertFalse(Str::startsWith('jason', 'day')); - $this->assertFalse(Str::startsWith('jason', ['day'])); - } - public function testE() { $str = 'A \'quote\' is bold'; @@ -260,80 +218,6 @@ public function testE() $this->assertEquals($str, e($html)); } - public function testEndsWith() - { - $this->assertTrue(Str::endsWith('jason', 'on')); - $this->assertTrue(Str::endsWith('jason', ['on'])); - $this->assertFalse(Str::endsWith('jason', 'no')); - $this->assertFalse(Str::endsWith('jason', ['no'])); - } - - public function testStrAfter() - { - $this->assertEquals('nah', Str::after('hannah', 'han')); - $this->assertEquals('nah', Str::after('hannah', 'n')); - $this->assertEquals('hannah', Str::after('hannah', 'xxxx')); - } - - public function testStrContains() - { - $this->assertTrue(Str::contains('taylor', 'ylo')); - $this->assertTrue(Str::contains('taylor', ['ylo'])); - $this->assertFalse(Str::contains('taylor', 'xxx')); - $this->assertFalse(Str::contains('taylor', ['xxx'])); - $this->assertTrue(Str::contains('taylor', ['xxx', 'taylor'])); - } - - public function testStrFinish() - { - $this->assertEquals('test/string/', Str::finish('test/string', '/')); - $this->assertEquals('test/string/', Str::finish('test/string/', '/')); - $this->assertEquals('test/string/', Str::finish('test/string//', '/')); - } - - public function testStrStart() - { - $this->assertEquals('/test/string', Str::start('test/string', '/')); - $this->assertEquals('/test/string', Str::start('/test/string', '/')); - $this->assertEquals('/test/string', Str::start('//test/string', '/')); - } - - public function testSnakeCase() - { - $this->assertEquals('foo_bar', Str::snake('fooBar')); - $this->assertEquals('foo_bar', Str::snake('fooBar')); // test cache - } - - public function testStrLimit() - { - $string = 'The PHP framework for web artisans.'; - $this->assertEquals('The PHP...', Str::limit($string, 7)); - $this->assertEquals('The PHP', Str::limit($string, 7, '')); - $this->assertEquals('The PHP framework for web artisans.', Str::limit($string, 100)); - - $nonAsciiString = '这是一段中文'; - $this->assertEquals('这是一...', Str::limit($nonAsciiString, 6)); - $this->assertEquals('这是一', Str::limit($nonAsciiString, 6, '')); - } - - public function testCamelCase() - { - $this->assertEquals('fooBar', Str::camel('FooBar')); - $this->assertEquals('fooBar', Str::camel('foo_bar')); - $this->assertEquals('fooBar', Str::camel('foo_bar')); // test cache - $this->assertEquals('fooBarBaz', Str::camel('Foo-barBaz')); - $this->assertEquals('fooBarBaz', Str::camel('foo-bar_baz')); - } - - public function testStudlyCase() - { - $this->assertEquals('FooBar', Str::studly('fooBar')); - $this->assertEquals('FooBar', Str::studly('foo_bar')); - $this->assertEquals('FooBar', Str::studly('foo_bar')); // test cache - $this->assertEquals('FooBarBaz', Str::studly('foo-barBaz')); - $this->assertEquals('FooBarBaz', Str::studly('foo-bar_baz')); - } - public function testClassBasename() { $this->assertEquals('Baz', class_basename('Foo\Bar\Baz')); diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index e63d5a27bd87..9860979ca49c 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -145,6 +145,13 @@ public function testSlug() $this->assertEquals('سلام-دنیا', Str::slug('سلام دنیا', '-', null)); } + public function testStrStart() + { + $this->assertEquals('/test/string', Str::start('test/string', '/')); + $this->assertEquals('/test/string', Str::start('/test/string', '/')); + $this->assertEquals('/test/string', Str::start('//test/string', '/')); + } + public function testFinish() { $this->assertEquals('abbc', Str::finish('ab', 'bc')); @@ -207,6 +214,15 @@ public function testLimit() { $this->assertEquals('Laravel is...', Str::limit('Laravel is a free, open source PHP web application framework.', 10)); $this->assertEquals('这是一...', Str::limit('这是一段中文', 6)); + + $string = 'The PHP framework for web artisans.'; + $this->assertEquals('The PHP...', Str::limit($string, 7)); + $this->assertEquals('The PHP', Str::limit($string, 7, '')); + $this->assertEquals('The PHP framework for web artisans.', Str::limit($string, 100)); + + $nonAsciiString = '这是一段中文'; + $this->assertEquals('这是一...', Str::limit($nonAsciiString, 6)); + $this->assertEquals('这是一', Str::limit($nonAsciiString, 6, '')); } public function testLength() @@ -274,6 +290,12 @@ public function testStudly() $this->assertEquals('LaravelPhpFramework', Str::studly('laravel_php_framework')); $this->assertEquals('LaravelPhPFramework', Str::studly('laravel-phP-framework')); $this->assertEquals('LaravelPhpFramework', Str::studly('laravel -_- php -_- framework ')); + + $this->assertEquals('FooBar', Str::studly('fooBar')); + $this->assertEquals('FooBar', Str::studly('foo_bar')); + $this->assertEquals('FooBar', Str::studly('foo_bar')); // test cache + $this->assertEquals('FooBarBaz', Str::studly('foo-barBaz')); + $this->assertEquals('FooBarBaz', Str::studly('foo-bar_baz')); } public function testCamel() @@ -282,6 +304,12 @@ public function testCamel() $this->assertEquals('laravelPhpFramework', Str::camel('Laravel_php_framework')); $this->assertEquals('laravelPhPFramework', Str::camel('Laravel-phP-framework')); $this->assertEquals('laravelPhpFramework', Str::camel('Laravel -_- php -_- framework ')); + + $this->assertEquals('fooBar', Str::camel('FooBar')); + $this->assertEquals('fooBar', Str::camel('foo_bar')); + $this->assertEquals('fooBar', Str::camel('foo_bar')); // test cache + $this->assertEquals('fooBarBaz', Str::camel('Foo-barBaz')); + $this->assertEquals('fooBarBaz', Str::camel('foo-bar_baz')); } public function testSubstr() From db20d3d754fa212605fad0cbcba833c714fda2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Xu=C3=A2n=20Qu=E1=BB=B3nh?= Date: Fri, 22 Feb 2019 08:42:45 +0700 Subject: [PATCH 17/78] Remove unused imports --- tests/Support/SupportHelpersTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 9ea0865546af..690435b829e9 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -7,7 +7,6 @@ use Mockery as m; use RuntimeException; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use PHPUnit\Framework\TestCase; use Illuminate\Support\Optional; use Illuminate\Contracts\Support\Htmlable; From f769ca4f2213aa7a6473772b068b88bba1b82c4b Mon Sep 17 00:00:00 2001 From: antonkomarev Date: Fri, 22 Feb 2019 15:25:30 +0300 Subject: [PATCH 18/78] Fix registering not exists observers --- .../Database/Eloquent/Concerns/HasEvents.php | 9 +++++++++ tests/Database/DatabaseEloquentModelTest.php | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php index 7f1ffd7a0636..3da14405f611 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php @@ -2,6 +2,7 @@ namespace Illuminate\Database\Eloquent\Concerns; +use RuntimeException; use Illuminate\Support\Arr; use Illuminate\Contracts\Events\Dispatcher; @@ -30,6 +31,8 @@ trait HasEvents * * @param object|array|string $classes * @return void + * + * @throws \RuntimeException */ public static function observe($classes) { @@ -45,11 +48,17 @@ public static function observe($classes) * * @param object|string $class * @return void + * + * @throws \RuntimeException */ protected function registerObserver($class) { $className = is_string($class) ? $class : get_class($class); + if (! class_exists($className)) { + throw new RuntimeException('Given observer class not exists.'); + } + // When registering a model observer, we will spin through the possible events // and determine if this observer has that method. If it does, we will hook // it into the model's event system, making it convenient to watch these. diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 2624f3e458e2..171fe767bea9 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -8,6 +8,7 @@ use Mockery as m; use LogicException; use ReflectionClass; +use RuntimeException; use DateTimeImmutable; use DateTimeInterface; use Illuminate\Support\Carbon; @@ -1310,6 +1311,18 @@ public function testModelObserversCanBeAttachedToModelsThroughAnArray() EloquentModelStub::flushEventListeners(); } + public function testThrowExceptionOnAttachingNotExistsModelObserverWithString() + { + $this->expectException(RuntimeException::class); + EloquentModelStub::observe(NotExistClass::class); + } + + public function testThrowExceptionOnAttachingNotExistsModelObserversThroughAnArray() + { + $this->expectException(RuntimeException::class); + EloquentModelStub::observe([NotExistClass::class]); + } + public function testModelObserversCanBeAttachedToModelsThroughCallingObserveMethodOnlyOnce() { EloquentModelStub::setEventDispatcher($events = m::mock(Dispatcher::class)); From a547770405179d26cb5b75e60870e1e64b595ee9 Mon Sep 17 00:00:00 2001 From: antonkomarev Date: Fri, 22 Feb 2019 17:45:19 +0300 Subject: [PATCH 19/78] Extract resolving observer class name to new method --- .../Database/Eloquent/Concerns/HasEvents.php | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php index 3da14405f611..f19158de909f 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php @@ -53,11 +53,7 @@ public static function observe($classes) */ protected function registerObserver($class) { - $className = is_string($class) ? $class : get_class($class); - - if (! class_exists($className)) { - throw new RuntimeException('Given observer class not exists.'); - } + $className = $this->resolveObserverClassName($class); // When registering a model observer, we will spin through the possible events // and determine if this observer has that method. If it does, we will hook @@ -381,4 +377,25 @@ public static function withoutEvents(callable $callback) } } } + + /** + * Resolve observer class name from object or string. + * + * @param object|string $class + * @return string + * + * @throws \RuntimeException + */ + private function resolveObserverClassName($class) + { + if (is_object($class)) { + return get_class($class); + } + + if (class_exists($class)) { + return $class; + } + + throw new RuntimeException('Given observer class not exists.'); + } } From b4dd3cee4df4243cabd3ccdbfc7a143bb8a89943 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Feb 2019 09:05:19 -0600 Subject: [PATCH 20/78] formatting --- .../Database/Eloquent/Concerns/HasEvents.php | 44 +++++++++---------- tests/Database/DatabaseEloquentModelTest.php | 5 ++- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php index f19158de909f..a8d65f734443 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php @@ -2,8 +2,8 @@ namespace Illuminate\Database\Eloquent\Concerns; -use RuntimeException; use Illuminate\Support\Arr; +use InvalidArgumentException; use Illuminate\Contracts\Events\Dispatcher; trait HasEvents @@ -65,6 +65,27 @@ protected function registerObserver($class) } } + /** + * Resolve the observer's class name from an object or string. + * + * @param object|string $class + * @return string + * + * @throws \InvalidArgumentException + */ + private function resolveObserverClassName($class) + { + if (is_object($class)) { + return get_class($class); + } + + if (class_exists($class)) { + return $class; + } + + throw new InvalidArgumentException('Unable to find observer: '.$class); + } + /** * Get the observable event names. * @@ -377,25 +398,4 @@ public static function withoutEvents(callable $callback) } } } - - /** - * Resolve observer class name from object or string. - * - * @param object|string $class - * @return string - * - * @throws \RuntimeException - */ - private function resolveObserverClassName($class) - { - if (is_object($class)) { - return get_class($class); - } - - if (class_exists($class)) { - return $class; - } - - throw new RuntimeException('Given observer class not exists.'); - } } diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 171fe767bea9..b87e5b7fc57b 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -11,6 +11,7 @@ use RuntimeException; use DateTimeImmutable; use DateTimeInterface; +use InvalidArgumentException; use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; @@ -1313,13 +1314,13 @@ public function testModelObserversCanBeAttachedToModelsThroughAnArray() public function testThrowExceptionOnAttachingNotExistsModelObserverWithString() { - $this->expectException(RuntimeException::class); + $this->expectException(InvalidArgumentException::class); EloquentModelStub::observe(NotExistClass::class); } public function testThrowExceptionOnAttachingNotExistsModelObserversThroughAnArray() { - $this->expectException(RuntimeException::class); + $this->expectException(InvalidArgumentException::class); EloquentModelStub::observe([NotExistClass::class]); } From f0504da67feda7c77fcdddb5c3130d6308b50308 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Feb 2019 09:06:02 -0600 Subject: [PATCH 21/78] Apply fixes from StyleCI (#27628) --- tests/Database/DatabaseEloquentModelTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index b87e5b7fc57b..fc44e2450203 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -8,7 +8,6 @@ use Mockery as m; use LogicException; use ReflectionClass; -use RuntimeException; use DateTimeImmutable; use DateTimeInterface; use InvalidArgumentException; From 09e9f8ee8132a727bfe4e0f1c8e36ed67952bad7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Feb 2019 09:10:25 -0600 Subject: [PATCH 22/78] Apply fixes from StyleCI (#27629) --- tests/Queue/QueueBeanstalkdQueueTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Queue/QueueBeanstalkdQueueTest.php b/tests/Queue/QueueBeanstalkdQueueTest.php index ac9aaf5b5ab0..9308869ac6b5 100755 --- a/tests/Queue/QueueBeanstalkdQueueTest.php +++ b/tests/Queue/QueueBeanstalkdQueueTest.php @@ -9,7 +9,6 @@ use Illuminate\Container\Container; use Illuminate\Queue\BeanstalkdQueue; use Illuminate\Queue\Jobs\BeanstalkdJob; -use Pheanstalk\Contract\PheanstalkInterface; class QueueBeanstalkdQueueTest extends TestCase { From 84baec2a7c7053e0360dbb7403e6b1c403cb5b3e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Feb 2019 09:26:56 -0600 Subject: [PATCH 23/78] fix docblock --- src/Illuminate/Mail/Mailer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Mail/Mailer.php b/src/Illuminate/Mail/Mailer.php index bda44d62561d..aac857483c79 100755 --- a/src/Illuminate/Mail/Mailer.php +++ b/src/Illuminate/Mail/Mailer.php @@ -62,9 +62,9 @@ class Mailer implements MailerContract, MailQueueContract protected $to; /** - * The queue implementation. + * The queue factory implementation. * - * @var \Illuminate\Contracts\Queue\Queue + * @var \Illuminate\Contracts\Queue\Factory */ protected $queue; From 3c0412b42b73b84690ba963b6a6a28e016fc105b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Feb 2019 09:36:47 -0600 Subject: [PATCH 24/78] formatting --- src/Illuminate/Foundation/Console/RouteListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 32e37ebd3a9b..02a416c205c7 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -72,7 +72,7 @@ public function handle() } if (empty($routes = $this->getRoutes())) { - return $this->info('Could not find any matched routes.'); + return $this->error("Your application doesn't have any routes matching the given criteria."); } $this->displayRoutes($routes); From 1ecc4bf0771362899d6e87a65d20ec3a4a6f2012 Mon Sep 17 00:00:00 2001 From: Filipe Bojikian Rissi Date: Fri, 22 Feb 2019 17:08:18 -0300 Subject: [PATCH 25/78] Fix the error by including files in the handler exception because the files were read and the stream no longer exists. --- src/Illuminate/Foundation/Exceptions/Handler.php | 2 +- src/Illuminate/Http/Concerns/InteractsWithInput.php | 5 +++-- tests/Http/HttpRequestTest.php | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index d6d61dbec023..a35d71b9b8d0 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -249,7 +249,7 @@ protected function convertValidationExceptionToResponse(ValidationException $e, protected function invalid($request, ValidationException $exception) { return redirect($exception->redirectTo ?? url()->previous()) - ->withInput($request->except($this->dontFlash)) + ->withInput($request->except($this->dontFlash, false)) ->withErrors($exception->errors(), $exception->errorBag); } diff --git a/src/Illuminate/Http/Concerns/InteractsWithInput.php b/src/Illuminate/Http/Concerns/InteractsWithInput.php index b1e9b830ba37..57e654d360b3 100644 --- a/src/Illuminate/Http/Concerns/InteractsWithInput.php +++ b/src/Illuminate/Http/Concerns/InteractsWithInput.php @@ -239,13 +239,14 @@ public function only($keys) * Get all of the input except for a specified array of items. * * @param array|mixed $keys + * @param bool $includeFiles * @return array */ - public function except($keys) + public function except($keys, $includeFiles = true) { $keys = is_array($keys) ? $keys : func_get_args(); - $results = $this->all(); + $results = $includeFiles ? $this->all() : $this->input(); Arr::forget($results, $keys); diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index d047b4ef3633..75c42c3593ab 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -8,6 +8,7 @@ use Illuminate\Session\Store; use PHPUnit\Framework\TestCase; use Illuminate\Http\UploadedFile; +use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; @@ -512,6 +513,18 @@ public function testFileMethod() $this->assertInstanceOf(SymfonyUploadedFile::class, $request->file('foo')); } + public function testValidateFileMethod() + { + $file = $this->getMockBuilder(SymfonyUploadedFile::class)->setConstructorArgs([__FILE__, 'photo.jpg', ''])->getMock(); + $file->method('isValid')->willReturn(false); + $file->method('getPathname')->willReturn('photo.jpg'); + $file->method('getClientOriginalName')->willReturn('photo.jpg'); + $request = Request::create('/', 'GET', [], [], ['photo' => $file]); + $request->except([], false); + $this->expectException(FileNotFoundException::class); + $request->except([]); + } + public function testHasFileMethod() { $request = Request::create('/', 'GET', [], [], []); From 31b935917a8516c99bfdd0ca1c3aadcb7dbf8850 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 22 Feb 2019 21:22:47 +0100 Subject: [PATCH 26/78] Test cache has method with false value An issue was filed which caused some confusion about false being a valid cache value with the has method. Turns out that the current implementation is the correct one but the behavior wasn't tested yet. This extra test makes it clear. More on valid data values: https://www.php-fig.org/psr/psr-16/#14-data Referenced issue: https://github.com/laravel/framework/issues/27630 --- tests/Cache/CacheRepositoryTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Cache/CacheRepositoryTest.php b/tests/Cache/CacheRepositoryTest.php index b88cafec0f45..2cba6cec5f3f 100755 --- a/tests/Cache/CacheRepositoryTest.php +++ b/tests/Cache/CacheRepositoryTest.php @@ -66,9 +66,11 @@ public function testHasMethod() $repo = $this->getRepository(); $repo->getStore()->shouldReceive('get')->once()->with('foo')->andReturn(null); $repo->getStore()->shouldReceive('get')->once()->with('bar')->andReturn('bar'); + $repo->getStore()->shouldReceive('get')->once()->with('baz')->andReturn(false); $this->assertTrue($repo->has('bar')); $this->assertFalse($repo->has('foo')); + $this->assertTrue($repo->has('baz')); } public function testMissingMethod() From a42d6976fc7bd17097f38e8990d53acaeb5e77c2 Mon Sep 17 00:00:00 2001 From: Filipe Bojikian Rissi Date: Fri, 22 Feb 2019 17:52:00 -0300 Subject: [PATCH 27/78] Organize import. --- tests/Http/HttpRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index 75c42c3593ab..b1214c577c62 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -8,8 +8,8 @@ use Illuminate\Session\Store; use PHPUnit\Framework\TestCase; use Illuminate\Http\UploadedFile; -use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; +use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; class HttpRequestTest extends TestCase From 27164a6bdb0d5571d0d01abd92a53d321d729d26 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Sat, 23 Feb 2019 12:36:31 +0100 Subject: [PATCH 28/78] Use proper method name for Pheanstalk --- src/Illuminate/Queue/Connectors/BeanstalkdConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php b/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php index a9c1173b94c4..38673edbde63 100755 --- a/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php +++ b/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php @@ -32,7 +32,7 @@ public function connect(array $config) */ protected function pheanstalk(array $config) { - return Pheanstalk::connect( + return Pheanstalk::create( $config['host'], $config['port'] ?? Pheanstalk::DEFAULT_PORT, $config['timeout'] ?? Connection::DEFAULT_CONNECT_TIMEOUT From 275dc0831fa39a70ab74a989b069cee659a14841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Xu=C3=A2n=20Qu=E1=BB=B3nh?= Date: Sat, 23 Feb 2019 20:47:11 +0700 Subject: [PATCH 29/78] Move Arr tests to the right location --- tests/Support/SupportArrTest.php | 103 +++++++++- tests/Support/SupportHelpersTest.php | 274 --------------------------- 2 files changed, 99 insertions(+), 278 deletions(-) diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 72661b35ed17..e254abea52ca 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -29,12 +29,18 @@ public function testAdd() { $array = Arr::add(['name' => 'Desk'], 'price', 100); $this->assertEquals(['name' => 'Desk', 'price' => 100], $array); + + $this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov')); + $this->assertEquals(['developer' => ['name' => 'Ferid']], Arr::add([], 'developer.name', 'Ferid')); } public function testCollapse() { $data = [['foo', 'bar'], ['baz']]; $this->assertEquals(['foo', 'bar', 'baz'], Arr::collapse($data)); + + $array = [[1], [2], [3], ['foo', 'bar'], collect(['baz', 'boom'])]; + $this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], Arr::collapse($array)); } public function testCrossJoin() @@ -102,13 +108,21 @@ public function testDot() $array = Arr::dot(['foo' => ['bar' => []]]); $this->assertEquals(['foo.bar' => []], $array); + + $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]); + $this->assertEquals($array, ['name' => 'taylor', 'languages.php' => true]); } public function testExcept() { - $array = ['name' => 'Desk', 'price' => 100]; - $array = Arr::except($array, ['price']); - $this->assertEquals(['name' => 'Desk'], $array); + $array = ['name' => 'taylor', 'age' => 26]; + $this->assertEquals(['age' => 26], Arr::except($array, ['name'])); + $this->assertEquals(['age' => 26], Arr::except($array, 'name')); + + $array = ['name' => 'taylor', 'framework' => ['language' => 'PHP', 'name' => 'Laravel']]; + $this->assertEquals(['name' => 'taylor'], Arr::except($array, 'framework')); + $this->assertEquals(['name' => 'taylor', 'framework' => ['name' => 'Laravel']], Arr::except($array, 'framework.language')); + $this->assertEquals(['framework' => ['language' => 'PHP']], Arr::except($array, ['name', 'framework.name'])); } public function testExists() @@ -282,6 +296,13 @@ public function testGet() ]; $this->assertEquals('desk', Arr::get($array, 'products.0.name')); $this->assertEquals('chair', Arr::get($array, 'products.1.name')); + + // Test return default value for non-existing key. + $array = ['names' => ['developer' => 'taylor']]; + $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', 'dayle')); + $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', function () { + return 'dayle'; + })); } public function testHas() @@ -361,10 +382,45 @@ public function testOnly() $array = ['name' => 'Desk', 'price' => 100, 'orders' => 10]; $array = Arr::only($array, ['name', 'price']); $this->assertEquals(['name' => 'Desk', 'price' => 100], $array); + $this->assertEmpty(Arr::only($array, ['nonExistingKey'])); } public function testPluck() { + $data = [ + 'post-1' => [ + 'comments' => [ + 'tags' => [ + '#foo', '#bar', + ], + ], + ], + 'post-2' => [ + 'comments' => [ + 'tags' => [ + '#baz', + ], + ], + ], + ]; + + $this->assertEquals([ + 0 => [ + 'tags' => [ + '#foo', '#bar', + ], + ], + 1 => [ + 'tags' => [ + '#baz', + ], + ], + ], Arr::pluck($data, 'comments')); + + $this->assertEquals([['#foo', '#bar'], ['#baz']], Arr::pluck($data, 'comments.tags')); + $this->assertEquals([null, null], Arr::pluck($data, 'foo')); + $this->assertEquals([null, null], Arr::pluck($data, 'foo.bar')); + $array = [ ['developer' => ['name' => 'Taylor']], ['developer' => ['name' => 'Abigail']], @@ -415,6 +471,45 @@ public function testPluckWithCarbonKeys() $this->assertEquals(['2017-07-25 00:00:00' => '2017-07-30 00:00:00'], $array); } + public function testArrayPluckWithArrayAndObjectValues() + { + $array = [(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']]; + $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'name')); + $this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], Arr::pluck($array, 'email', 'name')); + } + + public function testArrayPluckWithNestedKeys() + { + $array = [['user' => ['taylor', 'otwell']], ['user' => ['dayle', 'rees']]]; + $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'user.0')); + $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, ['user', 0])); + $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, 'user.1', 'user.0')); + $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, ['user', 1], ['user', 0])); + } + + public function testArrayPluckWithNestedArrays() + { + $array = [ + [ + 'account' => 'a', + 'users' => [ + ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'], + ], + ], + [ + 'account' => 'b', + 'users' => [ + ['first' => 'abigail', 'last' => 'otwell'], + ['first' => 'dayle', 'last' => 'rees'], + ], + ], + ]; + + $this->assertEquals([['taylor'], ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first')); + $this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first', 'account')); + $this->assertEquals([['taylorotwell@gmail.com'], [null, null]], Arr::pluck($array, 'users.*.email')); + } + public function testPrepend() { $array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero'); @@ -633,7 +728,7 @@ public function testWhere() return is_string($value); }); - $this->assertEquals([1 => 200, 3 => 400], $array); + $this->assertEquals([1 => '200', 3 => '400'], $array); } public function testWhereKey() diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 690435b829e9..694e6405c164 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -6,7 +6,6 @@ use ArrayAccess; use Mockery as m; use RuntimeException; -use Illuminate\Support\Arr; use PHPUnit\Framework\TestCase; use Illuminate\Support\Optional; use Illuminate\Contracts\Support\Htmlable; @@ -18,196 +17,6 @@ protected function tearDown(): void m::close(); } - public function testArrayDot() - { - $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]); - $this->assertEquals($array, ['name' => 'taylor', 'languages.php' => true]); - } - - public function testArrayGet() - { - $array = ['names' => ['developer' => 'taylor']]; - $this->assertEquals('taylor', Arr::get($array, 'names.developer')); - $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', 'dayle')); - $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', function () { - return 'dayle'; - })); - } - - public function testArrayHas() - { - $array = ['names' => ['developer' => 'taylor']]; - $this->assertTrue(Arr::has($array, 'names')); - $this->assertTrue(Arr::has($array, 'names.developer')); - $this->assertFalse(Arr::has($array, 'foo')); - $this->assertFalse(Arr::has($array, 'foo.bar')); - } - - public function testArraySet() - { - $array = []; - Arr::set($array, 'names.developer', 'taylor'); - $this->assertEquals('taylor', $array['names']['developer']); - } - - public function testArrayForget() - { - $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle']]; - Arr::forget($array, 'names.developer'); - $this->assertFalse(isset($array['names']['developer'])); - $this->assertTrue(isset($array['names']['otherDeveloper'])); - - $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle', 'thirdDeveloper' => 'Lucas']]; - Arr::forget($array, ['names.developer', 'names.otherDeveloper']); - $this->assertFalse(isset($array['names']['developer'])); - $this->assertFalse(isset($array['names']['otherDeveloper'])); - $this->assertTrue(isset($array['names']['thirdDeveloper'])); - - $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas', 'otherDeveloper' => 'Graham']]; - Arr::forget($array, ['names.developer', 'otherNames.otherDeveloper']); - $expected = ['names' => ['otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas']]; - $this->assertEquals($expected, $array); - } - - public function testArrayPluckWithArrayAndObjectValues() - { - $array = [(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']]; - $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'name')); - $this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], Arr::pluck($array, 'email', 'name')); - } - - public function testArrayPluckWithNestedKeys() - { - $array = [['user' => ['taylor', 'otwell']], ['user' => ['dayle', 'rees']]]; - $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'user.0')); - $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, ['user', 0])); - $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, 'user.1', 'user.0')); - $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, ['user', 1], ['user', 0])); - } - - public function testArrayPluckWithNestedArrays() - { - $array = [ - [ - 'account' => 'a', - 'users' => [ - ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'], - ], - ], - [ - 'account' => 'b', - 'users' => [ - ['first' => 'abigail', 'last' => 'otwell'], - ['first' => 'dayle', 'last' => 'rees'], - ], - ], - ]; - - $this->assertEquals([['taylor'], ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first')); - $this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first', 'account')); - $this->assertEquals([['taylorotwell@gmail.com'], [null, null]], Arr::pluck($array, 'users.*.email')); - } - - public function testArrayExcept() - { - $array = ['name' => 'taylor', 'age' => 26]; - $this->assertEquals(['age' => 26], Arr::except($array, ['name'])); - $this->assertEquals(['age' => 26], Arr::except($array, 'name')); - - $array = ['name' => 'taylor', 'framework' => ['language' => 'PHP', 'name' => 'Laravel']]; - $this->assertEquals(['name' => 'taylor'], Arr::except($array, 'framework')); - $this->assertEquals(['name' => 'taylor', 'framework' => ['name' => 'Laravel']], Arr::except($array, 'framework.language')); - $this->assertEquals(['framework' => ['language' => 'PHP']], Arr::except($array, ['name', 'framework.name'])); - } - - public function testArrayOnly() - { - $array = ['name' => 'taylor', 'age' => 26]; - $this->assertEquals(['name' => 'taylor'], Arr::only($array, ['name'])); - $this->assertEmpty(Arr::only($array, ['nonExistingKey'])); - } - - public function testArrayCollapse() - { - $array = [[1], [2], [3], ['foo', 'bar'], collect(['baz', 'boom'])]; - $this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], Arr::collapse($array)); - } - - public function testArrayDivide() - { - $array = ['name' => 'taylor']; - [$keys, $values] = Arr::divide($array); - $this->assertEquals(['name'], $keys); - $this->assertEquals(['taylor'], $values); - } - - public function testArrayFirst() - { - $array = ['name' => 'taylor', 'otherDeveloper' => 'dayle']; - $this->assertEquals('dayle', Arr::first($array, function ($value) { - return $value == 'dayle'; - })); - } - - public function testArrayLast() - { - $array = [100, 250, 290, 320, 500, 560, 670]; - $this->assertEquals(670, Arr::last($array, function ($value) { - return $value > 320; - })); - } - - public function testArrayPluck() - { - $data = [ - 'post-1' => [ - 'comments' => [ - 'tags' => [ - '#foo', '#bar', - ], - ], - ], - 'post-2' => [ - 'comments' => [ - 'tags' => [ - '#baz', - ], - ], - ], - ]; - - $this->assertEquals([ - 0 => [ - 'tags' => [ - '#foo', '#bar', - ], - ], - 1 => [ - 'tags' => [ - '#baz', - ], - ], - ], Arr::pluck($data, 'comments')); - - $this->assertEquals([['#foo', '#bar'], ['#baz']], Arr::pluck($data, 'comments.tags')); - $this->assertEquals([null, null], Arr::pluck($data, 'foo')); - $this->assertEquals([null, null], Arr::pluck($data, 'foo.bar')); - } - - public function testArrayPrepend() - { - $array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero'); - $this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $array); - - $array = Arr::prepend(['one' => 1, 'two' => 2], 0, 'zero'); - $this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $array); - } - - public function testArrayFlatten() - { - $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten([['#foo', '#bar'], ['#baz']])); - } - public function testE() { $str = 'A \'quote\' is bold'; @@ -499,76 +308,6 @@ public function testDataSetWithDoubleStar() ], $data); } - public function testArraySort() - { - $array = [ - ['name' => 'baz'], - ['name' => 'foo'], - ['name' => 'bar'], - ]; - - $this->assertEquals([ - ['name' => 'bar'], - ['name' => 'baz'], - ['name' => 'foo'], ], - array_values(Arr::sort($array, function ($v) { - return $v['name']; - }))); - } - - public function testArraySortRecursive() - { - $array = [ - [ - 'foo', - 'bar', - 'baz', - ], - [ - 'baz', - 'foo', - 'bar', - ], - ]; - - $assumedArray = [ - [ - 'bar', - 'baz', - 'foo', - ], - [ - 'bar', - 'baz', - 'foo', - ], - ]; - - $this->assertEquals($assumedArray, Arr::sortRecursive($array)); - } - - public function testArrayWhere() - { - $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8]; - $this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6, 'h' => 8], Arr::where( - $array, - function ($value, $key) { - return $value % 2 === 0; - } - )); - } - - public function testArrayWrap() - { - $string = 'a'; - $array = ['a']; - $object = new stdClass; - $object->value = 'a'; - $this->assertEquals(['a'], Arr::wrap($string)); - $this->assertEquals($array, Arr::wrap($array)); - $this->assertEquals([$object], Arr::wrap($object)); - } - public function testHead() { $array = ['a', 'b', 'c']; @@ -609,19 +348,6 @@ public function testClassUsesRecursiveReturnParentTraitsFirst() class_uses_recursive(SupportTestClassThree::class)); } - public function testArrayAdd() - { - $this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov')); - $this->assertEquals(['developer' => ['name' => 'Ferid']], Arr::add([], 'developer.name', 'Ferid')); - } - - public function testArrayPull() - { - $developer = ['firstname' => 'Ferid', 'surname' => 'Mövsümov']; - $this->assertEquals('Mövsümov', Arr::pull($developer, 'surname')); - $this->assertEquals(['firstname' => 'Ferid'], $developer); - } - public function testTap() { $object = (object) ['id' => 1]; From 838a47599dd7fb0597656cf71ce4e18c7d9051b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Xu=C3=A2n=20Qu=E1=BB=B3nh?= Date: Sat, 23 Feb 2019 20:57:12 +0700 Subject: [PATCH 30/78] Fix BoundMethod dockblock --- src/Illuminate/Container/BoundMethod.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Illuminate/Container/BoundMethod.php b/src/Illuminate/Container/BoundMethod.php index 2786c6a7d388..f5d4bba39a69 100644 --- a/src/Illuminate/Container/BoundMethod.php +++ b/src/Illuminate/Container/BoundMethod.php @@ -17,6 +17,9 @@ class BoundMethod * @param array $parameters * @param string|null $defaultMethod * @return mixed + * + * @throws \ReflectionException + * @throws \InvalidArgumentException */ public static function call($container, $callback, array $parameters = [], $defaultMethod = null) { @@ -107,6 +110,8 @@ protected static function normalizeMethod($callback) * @param callable|string $callback * @param array $parameters * @return array + * + * @throws \ReflectionException */ protected static function getMethodDependencies($container, $callback, array $parameters = []) { From 057ace25d8712a7b3142e10dd2e51f436bea2a0f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 23 Feb 2019 09:01:19 -0600 Subject: [PATCH 31/78] formatting --- src/Illuminate/Support/ServiceProvider.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Support/ServiceProvider.php b/src/Illuminate/Support/ServiceProvider.php index fb98d376a079..bce901a7d7ad 100755 --- a/src/Illuminate/Support/ServiceProvider.php +++ b/src/Illuminate/Support/ServiceProvider.php @@ -48,6 +48,16 @@ public function __construct($app) $this->app = $app; } + /** + * Register any application services. + * + * @return void + */ + public function register() + { + // + } + /** * Merge the given configuration with the existing configuration. * @@ -273,16 +283,6 @@ public function commands($commands) }); } - /** - * Register services. - * - * @return void - */ - public function register() - { - // - } - /** * Get the services provided by the provider. * From 8107fe1d3769fdef35a8ccb85d9ff0d942380394 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Sun, 24 Feb 2019 02:36:06 +0200 Subject: [PATCH 32/78] [5.7] update changelog --- CHANGELOG-5.7.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-5.7.md b/CHANGELOG-5.7.md index c413d5095355..a0deb9f078d3 100644 --- a/CHANGELOG-5.7.md +++ b/CHANGELOG-5.7.md @@ -1,6 +1,16 @@ # Release Notes for 5.7.x -## [Unreleased](https://github.com/laravel/framework/compare/v5.7.26...5.7) +## [Unreleased](https://github.com/laravel/framework/compare/v5.7.27...5.7) + +### Added +- Add support for `Pheanstalk 4.x` ([#27622](https://github.com/laravel/framework/pull/27622)) + +### Fixed +- Fixed Postgres grammar when using union queries ([#27589](https://github.com/laravel/framework/pull/27589)) + +### TODO: +- https://github.com/laravel/framework/pull/27585 +- https://github.com/laravel/framework/pull/27618 ## [v5.7.26 (2019-02-12)](https://github.com/laravel/framework/compare/v5.7.25...v5.7.26) From 3061ebade0b266668b64cfefd6993e0ea67cffae Mon Sep 17 00:00:00 2001 From: Ankur Kumar Date: Sun, 24 Feb 2019 20:27:29 +0530 Subject: [PATCH 33/78] [5.7] Update vue preset to exclude @babel/preset-react Laravel Mix v3+ is using babel 7 which has a new name for this preset https://www.npmjs.com/package/@babel/preset-react --- src/Illuminate/Foundation/Console/Presets/Vue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/Presets/Vue.php b/src/Illuminate/Foundation/Console/Presets/Vue.php index d25ffb8dd141..6d79fa1f2ec1 100644 --- a/src/Illuminate/Foundation/Console/Presets/Vue.php +++ b/src/Illuminate/Foundation/Console/Presets/Vue.php @@ -31,7 +31,7 @@ public static function install() protected static function updatePackageArray(array $packages) { return ['vue' => '^2.5.17'] + Arr::except($packages, [ - 'babel-preset-react', + '@babel/preset-react', 'react', 'react-dom', ]); From 6b94e3b5742f2e74c2529a0ed6936c2094d530a0 Mon Sep 17 00:00:00 2001 From: Abdel Date: Sun, 24 Feb 2019 10:03:48 -0500 Subject: [PATCH 34/78] Reflash the session for the broadcasting auth call. --- src/Illuminate/Broadcasting/BroadcastController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Broadcasting/BroadcastController.php b/src/Illuminate/Broadcasting/BroadcastController.php index f71c9237711d..486a60234066 100644 --- a/src/Illuminate/Broadcasting/BroadcastController.php +++ b/src/Illuminate/Broadcasting/BroadcastController.php @@ -16,6 +16,10 @@ class BroadcastController extends Controller */ public function authenticate(Request $request) { + if ($request->hasSession()) { + $request->session()->reflash(); + } + return Broadcast::auth($request); } } From d7af95076174a6887ab598b5b9b3789e448edfa3 Mon Sep 17 00:00:00 2001 From: Filipe Bojikian Rissi Date: Sun, 24 Feb 2019 15:45:26 -0300 Subject: [PATCH 35/78] Remove flag and adds test that checks value passed to the method withInput. --- .../Foundation/Exceptions/Handler.php | 2 +- .../Http/Concerns/InteractsWithInput.php | 5 +- .../FoundationExceptionsHandlerTest.php | 46 +++++++++++++++++++ tests/Http/HttpRequestTest.php | 13 ------ 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index a35d71b9b8d0..bd40a3ac34e1 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -249,7 +249,7 @@ protected function convertValidationExceptionToResponse(ValidationException $e, protected function invalid($request, ValidationException $exception) { return redirect($exception->redirectTo ?? url()->previous()) - ->withInput($request->except($this->dontFlash, false)) + ->withInput(array_except($request->input(), $this->dontFlash)) ->withErrors($exception->errors(), $exception->errorBag); } diff --git a/src/Illuminate/Http/Concerns/InteractsWithInput.php b/src/Illuminate/Http/Concerns/InteractsWithInput.php index 57e654d360b3..b1e9b830ba37 100644 --- a/src/Illuminate/Http/Concerns/InteractsWithInput.php +++ b/src/Illuminate/Http/Concerns/InteractsWithInput.php @@ -239,14 +239,13 @@ public function only($keys) * Get all of the input except for a specified array of items. * * @param array|mixed $keys - * @param bool $includeFiles * @return array */ - public function except($keys, $includeFiles = true) + public function except($keys) { $keys = is_array($keys) ? $keys : func_get_args(); - $results = $includeFiles ? $this->all() : $this->input(); + $results = $this->all(); Arr::forget($results, $keys); diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index a27da4b4a81b..d884d48e138b 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -8,13 +8,18 @@ use RuntimeException; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; +use Illuminate\Support\MessageBag; use Illuminate\Routing\Redirector; use Illuminate\Container\Container; +use Illuminate\Validation\Validator; +use Illuminate\Http\RedirectResponse; use Illuminate\Contracts\View\Factory; use Illuminate\Routing\ResponseFactory; use Illuminate\Config\Repository as Config; use Illuminate\Contracts\Support\Responsable; use Illuminate\Foundation\Exceptions\Handler; +use Illuminate\Validation\ValidationException; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; @@ -130,6 +135,47 @@ public function testReturnsJsonWithoutStackTraceWhenAjaxRequestAndDebugFalseAndA $this->assertNotContains('"line":', $response); $this->assertNotContains('"trace":', $response); } + + public function testValidateFileMethod() + { + $argumentExpected = ['input' => 'My input value']; + $argumentActual = null; + + $this->container->singleton('redirect', function () use ($argumentExpected, &$argumentActual) { + $redirector = m::mock(Redirector::class); + + $redirector->shouldReceive('to')->once() + ->andReturn($responser = m::mock(RedirectResponse::class)); + + $responser->shouldReceive('withInput')->once()->with(m::on(function ($argument) use ($argumentExpected, &$argumentActual) { + $argumentActual = $argument; + return true; + }))->andReturn($responser); + + $responser->shouldReceive('withErrors')->once() + ->andReturn($responser); + + return $redirector; + }); + + $this->request->shouldReceive('expectsJson')->once()->andReturn(false); + $this->request->shouldReceive('input')->once()->andReturn($argumentExpected); + + $file = m::mock(UploadedFile::class); + $file->shouldReceive('isValid')->zeroOrMoreTimes()->andReturn(false); + $file->shouldReceive('getPathname')->zeroOrMoreTimes()->andReturn('photo.jpg'); + $file->shouldReceive('getClientOriginalName')->zeroOrMoreTimes()->andReturn('photo.jpg'); + + $validator = m::mock(Validator::class); + $validator->shouldReceive('errors')->andReturn(new MessageBag(['error' => 'My custom validation exception'])); + + $validationException = new ValidationException($validator); + $validationException->redirectTo = '/'; + + $this->handler->render($this->request, $validationException); + + $this->assertEquals($argumentExpected, $argumentActual); + } } class CustomException extends Exception implements Responsable diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index b1214c577c62..d047b4ef3633 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\TestCase; use Illuminate\Http\UploadedFile; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; -use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; class HttpRequestTest extends TestCase @@ -513,18 +512,6 @@ public function testFileMethod() $this->assertInstanceOf(SymfonyUploadedFile::class, $request->file('foo')); } - public function testValidateFileMethod() - { - $file = $this->getMockBuilder(SymfonyUploadedFile::class)->setConstructorArgs([__FILE__, 'photo.jpg', ''])->getMock(); - $file->method('isValid')->willReturn(false); - $file->method('getPathname')->willReturn('photo.jpg'); - $file->method('getClientOriginalName')->willReturn('photo.jpg'); - $request = Request::create('/', 'GET', [], [], ['photo' => $file]); - $request->except([], false); - $this->expectException(FileNotFoundException::class); - $request->except([]); - } - public function testHasFileMethod() { $request = Request::create('/', 'GET', [], [], []); From fcf92aefc864724e4662afe612e1af27fe18528b Mon Sep 17 00:00:00 2001 From: Filipe Bojikian Rissi Date: Sun, 24 Feb 2019 15:47:25 -0300 Subject: [PATCH 36/78] Remove flag and adds test that checks value passed to the method withInput. --- tests/Foundation/FoundationExceptionsHandlerTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index d884d48e138b..6269e12d31f5 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -8,8 +8,8 @@ use RuntimeException; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; -use Illuminate\Support\MessageBag; use Illuminate\Routing\Redirector; +use Illuminate\Support\MessageBag; use Illuminate\Container\Container; use Illuminate\Validation\Validator; use Illuminate\Http\RedirectResponse; @@ -141,7 +141,7 @@ public function testValidateFileMethod() $argumentExpected = ['input' => 'My input value']; $argumentActual = null; - $this->container->singleton('redirect', function () use ($argumentExpected, &$argumentActual) { + $this->container->singleton('redirect', function () use ($argumentExpected, &$argumentActual) { $redirector = m::mock(Redirector::class); $redirector->shouldReceive('to')->once() @@ -149,6 +149,7 @@ public function testValidateFileMethod() $responser->shouldReceive('withInput')->once()->with(m::on(function ($argument) use ($argumentExpected, &$argumentActual) { $argumentActual = $argument; + return true; }))->andReturn($responser); From 97b2899ed23cb2ddd679702c349108c375525c99 Mon Sep 17 00:00:00 2001 From: Yohanan Baruchel Date: Sun, 24 Feb 2019 20:58:51 +0200 Subject: [PATCH 37/78] Use safe container getter on Pipeline carry --- src/Illuminate/Pipeline/Pipeline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Pipeline/Pipeline.php b/src/Illuminate/Pipeline/Pipeline.php index a2331ff3168b..626f87be0b20 100644 --- a/src/Illuminate/Pipeline/Pipeline.php +++ b/src/Illuminate/Pipeline/Pipeline.php @@ -164,7 +164,7 @@ protected function carry() : $pipe(...$parameters); return $response instanceof Responsable - ? $response->toResponse($this->container->make(Request::class)) + ? $response->toResponse($this->getContainer()->make(Request::class)) : $response; }; }; From 604dfa79648e966a6511e08ad6b71cdd742bb282 Mon Sep 17 00:00:00 2001 From: Filipe Bojikian Rissi Date: Sun, 24 Feb 2019 18:22:16 -0300 Subject: [PATCH 38/78] Remove mock request and use an instance. --- .../FoundationExceptionsHandlerTest.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index 6269e12d31f5..f8406bfb00bf 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -6,6 +6,7 @@ use Exception; use Mockery as m; use RuntimeException; +use Illuminate\Http\Request; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; use Illuminate\Routing\Redirector; @@ -141,17 +142,18 @@ public function testValidateFileMethod() $argumentExpected = ['input' => 'My input value']; $argumentActual = null; - $this->container->singleton('redirect', function () use ($argumentExpected, &$argumentActual) { + $this->container->singleton('redirect', function () use (&$argumentActual) { $redirector = m::mock(Redirector::class); $redirector->shouldReceive('to')->once() ->andReturn($responser = m::mock(RedirectResponse::class)); - $responser->shouldReceive('withInput')->once()->with(m::on(function ($argument) use ($argumentExpected, &$argumentActual) { - $argumentActual = $argument; + $responser->shouldReceive('withInput')->once()->with(m::on( + function ($argument) use (&$argumentActual) { + $argumentActual = $argument; - return true; - }))->andReturn($responser); + return true; + }))->andReturn($responser); $responser->shouldReceive('withErrors')->once() ->andReturn($responser); @@ -159,13 +161,13 @@ public function testValidateFileMethod() return $redirector; }); - $this->request->shouldReceive('expectsJson')->once()->andReturn(false); - $this->request->shouldReceive('input')->once()->andReturn($argumentExpected); - $file = m::mock(UploadedFile::class); - $file->shouldReceive('isValid')->zeroOrMoreTimes()->andReturn(false); - $file->shouldReceive('getPathname')->zeroOrMoreTimes()->andReturn('photo.jpg'); - $file->shouldReceive('getClientOriginalName')->zeroOrMoreTimes()->andReturn('photo.jpg'); + $file->shouldReceive('getPathname')->andReturn('photo.jpg'); + $file->shouldReceive('getClientOriginalName')->andReturn('photo.jpg'); + $file->shouldReceive('getClientMimeType')->andReturn(null); + $file->shouldReceive('getError')->andReturn(null); + + $request = Request::create('/', 'POST', $argumentExpected, [], ['photo' => $file]); $validator = m::mock(Validator::class); $validator->shouldReceive('errors')->andReturn(new MessageBag(['error' => 'My custom validation exception'])); @@ -173,7 +175,7 @@ public function testValidateFileMethod() $validationException = new ValidationException($validator); $validationException->redirectTo = '/'; - $this->handler->render($this->request, $validationException); + $this->handler->render($request, $validationException); $this->assertEquals($argumentExpected, $argumentActual); } From dbd3b78dfb3974e7376671399a53fef780f03052 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 25 Feb 2019 11:09:28 +0100 Subject: [PATCH 39/78] Replace helper --- src/Illuminate/Foundation/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 319a56425dec..b84aee7575af 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -249,7 +249,7 @@ protected function convertValidationExceptionToResponse(ValidationException $e, protected function invalid($request, ValidationException $exception) { return redirect($exception->redirectTo ?? url()->previous()) - ->withInput(array_except($request->input(), $this->dontFlash)) + ->withInput(Arr::except($request->input(), $this->dontFlash)) ->withErrors($exception->errors(), $exception->errorBag); } From 931a4371f42d4a095ac8803dbcd838f510db191a Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Mon, 25 Feb 2019 21:28:01 -0300 Subject: [PATCH 40/78] [5.7] Basic Auth Middleware - Improving readability Following: https://github.com/laravel/docs/pull/5005 --- .../Auth/Middleware/AuthenticateWithBasicAuth.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php b/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php index c51df9064e4f..92c81e68be47 100644 --- a/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php +++ b/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php @@ -33,9 +33,13 @@ public function __construct(AuthFactory $auth) * @param string|null $guard * @param string|null $field * @return mixed + * + * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException */ public function handle($request, Closure $next, $guard = null, $field = null) { - return $this->auth->guard($guard)->basic($field ?: 'email') ?: $next($request); + $this->auth->guard($guard)->basic($field ?: 'email'); + + return $next($request); } } From b176ecc937c587534837869e517b1daa20659054 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Feb 2019 20:19:54 -0600 Subject: [PATCH 41/78] support postmark driver --- src/Illuminate/Mail/TransportManager.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 5ccfb3e54a0d..b0e5f46e42e8 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -11,6 +11,7 @@ use Swift_SmtpTransport as SmtpTransport; use Illuminate\Mail\Transport\LogTransport; use Illuminate\Mail\Transport\SesTransport; +use Postmark\Transport as PostmarkTransport; use Illuminate\Mail\Transport\ArrayTransport; use Illuminate\Mail\Transport\MailgunTransport; use Illuminate\Mail\Transport\MandrillTransport; @@ -153,6 +154,18 @@ protected function createSparkPostDriver() ); } + /** + * Create an instance of the Postmark Swift Transport driver. + * + * @return \Swift_Transport + */ + protected function createPostmarkDriver() + { + return new PostmarkTransport( + $this->app['config']->get('services.postmark.token') + ); + } + /** * Create an instance of the Log Swift Transport driver. * From a5637515ceea23c429e46b7617e1a6a079c231d8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Feb 2019 20:22:11 -0600 Subject: [PATCH 42/78] add suggestion --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index db9d987d1014..645ac7b28001 100644 --- a/composer.json +++ b/composer.json @@ -133,7 +133,8 @@ "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0).", "symfony/css-selector": "Required to use some of the crawler integration testing tools (^4.2).", "symfony/dom-crawler": "Required to use most of the crawler integration testing tools (^4.2).", - "symfony/psr-http-message-bridge": "Required to psr7 bridging features (^1.1)." + "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^1.1).", + "wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)." }, "config": { "sort-packages": true From d88dfe1e5925fa61f62837359e1b26f799e4110b Mon Sep 17 00:00:00 2001 From: Sven Wittevrongel Date: Tue, 26 Feb 2019 03:41:38 +0100 Subject: [PATCH 43/78] Support multiple guesses for Policy resolution --- src/Illuminate/Auth/Access/Gate.php | 12 +++++---- .../Auth/GatePolicyResolutionTest.php | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 66dbc6107c57..55a764c4ae5a 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -538,8 +538,10 @@ public function getPolicyFor($class) return $this->resolvePolicy($this->policies[$class]); } - if (class_exists($guessedPolicy = $this->guessPolicyName($class))) { - return $this->resolvePolicy($guessedPolicy); + foreach ($this->guessPolicyName($class) as $guessedPolicy) { + if (class_exists($guessedPolicy)) { + return $this->resolvePolicy($guessedPolicy); + } } foreach ($this->policies as $expected => $policy) { @@ -553,17 +555,17 @@ public function getPolicyFor($class) * Guess the policy name for the given class. * * @param string $class - * @return string + * @return array */ protected function guessPolicyName($class) { if ($this->guessPolicyNamesUsingCallback) { - return call_user_func($this->guessPolicyNamesUsingCallback, $class); + return Arr::wrap(call_user_func($this->guessPolicyNamesUsingCallback, $class)); } $classDirname = str_replace('/', '\\', dirname(str_replace('\\', '/', $class))); - return $classDirname.'\\Policies\\'.class_basename($class).'Policy'; + return [$classDirname.'\\Policies\\'.class_basename($class).'Policy']; } /** diff --git a/tests/Integration/Auth/GatePolicyResolutionTest.php b/tests/Integration/Auth/GatePolicyResolutionTest.php index b950b2eb1e71..c43ed85c80e9 100644 --- a/tests/Integration/Auth/GatePolicyResolutionTest.php +++ b/tests/Integration/Auth/GatePolicyResolutionTest.php @@ -19,4 +19,31 @@ public function testPolicyCanBeGuessedUsingClassConventions() Gate::getPolicyFor(AuthenticationTestUser::class) ); } + + public function testPolicyCanBeGuessedUsingCallback() + { + Gate::guessPolicyNamesUsing(function () { + return AuthenticationTestUserPolicy::class; + }); + + $this->assertInstanceOf( + AuthenticationTestUserPolicy::class, + Gate::getPolicyFor(AuthenticationTestUser::class) + ); + } + + public function testPolicyCanBeGuessedMultipleTimes() + { + Gate::guessPolicyNamesUsing(function () { + return [ + 'App\\Policies\\TestUserPolicy', + AuthenticationTestUserPolicy::class + ]; + }); + + $this->assertInstanceOf( + AuthenticationTestUserPolicy::class, + Gate::getPolicyFor(AuthenticationTestUser::class) + ); + } } From ef95409b2bd9ce2c9a95d01c209b1f830dc3189b Mon Sep 17 00:00:00 2001 From: Sven Wittevrongel Date: Tue, 26 Feb 2019 03:51:48 +0100 Subject: [PATCH 44/78] StyleCI --- tests/Integration/Auth/GatePolicyResolutionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Auth/GatePolicyResolutionTest.php b/tests/Integration/Auth/GatePolicyResolutionTest.php index c43ed85c80e9..7c342f50cfa2 100644 --- a/tests/Integration/Auth/GatePolicyResolutionTest.php +++ b/tests/Integration/Auth/GatePolicyResolutionTest.php @@ -37,7 +37,7 @@ public function testPolicyCanBeGuessedMultipleTimes() Gate::guessPolicyNamesUsing(function () { return [ 'App\\Policies\\TestUserPolicy', - AuthenticationTestUserPolicy::class + AuthenticationTestUserPolicy::class, ]; }); From b1e2150508f5add600208ea9560af8cdeb6218e7 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Tue, 26 Feb 2019 11:53:02 +0100 Subject: [PATCH 45/78] Remove workaround for https://bugs.php.net/bug.php?id=75577 if PHP > 7.3 .v bug is fixed in PHP 7.3 and the work-around prevent using some custom formats so the workaround should only be called for PHP < 7.3 --- .../Database/Eloquent/Concerns/HasAttributes.php | 11 ++++++++--- tests/Database/DatabaseEloquentModelTest.php | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 0c1afc2e0db1..35d820d6aed0 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -792,12 +792,17 @@ protected function asDateTime($value) return Date::instance(Carbon::createFromFormat('Y-m-d', $value)->startOfDay()); } + $format = $this->getDateFormat(); + + // Work-around for https://bugs.php.net/bug.php?id=75577 + if (version_compare(PHP_VERSION, '7.3.0-dev', '<')) { + $format = str_replace('.v', '.u', $format); + } + // Finally, we will just assume this date is in the format used by default on // the database connection and use that format to create the Carbon object // that is returned back out to the developers after we convert it here. - return Date::createFromFormat( - str_replace('.v', '.u', $this->getDateFormat()), $value - ); + return Date::createFromFormat($format, $value); } /** diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index fc44e2450203..1fd6654aad2f 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -484,6 +484,22 @@ public function testFromDateTime() $this->assertNull($model->fromDateTime(null)); } + public function testFromDateTimeMilliseconds() + { + if (version_compare(PHP_VERSION, '7.3.0-dev', '<')) { + $this->markTestSkipped('Due to https://bugs.php.net/bug.php?id=75577, proper "v" format support can only works since PHP 7.3.'); + } + + $model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentDateModelStub')->setMethods(['getDateFormat'])->getMock(); + $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d H:s.vi')); + $model->setRawAttributes([ + 'created_at' => '2012-12-04 22:59.32130', + ]); + + $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertEquals('22:30:59.321000', $model->created_at->format('H:i:s.u')); + } + public function testInsertProcess() { $model = $this->getMockBuilder(EloquentModelStub::class)->setMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock(); From c7d5ad8ef51d6a793b78844c072438fb6db36078 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 07:55:36 -0600 Subject: [PATCH 46/78] formatting --- src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 35d820d6aed0..c67d522f99f1 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -794,7 +794,7 @@ protected function asDateTime($value) $format = $this->getDateFormat(); - // Work-around for https://bugs.php.net/bug.php?id=75577 + // https://bugs.php.net/bug.php?id=75577 if (version_compare(PHP_VERSION, '7.3.0-dev', '<')) { $format = str_replace('.v', '.u', $format); } From f3f03e49c60ac7abd6ee21075d1259bfee913f45 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 08:19:00 -0600 Subject: [PATCH 47/78] formatting --- .../Eloquent/Relations/Concerns/AsPivot.php | 18 ++-- .../Concerns/InteractsWithPivotTable.php | 86 ++++++++++++++----- .../Database/Eloquent/Relations/Pivot.php | 5 ++ 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index b77d7db80d82..a33f56bdc55b 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -42,8 +42,6 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist { $instance = new static; - // if this factory was presented valid timestamp columns, set the $timestamps - // property accordingly $instance->timestamps = $instance->hasTimestampAttributes($attributes); // The pivot model is a "dynamic" model since we will set the tables dynamically @@ -77,8 +75,6 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex { $instance = static::fromAttributes($parent, [], $table, $exists); - // if this factory was presented valid timestamp columns, set the $timestamps - // property accordingly $instance->timestamps = $instance->hasTimestampAttributes($attributes); $instance->setRawAttributes($attributes, true); @@ -114,7 +110,6 @@ protected function setKeysForSaveQuery(Builder $query) */ public function delete() { - // support for pivot classes that container a non-composite primary key if (isset($this->attributes[$this->getKeyName()])) { return (int) parent::delete(); } @@ -125,11 +120,9 @@ public function delete() $this->touchOwners(); - $affectedRows = $this->getDeleteQuery()->delete(); - - $this->fireModelEvent('deleted', false); - - return $affectedRows; + return tap($this->getDeleteQuery()->delete(), function () { + $this->fireModelEvent('deleted', false); + }); } /** @@ -208,10 +201,9 @@ public function setPivotKeys($foreignKey, $relatedKey) } /** - * Determine if the pivot model has timestamp attributes in either a provided - * array of attributes or the currently tracked attributes inside the model. + * Determine if the pivot model or given attributes has timestamp attributes. * - * @param $attributes array|null Options attributes to check instead of properties + * @param $attributes array|null * @return bool */ public function hasTimestampAttributes($attributes = null) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 2cd6abc9f9e0..695d0bc77656 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -185,16 +185,7 @@ protected function attachNew(array $records, array $current, $touch = true) public function updateExistingPivot($id, array $attributes, $touch = true) { if ($this->using) { - $updated = $this->newPivot([ - $this->foreignPivotKey => $this->parent->getKey(), - $this->relatedPivotKey => $this->parseId($id), - ], true)->fill($attributes)->save(); - - if ($touch) { - $this->touchIfTouching(); - } - - return (int) $updated; + return $this->updateExistingPivotUsingCustomClass($id, $attributes, $touch); } if (in_array($this->updatedAt(), $this->pivotColumns)) { @@ -212,6 +203,28 @@ public function updateExistingPivot($id, array $attributes, $touch = true) return $updated; } + /** + * Update an existing pivot record on the table via a custom class. + * + * @param mixed $id + * @param array $attributes + * @param bool $touch + * @return int + */ + protected function updateExistingPivotUsingCustomClass($id, array $attributes, $touch) + { + $updated = $this->newPivot([ + $this->foreignPivotKey => $this->parent->getKey(), + $this->relatedPivotKey => $this->parseId($id), + ], true)->fill($attributes)->save(); + + if ($touch) { + $this->touchIfTouching(); + } + + return (int) $updated; + } + /** * Attach a model to the parent. * @@ -223,12 +236,7 @@ public function updateExistingPivot($id, array $attributes, $touch = true) public function attach($id, array $attributes = [], $touch = true) { if ($this->using) { - $records = $this->formatAttachRecords( - $this->parseIds($id), $attributes - ); - foreach ($records as $record) { - $this->newPivot($record, false)->save(); - } + $this->attachUsingCustomClass($id, $attributes); } else { // Here we will insert the attachment records into the pivot table. Once we have // inserted the records, we will touch the relationships if necessary and the @@ -243,6 +251,24 @@ public function attach($id, array $attributes = [], $touch = true) } } + /** + * Attach a model to the parent using a custom class. + * + * @param mixed $id + * @param array $attributes + * @return void + */ + protected function attachUsingCustomClass($id, array $attributes) + { + $records = $this->formatAttachRecords( + $this->parseIds($id), $attributes + ); + + foreach ($records as $record) { + $this->newPivot($record, false)->save(); + } + } + /** * Create an array of records to insert into the pivot table. * @@ -378,13 +404,7 @@ protected function hasPivotColumn($column) public function detach($ids = null, $touch = true) { if ($this->using) { - $results = 0; - foreach ($this->parseIds($ids) as $id) { - $results += $this->newPivot([ - $this->foreignPivotKey => $this->parent->getKey(), - $this->relatedPivotKey => $id, - ], true)->delete(); - } + $results = $this->detachUsingCustomClass($ids); } else { $query = $this->newPivotQuery(); @@ -414,6 +434,26 @@ public function detach($ids = null, $touch = true) return $results; } + /** + * Detach models from the relationship using a custom class. + * + * @param mixed $ids + * @return int + */ + protected function detachUsingCustomClass($ids) + { + $results = 0; + + foreach ($this->parseIds($ids) as $id) { + $results += $this->newPivot([ + $this->foreignPivotKey => $this->parent->getKey(), + $this->relatedPivotKey => $id, + ], true)->delete(); + } + + return $results; + } + /** * Create a new pivot model instance. * diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 95799b8505af..a65ecdea6633 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -9,6 +9,11 @@ class Pivot extends Model { use AsPivot; + /** + * Indicates if the IDs are auto-incrementing. + * + * @var bool + */ public $incrementing = false; /** From 970c9ed70b053aec7d69487a825577ed6f0329d1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 08:49:42 -0600 Subject: [PATCH 48/78] remove broken code --- src/Illuminate/Auth/RequestGuard.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Illuminate/Auth/RequestGuard.php b/src/Illuminate/Auth/RequestGuard.php index e5e8da3ec819..2adc2cc35302 100644 --- a/src/Illuminate/Auth/RequestGuard.php +++ b/src/Illuminate/Auth/RequestGuard.php @@ -80,10 +80,6 @@ public function validate(array $credentials = []) */ public function setRequest(Request $request) { - if ($this->request !== $request) { - $this->user = null; - } - $this->request = $request; return $this; From cadea88cc2007cedb825b5d86a0fb184dcd76ab4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 09:24:16 -0600 Subject: [PATCH 49/78] tweak how detach and updateExistingPivot work with custom models --- .../Eloquent/Relations/Concerns/InteractsWithPivotTable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 695d0bc77656..eec606ec2706 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -184,7 +184,7 @@ protected function attachNew(array $records, array $current, $touch = true) */ public function updateExistingPivot($id, array $attributes, $touch = true) { - if ($this->using) { + if ($this->using && empty($this->pivotWheres) && empty($this->pivotWhereIns)) { return $this->updateExistingPivotUsingCustomClass($id, $attributes, $touch); } @@ -403,7 +403,7 @@ protected function hasPivotColumn($column) */ public function detach($ids = null, $touch = true) { - if ($this->using) { + if ($this->using && ! empty($ids)) { $results = $this->detachUsingCustomClass($ids); } else { $query = $this->newPivotQuery(); From 6733099346e523077c525f09ce6a9277e9de4ebc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 09:41:00 -0600 Subject: [PATCH 50/78] version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index ebeea45f3b84..7f58d94c0918 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '5.8-dev'; + const VERSION = '5.8.0'; /** * The base path for the Laravel installation. From 8e69728f1c80a024588adbd24c65c4fcf9aa9192 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Feb 2019 09:41:34 -0600 Subject: [PATCH 51/78] version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 051675ff2981..c225dac78e36 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '5.7.27'; + const VERSION = '5.7.28'; /** * The base path for the Laravel installation. From 9ff53132df6c6ffb5d791187f59185beb50fb9c4 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 26 Feb 2019 12:23:36 -0500 Subject: [PATCH 52/78] Add setter --- src/Illuminate/View/FileViewFinder.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/View/FileViewFinder.php b/src/Illuminate/View/FileViewFinder.php index 4a380f9ce3f0..9b549d6f1aff 100755 --- a/src/Illuminate/View/FileViewFinder.php +++ b/src/Illuminate/View/FileViewFinder.php @@ -266,6 +266,19 @@ public function getFilesystem() return $this->files; } + /** + * Set the active view paths. + * + * @param array $paths + * @return $this + */ + public function setPaths($paths) + { + $this->paths = $paths; + + return $this; + } + /** * Get the active view paths. * From 81895941a5ee83e89c1e707cdd5d06515d276b4d Mon Sep 17 00:00:00 2001 From: Bert van Hoekelen Date: Tue, 26 Feb 2019 19:01:33 +0100 Subject: [PATCH 53/78] Return fake objects from facades --- src/Illuminate/Support/Facades/Bus.php | 6 ++++-- src/Illuminate/Support/Facades/Event.php | 4 +++- src/Illuminate/Support/Facades/Mail.php | 6 ++++-- src/Illuminate/Support/Facades/Queue.php | 6 ++++-- src/Illuminate/Support/Facades/Storage.php | 12 ++++++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php index 9bbd4901ee94..cc543fd9466d 100644 --- a/src/Illuminate/Support/Facades/Bus.php +++ b/src/Illuminate/Support/Facades/Bus.php @@ -20,11 +20,13 @@ class Bus extends Facade /** * Replace the bound instance with a fake. * - * @return void + * @return BusFake */ public static function fake() { - static::swap(new BusFake); + static::swap($fake = new BusFake); + + return $fake; } /** diff --git a/src/Illuminate/Support/Facades/Event.php b/src/Illuminate/Support/Facades/Event.php index aefc49bb797b..335e7474c781 100755 --- a/src/Illuminate/Support/Facades/Event.php +++ b/src/Illuminate/Support/Facades/Event.php @@ -24,13 +24,15 @@ class Event extends Facade * Replace the bound instance with a fake. * * @param array|string $eventsToFake - * @return void + * @return EventFake */ public static function fake($eventsToFake = []) { static::swap($fake = new EventFake(static::getFacadeRoot(), $eventsToFake)); Model::setEventDispatcher($fake); + + return $fake; } /** diff --git a/src/Illuminate/Support/Facades/Mail.php b/src/Illuminate/Support/Facades/Mail.php index bee470c7f8fb..830ad174711a 100755 --- a/src/Illuminate/Support/Facades/Mail.php +++ b/src/Illuminate/Support/Facades/Mail.php @@ -31,11 +31,13 @@ class Mail extends Facade /** * Replace the bound instance with a fake. * - * @return void + * @return MailFake */ public static function fake() { - static::swap(new MailFake); + static::swap($fake = new MailFake); + + return $fake; } /** diff --git a/src/Illuminate/Support/Facades/Queue.php b/src/Illuminate/Support/Facades/Queue.php index 1f57ba0fec63..06dfeaeaced9 100755 --- a/src/Illuminate/Support/Facades/Queue.php +++ b/src/Illuminate/Support/Facades/Queue.php @@ -24,11 +24,13 @@ class Queue extends Facade /** * Replace the bound instance with a fake. * - * @return void + * @return QueueFake */ public static function fake() { - static::swap(new QueueFake(static::getFacadeApplication())); + static::swap($fake = new QueueFake(static::getFacadeApplication())); + + return $fake; } /** diff --git a/src/Illuminate/Support/Facades/Storage.php b/src/Illuminate/Support/Facades/Storage.php index 5bcbfd654643..8f25cda98b57 100644 --- a/src/Illuminate/Support/Facades/Storage.php +++ b/src/Illuminate/Support/Facades/Storage.php @@ -16,7 +16,7 @@ class Storage extends Facade * * @param string|null $disk * - * @return void + * @return Filesystem */ public static function fake($disk = null) { @@ -26,22 +26,26 @@ public static function fake($disk = null) $root = storage_path('framework/testing/disks/'.$disk) ); - static::set($disk, self::createLocalDriver(['root' => $root])); + static::set($disk, $fake = self::createLocalDriver(['root' => $root])); + + return $fake; } /** * Replace the given disk with a persistent local testing disk. * * @param string|null $disk - * @return void + * @return Filesystem */ public static function persistentFake($disk = null) { $disk = $disk ?: self::$app['config']->get('filesystems.default'); - static::set($disk, self::createLocalDriver([ + static::set($disk, $fake = self::createLocalDriver([ 'root' => storage_path('framework/testing/disks/'.$disk), ])); + + return $fake; } /** From bfa6749a43ec672bb6cab388c3cbc6998d22aeb9 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Tue, 26 Feb 2019 22:16:41 +0200 Subject: [PATCH 54/78] [5.7] update changelog --- CHANGELOG-5.7.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG-5.7.md b/CHANGELOG-5.7.md index a0deb9f078d3..ba4f123e4651 100644 --- a/CHANGELOG-5.7.md +++ b/CHANGELOG-5.7.md @@ -1,16 +1,24 @@ # Release Notes for 5.7.x -## [Unreleased](https://github.com/laravel/framework/compare/v5.7.27...5.7) +## [Unreleased](https://github.com/laravel/framework/compare/v5.7.28...5.7) + + +## [v5.7.28 (2019-02-28)](https://github.com/laravel/framework/compare/v5.7.27...v5.7.28) ### Added - Add support for `Pheanstalk 4.x` ([#27622](https://github.com/laravel/framework/pull/27622)) +- Allow configuration of token guard keys ([#27585](https://github.com/laravel/framework/pull/27585)) + +### Changed +- Update vue preset to exclude `@babel/preset-react` ([#27645](https://github.com/laravel/framework/pull/27645)) +- Reflash the session for the broadcasting auth call ([#27647](https://github.com/laravel/framework/pull/27647)) +- Improving readability in `AuthenticateWithBasicAuth` Middleware ([#27661](https://github.com/laravel/framework/pull/27661)) +- Use safe container getter on `Pipeline` ([#27648](https://github.com/laravel/framework/pull/27648)) ### Fixed - Fixed Postgres grammar when using union queries ([#27589](https://github.com/laravel/framework/pull/27589)) - -### TODO: -- https://github.com/laravel/framework/pull/27585 -- https://github.com/laravel/framework/pull/27618 +- Fixed an issue when using Mail::queue to queue Mailables ([#27618](https://github.com/laravel/framework/pull/27618)) +- Fixed error in `Foundation\Exceptions\Handler` ([#27632](https://github.com/laravel/framework/pull/27632)) ## [v5.7.26 (2019-02-12)](https://github.com/laravel/framework/compare/v5.7.25...v5.7.26) From 8ab09fb6377eb5b6dab45ab38b0a62446b08e8ae Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Tue, 26 Feb 2019 22:30:06 +0200 Subject: [PATCH 55/78] Update changelog 1 (#27682) [5.7] update changelog --- CHANGELOG-5.7.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG-5.7.md b/CHANGELOG-5.7.md index ba4f123e4651..c340d9ebfdd5 100644 --- a/CHANGELOG-5.7.md +++ b/CHANGELOG-5.7.md @@ -3,7 +3,7 @@ ## [Unreleased](https://github.com/laravel/framework/compare/v5.7.28...5.7) -## [v5.7.28 (2019-02-28)](https://github.com/laravel/framework/compare/v5.7.27...v5.7.28) +## [v5.7.28 (2019-02-26)](https://github.com/laravel/framework/compare/v5.7.27...v5.7.28) ### Added - Add support for `Pheanstalk 4.x` ([#27622](https://github.com/laravel/framework/pull/27622)) From 107ee4a8321b0e7a58d256143a513aa7afd3bd73 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Tue, 26 Feb 2019 22:32:50 +0200 Subject: [PATCH 56/78] [5.8] update changelog --- CHANGELOG-5.8.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-5.8.md b/CHANGELOG-5.8.md index 8d486d67e7c2..d327b1dd492d 100644 --- a/CHANGELOG-5.8.md +++ b/CHANGELOG-5.8.md @@ -2,6 +2,7 @@ ## [Unreleased](https://github.com/laravel/framework/compare/v5.8.0...5.8) -## [v5.8.0 (TODO)](https://github.com/laravel/framework/compare/5.7...v5.8.0) + +## [v5.8.0 (2019-02-26)](https://github.com/laravel/framework/compare/5.7...v5.8.0) Check the upgrade guide in the [Official Laravel Documentation](https://laravel.com/docs/5.8/upgrade). From e77e1f1d7e4be936fe8a082e97b9765f59bd50cc Mon Sep 17 00:00:00 2001 From: Bert van Hoekelen Date: Tue, 26 Feb 2019 23:48:20 +0100 Subject: [PATCH 57/78] Set FQCN as docblock return type --- src/Illuminate/Support/Facades/Bus.php | 2 +- src/Illuminate/Support/Facades/Event.php | 2 +- src/Illuminate/Support/Facades/Mail.php | 2 +- src/Illuminate/Support/Facades/Queue.php | 2 +- src/Illuminate/Support/Facades/Storage.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php index cc543fd9466d..611358afffca 100644 --- a/src/Illuminate/Support/Facades/Bus.php +++ b/src/Illuminate/Support/Facades/Bus.php @@ -20,7 +20,7 @@ class Bus extends Facade /** * Replace the bound instance with a fake. * - * @return BusFake + * @return \Illuminate\Support\Testing\Fakes\BusFake */ public static function fake() { diff --git a/src/Illuminate/Support/Facades/Event.php b/src/Illuminate/Support/Facades/Event.php index 335e7474c781..73b65981cf3a 100755 --- a/src/Illuminate/Support/Facades/Event.php +++ b/src/Illuminate/Support/Facades/Event.php @@ -24,7 +24,7 @@ class Event extends Facade * Replace the bound instance with a fake. * * @param array|string $eventsToFake - * @return EventFake + * @return \Illuminate\Support\Testing\Fakes\EventFake */ public static function fake($eventsToFake = []) { diff --git a/src/Illuminate/Support/Facades/Mail.php b/src/Illuminate/Support/Facades/Mail.php index 830ad174711a..00fc76f7304d 100755 --- a/src/Illuminate/Support/Facades/Mail.php +++ b/src/Illuminate/Support/Facades/Mail.php @@ -31,7 +31,7 @@ class Mail extends Facade /** * Replace the bound instance with a fake. * - * @return MailFake + * @return \Illuminate\Support\Testing\Fakes\MailFake */ public static function fake() { diff --git a/src/Illuminate/Support/Facades/Queue.php b/src/Illuminate/Support/Facades/Queue.php index 06dfeaeaced9..521d2eb21441 100755 --- a/src/Illuminate/Support/Facades/Queue.php +++ b/src/Illuminate/Support/Facades/Queue.php @@ -24,7 +24,7 @@ class Queue extends Facade /** * Replace the bound instance with a fake. * - * @return QueueFake + * @return \Illuminate\Support\Testing\Fakes\QueueFake */ public static function fake() { diff --git a/src/Illuminate/Support/Facades/Storage.php b/src/Illuminate/Support/Facades/Storage.php index 8f25cda98b57..97426a1004bc 100644 --- a/src/Illuminate/Support/Facades/Storage.php +++ b/src/Illuminate/Support/Facades/Storage.php @@ -16,7 +16,7 @@ class Storage extends Facade * * @param string|null $disk * - * @return Filesystem + * @return \Illuminate\Filesystem\Filesystem */ public static function fake($disk = null) { @@ -35,7 +35,7 @@ public static function fake($disk = null) * Replace the given disk with a persistent local testing disk. * * @param string|null $disk - * @return Filesystem + * @return \Illuminate\Filesystem\Filesystem */ public static function persistentFake($disk = null) { From 394cf1ad9f55e165ce3c5aceec3f4e1f9fa453f1 Mon Sep 17 00:00:00 2001 From: mpyw Date: Wed, 27 Feb 2019 14:34:13 +0900 Subject: [PATCH 58/78] [5.8] Fix quoted environment variable parsing --- src/Illuminate/Support/helpers.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 0741c4d2029c..956051cf7620 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -662,6 +662,10 @@ function env($key, $default = null) return; } + if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') { + return substr($value, 1, -1); + } + return $value; }) ->getOrCall(function () use ($default) { From b0d163f078145c6f1ae943bd487bb512b4e493b5 Mon Sep 17 00:00:00 2001 From: mpyw Date: Wed, 27 Feb 2019 16:53:44 +0900 Subject: [PATCH 59/78] Add test for escaped environment variable string --- tests/Support/SupportHelpersTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 694e6405c164..282513dc0d91 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -572,6 +572,12 @@ public function testEnvNull() $this->assertNull(env('foo')); } + public function testEnvEscapedString() + { + $_SERVER['foo'] = '"null"'; + $this->assertSame('null', env('foo')); + } + public function testGetFromENVFirst() { $_ENV['foo'] = 'From $_ENV'; From 887916ba7815e6bf7e2feec44e0d49d85e9ab671 Mon Sep 17 00:00:00 2001 From: mpyw Date: Wed, 27 Feb 2019 16:58:11 +0900 Subject: [PATCH 60/78] Add support for single-quoted string --- src/Illuminate/Support/helpers.php | 2 +- tests/Support/SupportHelpersTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 956051cf7620..5c6c45b45652 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -662,7 +662,7 @@ function env($key, $default = null) return; } - if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') { + if (($valueLength = strlen($value)) > 1 && ($value[0] === '"' && $value[$valueLength - 1] === '"' || $value[0] === "'" && $value[$valueLength - 1] === "'")) { return substr($value, 1, -1); } diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 282513dc0d91..8ca6b399b209 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -576,6 +576,9 @@ public function testEnvEscapedString() { $_SERVER['foo'] = '"null"'; $this->assertSame('null', env('foo')); + + $_SERVER['foo'] = "'null'"; + $this->assertSame('null', env('foo')); } public function testGetFromENVFirst() From 6427cdd8aebb49fa1136273e7a9fe10ee7ef6be1 Mon Sep 17 00:00:00 2001 From: mpyw Date: Wed, 27 Feb 2019 22:46:08 +0900 Subject: [PATCH 61/78] Refactor unquoting logic --- src/Illuminate/Support/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 5c6c45b45652..41eb7c486b5a 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -662,8 +662,8 @@ function env($key, $default = null) return; } - if (($valueLength = strlen($value)) > 1 && ($value[0] === '"' && $value[$valueLength - 1] === '"' || $value[0] === "'" && $value[$valueLength - 1] === "'")) { - return substr($value, 1, -1); + if (preg_match('/([\'"])(.*)\1/', $value, $matches)) { + return $matches[2]; } return $value; From 63d87d78e08cc502947f07ebbfa4993955339c5a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Feb 2019 07:46:50 -0600 Subject: [PATCH 62/78] revert facade change --- src/Illuminate/Database/DatabaseServiceProvider.php | 4 ---- src/Illuminate/Support/Facades/Facade.php | 6 +++++- src/Illuminate/Support/Facades/Schema.php | 6 +++--- tests/Database/DatabaseMigratorIntegrationTest.php | 4 ---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Database/DatabaseServiceProvider.php b/src/Illuminate/Database/DatabaseServiceProvider.php index 66dd4b9a3957..a8ee7b030b78 100755 --- a/src/Illuminate/Database/DatabaseServiceProvider.php +++ b/src/Illuminate/Database/DatabaseServiceProvider.php @@ -65,10 +65,6 @@ protected function registerConnectionServices() $this->app->bind('db.connection', function ($app) { return $app['db']->connection(); }); - - $this->app->bind('db.schema', function ($app) { - return $app['db']->connection()->getSchemaBuilder(); - }); } /** diff --git a/src/Illuminate/Support/Facades/Facade.php b/src/Illuminate/Support/Facades/Facade.php index 2a335fd4b7c5..97286b9b0fc1 100755 --- a/src/Illuminate/Support/Facades/Facade.php +++ b/src/Illuminate/Support/Facades/Facade.php @@ -159,11 +159,15 @@ protected static function getFacadeAccessor() /** * Resolve the facade root instance from the container. * - * @param string $name + * @param object|string $name * @return mixed */ protected static function resolveFacadeInstance($name) { + if (is_object($name)) { + return $name; + } + if (isset(static::$resolvedInstance[$name])) { return static::$resolvedInstance[$name]; } diff --git a/src/Illuminate/Support/Facades/Schema.php b/src/Illuminate/Support/Facades/Schema.php index d3a924811b01..31748e15029b 100755 --- a/src/Illuminate/Support/Facades/Schema.php +++ b/src/Illuminate/Support/Facades/Schema.php @@ -25,12 +25,12 @@ public static function connection($name) } /** - * Get the registered name of the component. + * Get a schema builder instance for the default connection. * - * @return string + * @return \Illuminate\Database\Schema\Builder */ protected static function getFacadeAccessor() { - return 'db.schema'; + return static::$app['db']->connection()->getSchemaBuilder(); } } diff --git a/tests/Database/DatabaseMigratorIntegrationTest.php b/tests/Database/DatabaseMigratorIntegrationTest.php index 56763c31fc18..1a421732620e 100644 --- a/tests/Database/DatabaseMigratorIntegrationTest.php +++ b/tests/Database/DatabaseMigratorIntegrationTest.php @@ -37,10 +37,6 @@ protected function setUp(): void $container = new Container; $container->instance('db', $db->getDatabaseManager()); - $container->bind('db.schema', function ($c) { - return $c['db']->connection()->getSchemaBuilder(); - }); - Facade::setFacadeApplication($container); $this->migrator = new Migrator( From 9be2899caaefd749cdcf6819f2d6f763cfa9c433 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Feb 2019 07:47:36 -0600 Subject: [PATCH 63/78] version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 7f58d94c0918..0e632d562789 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '5.8.0'; + const VERSION = '5.8.1'; /** * The base path for the Laravel installation. From c3b7cbe700efb0f4c9a5359feaedb0a1f0a741ca Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Feb 2019 08:02:36 -0600 Subject: [PATCH 64/78] increment version --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 0e632d562789..786d5e212b56 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '5.8.1'; + const VERSION = '5.8.2'; /** * The base path for the Laravel installation. From 66b56bd0b73a76f8f8c76238ca6b78d11f6938df Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Wed, 27 Feb 2019 22:03:55 +0200 Subject: [PATCH 65/78] [5.8] update changelog --- CHANGELOG-5.8.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-5.8.md b/CHANGELOG-5.8.md index d327b1dd492d..1edf7c3f132c 100644 --- a/CHANGELOG-5.8.md +++ b/CHANGELOG-5.8.md @@ -1,6 +1,24 @@ # Release Notes for 5.8.x -## [Unreleased](https://github.com/laravel/framework/compare/v5.8.0...5.8) +## [Unreleased](https://github.com/laravel/framework/compare/v5.8.2...5.8) + + +## [v5.8.2 (2019-02-27)](https://github.com/laravel/framework/compare/v5.8.1...v5.8.2) + +### Fixed +- Fixed quoted environment variable parsing ([#27691](https://github.com/laravel/framework/pull/27691)) + + +## [v5.8.1 (2019-02-27)](https://github.com/laravel/framework/compare/v5.8.0...v5.8.1) + +### Added +- Added `Illuminate\View\FileViewFinder::setPaths()` ([#27678](https://github.com/laravel/framework/pull/27678)) + +### Changed +- Return fake objects from facades ([#27680](https://github.com/laravel/framework/pull/27680)) + +### Reverted +- reverted changes related to the `Facade` ([63d87d7](https://github.com/laravel/framework/commit/63d87d78e08cc502947f07ebbfa4993955339c5a)) ## [v5.8.0 (2019-02-26)](https://github.com/laravel/framework/compare/5.7...v5.8.0) From 11fe65bbb16be873c11d421ef54653972e3636ad Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Thu, 28 Feb 2019 00:48:34 +0200 Subject: [PATCH 66/78] [5.8] add `Illuminate\Database\Schema\Blueprint` type hint to table creating --- .../2016_01_01_200000_create_flights_table.php | 3 ++- tests/Integration/Auth/AuthenticationTest.php | 3 ++- .../Database/EloquentBelongsToManyTest.php | 7 ++++--- .../Database/EloquentBelongsToTest.php | 3 ++- .../Database/EloquentCollectionFreshTest.php | 3 ++- .../Database/EloquentCustomPivotCastTest.php | 7 ++++--- tests/Integration/Database/EloquentDeleteTest.php | 7 ++++--- .../Database/EloquentFactoryBuilderTest.php | 13 +++++++------ .../Database/EloquentHasManyThroughTest.php | 9 +++++---- .../Database/EloquentLazyEagerLoadingTest.php | 7 ++++--- .../Database/EloquentModelConnectionsTest.php | 9 +++++---- .../Database/EloquentModelCustomEventsTest.php | 3 ++- .../Database/EloquentModelDateCastingTest.php | 3 ++- .../Database/EloquentModelDecimalCastingTest.php | 3 ++- tests/Integration/Database/EloquentModelTest.php | 5 +++-- .../Database/EloquentMorphManyTest.php | 5 +++-- .../Integration/Database/EloquentPaginateTest.php | 3 ++- .../Database/EloquentPivotEventsTest.php | 7 ++++--- .../Database/EloquentPivotSerializationTest.php | 11 ++++++----- .../EloquentTouchParentWithGlobalScopeTest.php | 5 +++-- tests/Integration/Database/EloquentUpdateTest.php | 7 ++++--- .../Database/EloquentWithCountTest.php | 9 +++++---- tests/Integration/Database/QueryBuilderTest.php | 3 ++- tests/Integration/Database/SchemaBuilderTest.php | 5 +++-- .../Concerns/InteractsWithAuthenticationTest.php | 3 ++- .../SendingMailNotificationsTest.php | 3 ++- .../SendingNotificationsWithLocaleTest.php | 3 ++- .../Integration/Queue/ModelSerializationTest.php | 15 ++++++++------- tests/Integration/Validation/ValidatorTest.php | 3 ++- 29 files changed, 98 insertions(+), 69 deletions(-) diff --git a/tests/Database/migrations/two/2016_01_01_200000_create_flights_table.php b/tests/Database/migrations/two/2016_01_01_200000_create_flights_table.php index ab45888712f3..8626f14eea76 100644 --- a/tests/Database/migrations/two/2016_01_01_200000_create_flights_table.php +++ b/tests/Database/migrations/two/2016_01_01_200000_create_flights_table.php @@ -1,6 +1,7 @@ increments('id'); $table->string('name'); }); diff --git a/tests/Integration/Auth/AuthenticationTest.php b/tests/Integration/Auth/AuthenticationTest.php index 8789149c3384..d4f178ff736e 100644 --- a/tests/Integration/Auth/AuthenticationTest.php +++ b/tests/Integration/Auth/AuthenticationTest.php @@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Auth\EloquentUserProvider; use Illuminate\Auth\Events\Authenticated; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; /** @@ -38,7 +39,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('username'); diff --git a/tests/Integration/Database/EloquentBelongsToManyTest.php b/tests/Integration/Database/EloquentBelongsToManyTest.php index 3a1359f8f6d3..ccd09fc9b7ed 100644 --- a/tests/Integration/Database/EloquentBelongsToManyTest.php +++ b/tests/Integration/Database/EloquentBelongsToManyTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -21,19 +22,19 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); - Schema::create('tags', function ($table) { + Schema::create('tags', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); - Schema::create('posts_tags', function ($table) { + Schema::create('posts_tags', function (Blueprint $table) { $table->integer('post_id'); $table->integer('tag_id'); $table->string('flag')->default(''); diff --git a/tests/Integration/Database/EloquentBelongsToTest.php b/tests/Integration/Database/EloquentBelongsToTest.php index 52bfc49b5b5e..30ea34be35c2 100644 --- a/tests/Integration/Database/EloquentBelongsToTest.php +++ b/tests/Integration/Database/EloquentBelongsToTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -16,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('slug')->nullable(); $table->unsignedInteger('parent_id')->nullable(); diff --git a/tests/Integration/Database/EloquentCollectionFreshTest.php b/tests/Integration/Database/EloquentCollectionFreshTest.php index a25e572899b6..719093c067cd 100644 --- a/tests/Integration/Database/EloquentCollectionFreshTest.php +++ b/tests/Integration/Database/EloquentCollectionFreshTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; /** * @group integration @@ -14,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); }); diff --git a/tests/Integration/Database/EloquentCustomPivotCastTest.php b/tests/Integration/Database/EloquentCustomPivotCastTest.php index 6924ccaedfbe..89cecab7b31d 100644 --- a/tests/Integration/Database/EloquentCustomPivotCastTest.php +++ b/tests/Integration/Database/EloquentCustomPivotCastTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Relations\Pivot; /** @@ -15,17 +16,17 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); }); - Schema::create('projects', function ($table) { + Schema::create('projects', function (Blueprint $table) { $table->increments('id'); $table->string('name'); }); - Schema::create('project_users', function ($table) { + Schema::create('project_users', function (Blueprint $table) { $table->integer('user_id'); $table->integer('project_id'); $table->text('permissions'); diff --git a/tests/Integration/Database/EloquentDeleteTest.php b/tests/Integration/Database/EloquentDeleteTest.php index b1cbfc5f3787..f32901445d4a 100644 --- a/tests/Integration/Database/EloquentDeleteTest.php +++ b/tests/Integration/Database/EloquentDeleteTest.php @@ -5,6 +5,7 @@ use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -29,20 +30,20 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title')->nullable(); $table->timestamps(); }); - Schema::create('comments', function ($table) { + Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->string('body')->nullable(); $table->integer('post_id'); $table->timestamps(); }); - Schema::create('roles', function ($table) { + Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); $table->softDeletes(); diff --git a/tests/Integration/Database/EloquentFactoryBuilderTest.php b/tests/Integration/Database/EloquentFactoryBuilderTest.php index aa542c0e6996..0c1c0389158b 100644 --- a/tests/Integration/Database/EloquentFactoryBuilderTest.php +++ b/tests/Integration/Database/EloquentFactoryBuilderTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factory; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Collection; /** @@ -107,36 +108,36 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email'); }); - Schema::create('profiles', function ($table) { + Schema::create('profiles', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id'); }); - Schema::create('teams', function ($table) { + Schema::create('teams', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('owner_id'); }); - Schema::create('team_users', function ($table) { + Schema::create('team_users', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('team_id'); $table->unsignedInteger('user_id'); }); - Schema::connection('alternative-connection')->create('users', function ($table) { + Schema::connection('alternative-connection')->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email'); }); - Schema::create('servers', function ($table) { + Schema::create('servers', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('tags'); diff --git a/tests/Integration/Database/EloquentHasManyThroughTest.php b/tests/Integration/Database/EloquentHasManyThroughTest.php index 33ad544ede41..f312ef41a970 100644 --- a/tests/Integration/Database/EloquentHasManyThroughTest.php +++ b/tests/Integration/Database/EloquentHasManyThroughTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Tests\Integration\Database\DatabaseTestCase; @@ -17,26 +18,26 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('slug')->nullable(); $table->integer('team_id')->nullable(); $table->string('name'); }); - Schema::create('teams', function ($table) { + Schema::create('teams', function (Blueprint $table) { $table->increments('id'); $table->integer('owner_id')->nullable(); $table->string('owner_slug')->nullable(); }); - Schema::create('categories', function ($table) { + Schema::create('categories', function (Blueprint $table) { $table->increments('id'); $table->integer('parent_id')->nullable(); $table->softDeletes(); }); - Schema::create('products', function ($table) { + Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->integer('category_id'); }); diff --git a/tests/Integration/Database/EloquentLazyEagerLoadingTest.php b/tests/Integration/Database/EloquentLazyEagerLoadingTest.php index 0d0eba3ee438..d70a1dcc21ae 100644 --- a/tests/Integration/Database/EloquentLazyEagerLoadingTest.php +++ b/tests/Integration/Database/EloquentLazyEagerLoadingTest.php @@ -5,6 +5,7 @@ use DB; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -16,16 +17,16 @@ protected function setUp(): void { parent::setUp(); - Schema::create('one', function ($table) { + Schema::create('one', function (Blueprint $table) { $table->increments('id'); }); - Schema::create('two', function ($table) { + Schema::create('two', function (Blueprint $table) { $table->increments('id'); $table->integer('one_id'); }); - Schema::create('three', function ($table) { + Schema::create('three', function (Blueprint $table) { $table->increments('id'); $table->integer('one_id'); }); diff --git a/tests/Integration/Database/EloquentModelConnectionsTest.php b/tests/Integration/Database/EloquentModelConnectionsTest.php index bba8071750a9..28260fd09323 100644 --- a/tests/Integration/Database/EloquentModelConnectionsTest.php +++ b/tests/Integration/Database/EloquentModelConnectionsTest.php @@ -6,6 +6,7 @@ use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; /** * @group integration @@ -35,23 +36,23 @@ protected function setUp(): void { parent::setUp(); - Schema::create('parent', function ($table) { + Schema::create('parent', function (Blueprint $table) { $table->increments('id'); $table->string('name'); }); - Schema::create('child', function ($table) { + Schema::create('child', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->integer('parent_id'); }); - Schema::connection('conn2')->create('parent', function ($table) { + Schema::connection('conn2')->create('parent', function (Blueprint $table) { $table->increments('id'); $table->string('name'); }); - Schema::connection('conn2')->create('child', function ($table) { + Schema::connection('conn2')->create('child', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->integer('parent_id'); diff --git a/tests/Integration/Database/EloquentModelCustomEventsTest.php b/tests/Integration/Database/EloquentModelCustomEventsTest.php index 672265730a53..a9b8b093cae8 100644 --- a/tests/Integration/Database/EloquentModelCustomEventsTest.php +++ b/tests/Integration/Database/EloquentModelCustomEventsTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -16,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('test_model1', function ($table) { + Schema::create('test_model1', function (Blueprint $table) { $table->increments('id'); }); diff --git a/tests/Integration/Database/EloquentModelDateCastingTest.php b/tests/Integration/Database/EloquentModelDateCastingTest.php index 51368c83db2b..15b3217fa51e 100644 --- a/tests/Integration/Database/EloquentModelDateCastingTest.php +++ b/tests/Integration/Database/EloquentModelDateCastingTest.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -16,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('test_model1', function ($table) { + Schema::create('test_model1', function (Blueprint $table) { $table->increments('id'); $table->date('date_field')->nullable(); $table->datetime('datetime_field')->nullable(); diff --git a/tests/Integration/Database/EloquentModelDecimalCastingTest.php b/tests/Integration/Database/EloquentModelDecimalCastingTest.php index a3eb2f71e640..2f13c5ee4d3d 100644 --- a/tests/Integration/Database/EloquentModelDecimalCastingTest.php +++ b/tests/Integration/Database/EloquentModelDecimalCastingTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -15,7 +16,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('test_model1', function ($table) { + Schema::create('test_model1', function (Blueprint $table) { $table->increments('id'); $table->decimal('decimal_field_2', 8, 2)->nullable(); $table->decimal('decimal_field_4', 8, 4)->nullable(); diff --git a/tests/Integration/Database/EloquentModelTest.php b/tests/Integration/Database/EloquentModelTest.php index 79ae116d5681..247d88113487 100644 --- a/tests/Integration/Database/EloquentModelTest.php +++ b/tests/Integration/Database/EloquentModelTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; /** * @group integration @@ -16,12 +17,12 @@ protected function setUp(): void { parent::setUp(); - Schema::create('test_model1', function ($table) { + Schema::create('test_model1', function (Blueprint $table) { $table->increments('id'); $table->timestamp('nullable_date')->nullable(); }); - Schema::create('test_model2', function ($table) { + Schema::create('test_model2', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('title'); diff --git a/tests/Integration/Database/EloquentMorphManyTest.php b/tests/Integration/Database/EloquentMorphManyTest.php index 394caa387eb3..959bee211fad 100644 --- a/tests/Integration/Database/EloquentMorphManyTest.php +++ b/tests/Integration/Database/EloquentMorphManyTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -17,13 +18,13 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); - Schema::create('comments', function ($table) { + Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->integer('commentable_id'); diff --git a/tests/Integration/Database/EloquentPaginateTest.php b/tests/Integration/Database/EloquentPaginateTest.php index 297608c30e38..25cd8e187b84 100644 --- a/tests/Integration/Database/EloquentPaginateTest.php +++ b/tests/Integration/Database/EloquentPaginateTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -15,7 +16,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title')->nullable(); $table->timestamps(); diff --git a/tests/Integration/Database/EloquentPivotEventsTest.php b/tests/Integration/Database/EloquentPivotEventsTest.php index a81ce022d683..05268ab53d27 100644 --- a/tests/Integration/Database/EloquentPivotEventsTest.php +++ b/tests/Integration/Database/EloquentPivotEventsTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Relations\Pivot; /** @@ -15,19 +16,19 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->timestamps(); }); - Schema::create('projects', function ($table) { + Schema::create('projects', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); - Schema::create('project_users', function ($table) { + Schema::create('project_users', function (Blueprint $table) { $table->integer('user_id'); $table->integer('project_id'); $table->string('role')->nullable(); diff --git a/tests/Integration/Database/EloquentPivotSerializationTest.php b/tests/Integration/Database/EloquentPivotSerializationTest.php index 190b2f39f73b..e7fd82515b38 100644 --- a/tests/Integration/Database/EloquentPivotSerializationTest.php +++ b/tests/Integration/Database/EloquentPivotSerializationTest.php @@ -5,6 +5,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Database\Eloquent\Collection as DatabaseCollection; @@ -18,30 +19,30 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->timestamps(); }); - Schema::create('projects', function ($table) { + Schema::create('projects', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); - Schema::create('project_users', function ($table) { + Schema::create('project_users', function (Blueprint $table) { $table->integer('user_id'); $table->integer('project_id'); }); - Schema::create('tags', function ($table) { + Schema::create('tags', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); - Schema::create('taggables', function ($table) { + Schema::create('taggables', function (Blueprint $table) { $table->integer('tag_id'); $table->integer('taggable_id'); $table->string('taggable_type'); diff --git a/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php b/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php index 796644d176d1..5cd239f7e820 100644 --- a/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php +++ b/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -17,13 +18,13 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); - Schema::create('comments', function ($table) { + Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->integer('post_id'); $table->string('title'); diff --git a/tests/Integration/Database/EloquentUpdateTest.php b/tests/Integration/Database/EloquentUpdateTest.php index e5e25434cd33..62ab3fcea4be 100644 --- a/tests/Integration/Database/EloquentUpdateTest.php +++ b/tests/Integration/Database/EloquentUpdateTest.php @@ -6,6 +6,7 @@ use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -30,13 +31,13 @@ protected function setUp(): void { parent::setUp(); - Schema::create('test_model1', function ($table) { + Schema::create('test_model1', function (Blueprint $table) { $table->increments('id'); $table->string('name')->nullable(); $table->string('title')->nullable(); }); - Schema::create('test_model2', function ($table) { + Schema::create('test_model2', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('job')->nullable(); @@ -44,7 +45,7 @@ protected function setUp(): void $table->timestamps(); }); - Schema::create('test_model3', function ($table) { + Schema::create('test_model3', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('counter'); $table->softDeletes(); diff --git a/tests/Integration/Database/EloquentWithCountTest.php b/tests/Integration/Database/EloquentWithCountTest.php index 52c1a515be5a..a8453bf0fd23 100644 --- a/tests/Integration/Database/EloquentWithCountTest.php +++ b/tests/Integration/Database/EloquentWithCountTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -15,21 +16,21 @@ protected function setUp(): void { parent::setUp(); - Schema::create('one', function ($table) { + Schema::create('one', function (Blueprint $table) { $table->increments('id'); }); - Schema::create('two', function ($table) { + Schema::create('two', function (Blueprint $table) { $table->increments('id'); $table->integer('one_id'); }); - Schema::create('three', function ($table) { + Schema::create('three', function (Blueprint $table) { $table->increments('id'); $table->integer('two_id'); }); - Schema::create('four', function ($table) { + Schema::create('four', function (Blueprint $table) { $table->increments('id'); $table->integer('one_id'); }); diff --git a/tests/Integration/Database/QueryBuilderTest.php b/tests/Integration/Database/QueryBuilderTest.php index 687575aefb81..abd27439fdb5 100644 --- a/tests/Integration/Database/QueryBuilderTest.php +++ b/tests/Integration/Database/QueryBuilderTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -16,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->timestamp('created_at'); }); diff --git a/tests/Integration/Database/SchemaBuilderTest.php b/tests/Integration/Database/SchemaBuilderTest.php index f63deade31cd..15325e377608 100644 --- a/tests/Integration/Database/SchemaBuilderTest.php +++ b/tests/Integration/Database/SchemaBuilderTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** @@ -13,13 +14,13 @@ class SchemaBuilderTest extends DatabaseTestCase { public function test_drop_all_tables() { - Schema::create('table', function ($table) { + Schema::create('table', function (Blueprint $table) { $table->increments('id'); }); Schema::dropAllTables(); - Schema::create('table', function ($table) { + Schema::create('table', function (Blueprint $table) { $table->increments('id'); }); diff --git a/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php index c5ecf4d8ef10..20a6a464d799 100644 --- a/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php +++ b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Foundation\Auth\User as Authenticatable; class InteractsWithAuthenticationTest extends TestCase @@ -27,7 +28,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('username'); diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index 04dabf8d9c6e..2141a09ff4ff 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -11,6 +11,7 @@ use Illuminate\Contracts\Mail\Mailable; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Notifications\Notification; use Illuminate\Notifications\Channels\MailChannel; use Illuminate\Notifications\Messages\MailMessage; @@ -58,7 +59,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('name')->nullable(); diff --git a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php index f3eb88f71a60..504057a194a1 100644 --- a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php +++ b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Notifications\Notification; use Illuminate\Foundation\Events\LocaleUpdated; use Illuminate\Notifications\Channels\MailChannel; @@ -57,7 +58,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('name')->nullable(); diff --git a/tests/Integration/Queue/ModelSerializationTest.php b/tests/Integration/Queue/ModelSerializationTest.php index ca87c9adcc24..8b7f16530743 100644 --- a/tests/Integration/Queue/ModelSerializationTest.php +++ b/tests/Integration/Queue/ModelSerializationTest.php @@ -7,6 +7,7 @@ use Orchestra\Testbench\TestCase; use Illuminate\Queue\SerializesModels; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\Pivot; @@ -38,35 +39,35 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); }); - Schema::connection('custom')->create('users', function ($table) { + Schema::connection('custom')->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); }); - Schema::create('orders', function ($table) { + Schema::create('orders', function (Blueprint $table) { $table->increments('id'); }); - Schema::create('lines', function ($table) { + Schema::create('lines', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('order_id'); $table->unsignedInteger('product_id'); }); - Schema::create('products', function ($table) { + Schema::create('products', function (Blueprint $table) { $table->increments('id'); }); - Schema::create('roles', function ($table) { + Schema::create('roles', function (Blueprint $table) { $table->increments('id'); }); - Schema::create('role_user', function ($table) { + Schema::create('role_user', function (Blueprint $table) { $table->unsignedInteger('user_id'); $table->unsignedInteger('role_id'); }); diff --git a/tests/Integration/Validation/ValidatorTest.php b/tests/Integration/Validation/ValidatorTest.php index 087220a315d7..122fd1e94f60 100644 --- a/tests/Integration/Validation/ValidatorTest.php +++ b/tests/Integration/Validation/ValidatorTest.php @@ -7,6 +7,7 @@ use Illuminate\Translation\Translator; use Illuminate\Database\Eloquent\Model; use Illuminate\Translation\ArrayLoader; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Validation\DatabasePresenceVerifier; use Illuminate\Tests\Integration\Database\DatabaseTestCase; @@ -16,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('first_name'); }); From 850ab8443ac3c2214a6371c21763823632adea49 Mon Sep 17 00:00:00 2001 From: mpyw Date: Thu, 28 Feb 2019 14:12:51 +0900 Subject: [PATCH 67/78] [5.8] Fix unquoting regular expression pattern --- src/Illuminate/Support/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 41eb7c486b5a..4cc472c991f5 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -662,7 +662,7 @@ function env($key, $default = null) return; } - if (preg_match('/([\'"])(.*)\1/', $value, $matches)) { + if (preg_match('/\A([\'"])(.*)\1\z/', $value, $matches)) { return $matches[2]; } From edd383b4897fce537729081749e6c7774069214c Mon Sep 17 00:00:00 2001 From: Erik Gaal Date: Thu, 28 Feb 2019 09:40:02 +0100 Subject: [PATCH 68/78] Make Gate::forUser pass the policy guesser to the constructor --- src/Illuminate/Auth/Access/Gate.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 55a764c4ae5a..cd3a6f974dd9 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -80,10 +80,12 @@ class Gate implements GateContract * @param array $policies * @param array $beforeCallbacks * @param array $afterCallbacks + * @param callable $guessPolicyNamesUsingCallback * @return void */ public function __construct(Container $container, callable $userResolver, array $abilities = [], - array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = []) + array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = [], + callable $guessPolicyNamesUsingCallback = null) { $this->policies = $policies; $this->container = $container; @@ -91,6 +93,7 @@ public function __construct(Container $container, callable $userResolver, array $this->userResolver = $userResolver; $this->afterCallbacks = $afterCallbacks; $this->beforeCallbacks = $beforeCallbacks; + $this->guessPolicyNamesUsingCallback = $guessPolicyNamesUsingCallback; } /** @@ -700,7 +703,7 @@ public function forUser($user) return new static( $this->container, $callback, $this->abilities, - $this->policies, $this->beforeCallbacks, $this->afterCallbacks + $this->policies, $this->beforeCallbacks, $this->afterCallbacks, $this->guessPolicyNamesUsingCallback ); } From ed91b7ddaedcde80dcfda261d8f125fd1ee19c4f Mon Sep 17 00:00:00 2001 From: Erik Gaal Date: Thu, 28 Feb 2019 09:51:19 +0100 Subject: [PATCH 69/78] Push 7th argument to new line --- src/Illuminate/Auth/Access/Gate.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index cd3a6f974dd9..3a80ca6b14b7 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -703,7 +703,8 @@ public function forUser($user) return new static( $this->container, $callback, $this->abilities, - $this->policies, $this->beforeCallbacks, $this->afterCallbacks, $this->guessPolicyNamesUsingCallback + $this->policies, $this->beforeCallbacks, $this->afterCallbacks, + $this->guessPolicyNamesUsingCallback ); } From e19bed7f3faccc039b3e5d1f688ce1aaa06721b1 Mon Sep 17 00:00:00 2001 From: mpyw Date: Thu, 28 Feb 2019 19:16:16 +0900 Subject: [PATCH 70/78] Add test verifying \A and \z --- tests/Support/SupportHelpersTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 8ca6b399b209..4c50240f8d8d 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -579,6 +579,9 @@ public function testEnvEscapedString() $_SERVER['foo'] = "'null'"; $this->assertSame('null', env('foo')); + + $_SERVER['foo'] = 'x"null"x'; // this should not be unquoted + $this->assertSame('x"null"x', env('foo')); } public function testGetFromENVFirst() From 84b438c432531dc41d4d71f18d396636addebedb Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 28 Feb 2019 12:09:14 +0100 Subject: [PATCH 71/78] Fix a bug with string via in queued notifications A queued notification with a string via currently fails because it's not converted to an array. I've added a test which proves the failure. Reported via https://github.com/laravel/docs/pull/5023 --- .../Notifications/NotificationSender.php | 2 +- .../Notifications/NotificationSenderTest.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/Notifications/NotificationSenderTest.php diff --git a/src/Illuminate/Notifications/NotificationSender.php b/src/Illuminate/Notifications/NotificationSender.php index f75c6a88a575..0e1e8de40576 100644 --- a/src/Illuminate/Notifications/NotificationSender.php +++ b/src/Illuminate/Notifications/NotificationSender.php @@ -179,7 +179,7 @@ protected function queueNotification($notifiables, $notification) foreach ($notifiables as $notifiable) { $notificationId = Str::uuid()->toString(); - foreach ($original->via($notifiable) as $channel) { + foreach ((array) $original->via($notifiable) as $channel) { $notification = clone $original; $notification->id = $notificationId; diff --git a/tests/Notifications/NotificationSenderTest.php b/tests/Notifications/NotificationSenderTest.php new file mode 100644 index 000000000000..4bf0903e1c35 --- /dev/null +++ b/tests/Notifications/NotificationSenderTest.php @@ -0,0 +1,54 @@ +shouldReceive('dispatch'); + $events = m::mock(EventDispatcher::class); + + $sender = new NotificationSender($manager, $bus, $events); + + $sender->send($notifiable, new DummyQueuedNotificationWithStringVia()); + } +} + +class DummyQueuedNotificationWithStringVia extends Notification implements ShouldQueue +{ + use Queueable; + + /** + * Get the notification channels. + * + * @param mixed $notifiable + * @return array|string + * @return array|string + */ + public function via($notifiable) + { + return 'mail'; + } +} From 586345a52f6639dfcf5cba6effa87889b8862b4f Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 28 Feb 2019 12:11:15 +0100 Subject: [PATCH 72/78] Fix StyleCI failure --- tests/Notifications/NotificationSenderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Notifications/NotificationSenderTest.php b/tests/Notifications/NotificationSenderTest.php index 4bf0903e1c35..16f235f62414 100644 --- a/tests/Notifications/NotificationSenderTest.php +++ b/tests/Notifications/NotificationSenderTest.php @@ -2,8 +2,8 @@ namespace Illuminate\Tests\Notifications; -use Illuminate\Bus\Queueable; use Mockery as m; +use Illuminate\Bus\Queueable; use PHPUnit\Framework\TestCase; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; From 8d3b543f83097593f6ccb285815810500d2f0af6 Mon Sep 17 00:00:00 2001 From: Robbie Thompson Date: Thu, 28 Feb 2019 16:37:25 +0000 Subject: [PATCH 73/78] Check if MessageBag is empty before checking keys exist --- src/Illuminate/Support/MessageBag.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Support/MessageBag.php b/src/Illuminate/Support/MessageBag.php index 72fe683edb0b..b20bd77a7b7a 100755 --- a/src/Illuminate/Support/MessageBag.php +++ b/src/Illuminate/Support/MessageBag.php @@ -105,6 +105,10 @@ public function merge($messages) */ public function has($key) { + if ($this->isEmpty()) { + return false; + } + if (is_null($key)) { return $this->any(); } @@ -128,6 +132,10 @@ public function has($key) */ public function hasAny($keys = []) { + if ($this->isEmpty()) { + return false; + } + $keys = is_array($keys) ? $keys : func_get_args(); foreach ($keys as $key) { From ef6ee6766a03bc45e4c76540f0593d2b11dd6d81 Mon Sep 17 00:00:00 2001 From: Abdel Elrafa Date: Thu, 28 Feb 2019 11:51:31 -0500 Subject: [PATCH 74/78] Fix dockblock. --- tests/Notifications/NotificationSenderTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Notifications/NotificationSenderTest.php b/tests/Notifications/NotificationSenderTest.php index 16f235f62414..a6fa249f3d80 100644 --- a/tests/Notifications/NotificationSenderTest.php +++ b/tests/Notifications/NotificationSenderTest.php @@ -45,7 +45,6 @@ class DummyQueuedNotificationWithStringVia extends Notification implements Shoul * * @param mixed $notifiable * @return array|string - * @return array|string */ public function via($notifiable) { From 796dd443c084f5d00e507b2893af036cbfc5e86a Mon Sep 17 00:00:00 2001 From: Nicolas Hedger <649677+nhedger@users.noreply.github.com> Date: Fri, 1 Mar 2019 03:16:20 +0100 Subject: [PATCH 75/78] Typo fix in a comment --- src/Illuminate/Routing/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteCollection.php b/src/Illuminate/Routing/RouteCollection.php index 1c7879d562f3..47520fe3d85c 100644 --- a/src/Illuminate/Routing/RouteCollection.php +++ b/src/Illuminate/Routing/RouteCollection.php @@ -21,7 +21,7 @@ class RouteCollection implements Countable, IteratorAggregate protected $routes = []; /** - * An flattened array of all of the routes. + * A flattened array of all of the routes. * * @var array */ From 1b6e13f584ef123522d41f1ddd6b55c7a4555e90 Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Fri, 1 Mar 2019 05:53:04 +0330 Subject: [PATCH 76/78] include $level --- src/Illuminate/Log/LogManager.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 9418380991bf..29f7643daaf1 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -335,6 +335,8 @@ protected function createMonologDriver(array $config) $config['handler_with'] ?? [] ); + $with['level'] = $this->level($config); + return new Monolog($this->parseChannel($config), [$this->prepareHandler( $this->app->make($config['handler'], $with), $config )]); From 7d7bdf60f318996a4ffab7cbd33d58bbc18ce43e Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Fri, 1 Mar 2019 05:53:31 +0330 Subject: [PATCH 77/78] Added tests --- tests/Log/LogManagerTest.php | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/Log/LogManagerTest.php b/tests/Log/LogManagerTest.php index 667294e6c9dc..b786b6102091 100755 --- a/tests/Log/LogManagerTest.php +++ b/tests/Log/LogManagerTest.php @@ -27,6 +27,51 @@ public function testLogManagerCachesLoggerInstances() $this->assertSame($logger1, $logger2); } + public function testStackChannel() + { + $config = $this->app['config']; + + $config->set('logging.channels.stack', [ + 'driver' => 'stack', + 'channels' => ['stderr', 'stdout'], + ]); + + $config->set('logging.channels.stderr', [ + 'driver' => 'monolog', + 'handler' => StreamHandler::class, + 'level' => 'notice', + 'with' => [ + 'stream' => 'php://stderr', + 'bubble' => false, + ], + ]); + + $config->set('logging.channels.stdout', [ + 'driver' => 'monolog', + 'handler' => StreamHandler::class, + 'level' => 'info', + 'with' => [ + 'stream' => 'php://stdout', + 'bubble' => true, + ], + ]); + + $manager = new LogManager($this->app); + + // create logger with handler specified from configuration + $logger = $manager->channel('stack'); + $handlers = $logger->getLogger()->getHandlers(); + + $this->assertInstanceOf(Logger::class, $logger); + $this->assertCount(2, $handlers); + $this->assertInstanceOf(StreamHandler::class, $handlers[0]); + $this->assertInstanceOf(StreamHandler::class, $handlers[1]); + $this->assertEquals(Monolog::NOTICE, $handlers[0]->getLevel()); + $this->assertEquals(Monolog::INFO, $handlers[1]->getLevel()); + $this->assertFalse($handlers[0]->getBubble()); + $this->assertTrue($handlers[1]->getBubble()); + } + public function testLogManagerCreatesConfiguredMonologHandler() { $config = $this->app['config']; @@ -34,9 +79,9 @@ public function testLogManagerCreatesConfiguredMonologHandler() 'driver' => 'monolog', 'name' => 'foobar', 'handler' => StreamHandler::class, + 'level' => 'notice', 'with' => [ 'stream' => 'php://stderr', - 'level' => Monolog::NOTICE, 'bubble' => false, ], ]); From bc884bb30e3dc12545ab63cea1f5a74b33dab59c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 1 Mar 2019 08:17:35 -0600 Subject: [PATCH 78/78] formatting --- src/Illuminate/Log/LogManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 29f7643daaf1..d636f869f000 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -331,12 +331,11 @@ protected function createMonologDriver(array $config) } $with = array_merge( + ['level' => $this->level($config)], $config['with'] ?? [], $config['handler_with'] ?? [] ); - $with['level'] = $this->level($config); - return new Monolog($this->parseChannel($config), [$this->prepareHandler( $this->app->make($config['handler'], $with), $config )]);