diff --git a/CHANGELOG-5.7.md b/CHANGELOG-5.7.md index c413d5095355..c340d9ebfdd5 100644 --- a/CHANGELOG-5.7.md +++ b/CHANGELOG-5.7.md @@ -1,6 +1,24 @@ # 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.28...5.7) + + +## [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)) +- 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)) +- 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) diff --git a/CHANGELOG-5.8.md b/CHANGELOG-5.8.md index 8d486d67e7c2..1edf7c3f132c 100644 --- a/CHANGELOG-5.8.md +++ b/CHANGELOG-5.8.md @@ -1,7 +1,26 @@ # 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.0 (TODO)](https://github.com/laravel/framework/compare/5.7...v5.8.0) + +## [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) Check the upgrade guide in the [Official Laravel Documentation](https://laravel.com/docs/5.8/upgrade). 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 diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 66dbc6107c57..3a80ca6b14b7 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; } /** @@ -538,8 +541,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 +558,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']; } /** @@ -698,7 +703,8 @@ 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 ); } 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); } } 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; 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); } } 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 = []) { 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/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 0c1afc2e0db1..c67d522f99f1 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(); + + // 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/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php index 7f1ffd7a0636..a8d65f734443 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php @@ -3,6 +3,7 @@ namespace Illuminate\Database\Eloquent\Concerns; use Illuminate\Support\Arr; +use InvalidArgumentException; use Illuminate\Contracts\Events\Dispatcher; trait HasEvents @@ -30,6 +31,8 @@ trait HasEvents * * @param object|array|string $classes * @return void + * + * @throws \RuntimeException */ public static function observe($classes) { @@ -45,10 +48,12 @@ 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); + $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 @@ -60,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. * diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php index 7fe75e6d4be5..a33f56bdc55b 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php @@ -42,6 +42,8 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist { $instance = new static; + $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. @@ -57,8 +59,6 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist $instance->exists = $exists; - $instance->timestamps = $instance->hasTimestampAttributes(); - return $instance; } @@ -75,9 +75,9 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex { $instance = static::fromAttributes($parent, [], $table, $exists); - $instance->setRawAttributes($attributes, true); + $instance->timestamps = $instance->hasTimestampAttributes($attributes); - $instance->timestamps = $instance->hasTimestampAttributes(); + $instance->setRawAttributes($attributes, true); return $instance; } @@ -111,10 +111,18 @@ protected function setKeysForSaveQuery(Builder $query) public function delete() { if (isset($this->attributes[$this->getKeyName()])) { - return parent::delete(); + return (int) parent::delete(); } - return $this->getDeleteQuery()->delete(); + if ($this->fireModelEvent('deleting') === false) { + return 0; + } + + $this->touchOwners(); + + return tap($this->getDeleteQuery()->delete(), function () { + $this->fireModelEvent('deleted', false); + }); } /** @@ -193,13 +201,14 @@ public function setPivotKeys($foreignKey, $relatedKey) } /** - * Determine if the pivot model has timestamp attributes. + * Determine if the pivot model or given attributes has timestamp attributes. * + * @param $attributes array|null * @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/Concerns/InteractsWithPivotTable.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 1984ec690611..eec606ec2706 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -184,6 +184,10 @@ protected function attachNew(array $records, array $current, $touch = true) */ public function updateExistingPivot($id, array $attributes, $touch = true) { + if ($this->using && empty($this->pivotWheres) && empty($this->pivotWhereIns)) { + return $this->updateExistingPivotUsingCustomClass($id, $attributes, $touch); + } + if (in_array($this->updatedAt(), $this->pivotColumns)) { $attributes = $this->addTimestampsToAttachment($attributes, true); } @@ -199,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. * @@ -209,18 +235,40 @@ 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) { + $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 + // 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(); } } + /** + * 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. * @@ -355,26 +403,30 @@ protected function hasPivotColumn($column) */ public function detach($ids = null, $touch = true) { - $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 (empty($ids)) { - return 0; + if ($this->using && ! empty($ids)) { + $results = $this->detachUsingCustomClass($ids); + } 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 (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(); } @@ -382,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 2ec8235156bb..a65ecdea6633 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -9,6 +9,13 @@ class Pivot extends Model { use AsPivot; + /** + * Indicates if the IDs are auto-incrementing. + * + * @var bool + */ + public $incrementing = false; + /** * The attributes that aren't mass assignable. * diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 27500fad1bbe..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-dev'; + const VERSION = '5.8.2'; /** * The base path for the Laravel installation. @@ -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/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', ]); diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 9fb99a59bde7..02a416c205c7 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->error("Your application doesn't have any routes matching the given criteria."); + } + + $this->displayRoutes($routes); } /** diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index c2516bb2f37e..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($request->except($this->dontFlash)) + ->withInput(Arr::except($request->input(), $this->dontFlash)) ->withErrors($exception->errors(), $exception->errorBag); } 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/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 9418380991bf..d636f869f000 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -331,6 +331,7 @@ protected function createMonologDriver(array $config) } $with = array_merge( + ['level' => $this->level($config)], $config['with'] ?? [], $config['handler_with'] ?? [] ); diff --git a/src/Illuminate/Mail/Mailer.php b/src/Illuminate/Mail/Mailer.php index 6880be86898e..9869b171c33b 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; @@ -381,7 +381,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); } /** 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. * 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/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; }; }; 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 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 */ diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php index 9bbd4901ee94..611358afffca 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 \Illuminate\Support\Testing\Fakes\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..73b65981cf3a 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 \Illuminate\Support\Testing\Fakes\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/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/Mail.php b/src/Illuminate/Support/Facades/Mail.php index bee470c7f8fb..00fc76f7304d 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 \Illuminate\Support\Testing\Fakes\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..521d2eb21441 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 \Illuminate\Support\Testing\Fakes\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/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/src/Illuminate/Support/Facades/Storage.php b/src/Illuminate/Support/Facades/Storage.php index 5bcbfd654643..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 void + * @return \Illuminate\Filesystem\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 \Illuminate\Filesystem\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; } /** 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) { diff --git a/src/Illuminate/Support/ServiceProvider.php b/src/Illuminate/Support/ServiceProvider.php index 30de0f4fc3f9..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. * diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 0741c4d2029c..4cc472c991f5 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -662,6 +662,10 @@ function env($key, $default = null) return; } + if (preg_match('/\A([\'"])(.*)\1\z/', $value, $matches)) { + return $matches[2]; + } + return $value; }) ->getOrCall(function () use ($default) { diff --git a/src/Illuminate/View/FileViewFinder.php b/src/Illuminate/View/FileViewFinder.php index bfd3b9e62cb8..9a80a586f75c 100755 --- a/src/Illuminate/View/FileViewFinder.php +++ b/src/Illuminate/View/FileViewFinder.php @@ -277,6 +277,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. * diff --git a/tests/Cache/CacheRepositoryTest.php b/tests/Cache/CacheRepositoryTest.php index c221115311de..5ead0cb50c8d 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() diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 2624f3e458e2..1fd6654aad2f 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -10,6 +10,7 @@ use ReflectionClass; use DateTimeImmutable; use DateTimeInterface; +use InvalidArgumentException; use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Connection; @@ -483,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(); @@ -1310,6 +1327,18 @@ public function testModelObserversCanBeAttachedToModelsThroughAnArray() EloquentModelStub::flushEventListeners(); } + public function testThrowExceptionOnAttachingNotExistsModelObserverWithString() + { + $this->expectException(InvalidArgumentException::class); + EloquentModelStub::observe(NotExistClass::class); + } + + public function testThrowExceptionOnAttachingNotExistsModelObserversThroughAnArray() + { + $this->expectException(InvalidArgumentException::class); + EloquentModelStub::observe([NotExistClass::class]); + } + public function testModelObserversCanBeAttachedToModelsThroughCallingObserveMethodOnlyOnce() { EloquentModelStub::setEventDispatcher($events = m::mock(Dispatcher::class)); diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index 5f461ea5111e..4f09aba25ee7 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -119,7 +119,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() 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( 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/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); diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index 79607b66586d..65d2fea69493 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -6,15 +6,21 @@ use Exception; use Mockery as m; use RuntimeException; +use Illuminate\Http\Request; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; use Illuminate\Routing\Redirector; +use Illuminate\Support\MessageBag; 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; @@ -141,6 +147,49 @@ public function testReturnsJsonWithoutStackTraceWhenAjaxRequestAndDebugFalseAndA $this->assertStringNotContainsString('"line":', $response); $this->assertStringNotContainsString('"trace":', $response); } + + public function testValidateFileMethod() + { + $argumentExpected = ['input' => 'My input value']; + $argumentActual = null; + + $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 (&$argumentActual) { + $argumentActual = $argument; + + return true; + }))->andReturn($responser); + + $responser->shouldReceive('withErrors')->once() + ->andReturn($responser); + + return $redirector; + }); + + $file = m::mock(UploadedFile::class); + $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'])); + + $validationException = new ValidationException($validator); + $validationException->redirectTo = '/'; + + $this->handler->render($request, $validationException); + + $this->assertEquals($argumentExpected, $argumentActual); + } } class CustomException extends Exception implements Responsable 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/Auth/GatePolicyResolutionTest.php b/tests/Integration/Auth/GatePolicyResolutionTest.php index b950b2eb1e71..7c342f50cfa2 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) + ); + } } 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 new file mode 100644 index 000000000000..05268ab53d27 --- /dev/null +++ b/tests/Integration/Database/EloquentPivotEventsTest.php @@ -0,0 +1,116 @@ +increments('id'); + $table->string('email'); + $table->timestamps(); + }); + + Schema::create('projects', function (Blueprint $table) { + $table->increments('id'); + $table->string('name'); + $table->timestamps(); + }); + + Schema::create('project_users', function (Blueprint $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'; + }); + + static::created(function ($model) { + static::$eventsCalled[] = 'created'; + }); + + static::updating(function ($model) { + static::$eventsCalled[] = 'updating'; + }); + + static::updated(function ($model) { + static::$eventsCalled[] = 'updated'; + }); + + static::saving(function ($model) { + static::$eventsCalled[] = 'saving'; + }); + + static::saved(function ($model) { + static::$eventsCalled[] = 'saved'; + }); + + static::deleting(function ($model) { + static::$eventsCalled[] = 'deleting'; + }); + + static::deleted(function ($model) { + static::$eventsCalled[] = 'deleted'; + }); + } +} 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/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()); } } 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'); }); 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, ], ]); diff --git a/tests/Notifications/NotificationSenderTest.php b/tests/Notifications/NotificationSenderTest.php new file mode 100644 index 000000000000..a6fa249f3d80 --- /dev/null +++ b/tests/Notifications/NotificationSenderTest.php @@ -0,0 +1,53 @@ +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 + */ + public function via($notifiable) + { + return 'mail'; + } +} 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 1716c7bf9483..4c50240f8d8d 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -6,8 +6,6 @@ use ArrayAccess; 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; @@ -19,238 +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 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 +26,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')); @@ -616,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']; @@ -726,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]; @@ -963,6 +572,18 @@ public function testEnvNull() $this->assertNull(env('foo')); } + public function testEnvEscapedString() + { + $_SERVER['foo'] = '"null"'; + $this->assertSame('null', env('foo')); + + $_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() { $_ENV['foo'] = 'From $_ENV'; 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()