From e365c0833ac7854c14af3020c9695dee3afeacc9 Mon Sep 17 00:00:00 2001 From: Vincent Neubauer Date: Thu, 23 Jan 2025 15:00:23 +0100 Subject: [PATCH 01/14] fix: `schedule:test` on commands using runInBackground (#54321) Force to run the selected command in the foreground. The `artisan schedule:test` command exited immediately after invocation and the selected command did not start if it uses `->runInBackground()`. If `->withoutOverlapping()` is used too, the mutex would not be removed and blocks any further execution without any user facing notice. --- src/Illuminate/Console/Scheduling/ScheduleTestCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php index 5e902a05b13e..0da0f7d04aa0 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php @@ -76,9 +76,11 @@ public function handle(Schedule $schedule) $description = sprintf( 'Running [%s]%s', $command, - $event->runInBackground ? ' in background' : '', + $event->runInBackground ? ' normally in background' : '', ); + $event->runInBackground = false; + $this->components->task($description, fn () => $event->run($this->laravel)); if (! $event instanceof CallbackEvent) { From 5253cc2caa30416cca52eb188b1edda6266208d5 Mon Sep 17 00:00:00 2001 From: Craig Morris Date: Fri, 24 Jan 2025 01:04:49 +1100 Subject: [PATCH 02/14] [11.x] Helper methods to dump responses of the Laravel HTTP client (#54317) * Add dump and dd methods to Response class for debugging * Remove unused VarDumper import from Response class * Update Response.php --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Http/Client/Response.php | 62 +++++++++++++++++++++++++ tests/Http/HttpClientTest.php | 57 +++++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index 491eecf081fd..ac51d9c7ade8 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -396,6 +396,68 @@ public function throwIfServerError() return $this->serverError() ? $this->throw() : $this; } + /** + * Dump the content from the response. + * + * @param string|null $key + * @return $this + */ + public function dump($key = null) + { + $content = $this->body(); + + $json = json_decode($content); + + if (json_last_error() === JSON_ERROR_NONE) { + $content = $json; + } + + if (! is_null($key)) { + dump(data_get($content, $key)); + } else { + dump($content); + } + + return $this; + } + + /** + * Dump the content from the response and end the script. + * + * @param string|null $key + * @return never + */ + public function dd($key = null) + { + $this->dump($key); + + exit(1); + } + + /** + * Dump the headers from the response. + * + * @return $this + */ + public function dumpHeaders() + { + dump($this->headers()); + + return $this; + } + + /** + * Dump the headers from the response and end the script. + * + * @return never + */ + public function ddHeaders() + { + $this->dumpHeaders(); + + exit(1); + } + /** * Determine if the given offset exists. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 64745bf49987..21c9718c2da6 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -1606,6 +1606,63 @@ public function testCanDump() VarDumper::setHandler(null); } + public function testResponseCanDump() + { + $dumped = []; + + VarDumper::setHandler(function ($value) use (&$dumped) { + $dumped[] = $value; + }); + + $this->factory->fake([ + '200.com' => $this->factory::response('hello', 200), + ]); + + $this->factory->get('http://200.com')->dump(); + + $this->assertSame('hello', $dumped[0]); + + VarDumper::setHandler(null); + } + + public function testResponseCanDumpWithKey() + { + $dumped = []; + + VarDumper::setHandler(function ($value) use (&$dumped) { + $dumped[] = $value; + }); + + $this->factory->fake([ + '200.com' => $this->factory::response(['hello' => 'world'], 200), + ]); + + $this->factory->get('http://200.com')->dump('hello'); + + $this->assertSame('world', $dumped[0]); + + VarDumper::setHandler(null); + } + + public function testResponseCanDumpHeaders() + { + $dumped = []; + + VarDumper::setHandler(function ($value) use (&$dumped) { + $dumped[] = $value; + }); + + $this->factory->fake([ + '200.com' => $this->factory::response('hello', 200, ['hello' => 'world']), + ]); + + $this->factory->get('http://200.com')->dumpHeaders(); + + $this->assertSame(['hello' => ['world']], $dumped[0]); + + VarDumper::setHandler(null); + } + public function testResponseSequenceIsMacroable() { ResponseSequence::macro('customMethod', function () { From 94e62583ebec7700466dd1194a79d35ecb07ba02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20M=2E?= Date: Thu, 23 Jan 2025 15:05:38 +0100 Subject: [PATCH 03/14] Add support for cursor editor in ResolvesDumpSource (#54318) Add support for cursor editor --- src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index 382d651b6056..318ec6c57f3b 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -13,6 +13,7 @@ trait ResolvesDumpSource */ protected $editorHrefs = [ 'atom' => 'atom://core/open/file?filename={file}&line={line}', + 'cursor' => 'cursor://file/{file}:{line}', 'emacs' => 'emacs://open?url=file://{file}&line={line}', 'idea' => 'idea://open?file={file}&line={line}', 'macvim' => 'mvim://open/?url=file://{file}&line={line}', From 1049c0370b24a0d08ba5f3f2c8019b3249a31851 Mon Sep 17 00:00:00 2001 From: Michael Nabil <46572405+michaelnabil230@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:14:15 +0200 Subject: [PATCH 04/14] [11.x] Add Customizable Date Validation Rule with Flexible Date Constraints (#53465) * Add Flexible Date Validation Options: After, Before, and Custom Formats * Add tests * Formatting * Renaming * Fix separator * Added between date * Formatting * Enabled seamless handling of `Carbon` and `DateTime` instances. * Add tests * Add `afterOrEqualToday` and `beforeOrEqualToday` and `betweenOrEqual` * Added tests * Formatting * Fix typo * formatting --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Validation/Rule.php | 11 ++ src/Illuminate/Validation/Rules/Date.php | 135 +++++++++++++++++++ tests/Validation/ValidationDateRuleTest.php | 138 ++++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 src/Illuminate/Validation/Rules/Date.php create mode 100644 tests/Validation/ValidationDateRuleTest.php diff --git a/src/Illuminate/Validation/Rule.php b/src/Illuminate/Validation/Rule.php index b94f40ca3372..5e367f64cb6c 100644 --- a/src/Illuminate/Validation/Rule.php +++ b/src/Illuminate/Validation/Rule.php @@ -6,6 +6,7 @@ use Illuminate\Support\Traits\Macroable; use Illuminate\Validation\Rules\ArrayRule; use Illuminate\Validation\Rules\Can; +use Illuminate\Validation\Rules\Date; use Illuminate\Validation\Rules\Dimensions; use Illuminate\Validation\Rules\Email; use Illuminate\Validation\Rules\Enum; @@ -170,6 +171,16 @@ public static function prohibitedIf($callback) return new ProhibitedIf($callback); } + /** + * Get a date rule builder instance. + * + * @return \Illuminate\Validation\Rules\Date + */ + public static function date() + { + return new Date; + } + /** * Get an email rule builder instance. * diff --git a/src/Illuminate/Validation/Rules/Date.php b/src/Illuminate/Validation/Rules/Date.php new file mode 100644 index 000000000000..6b6140fbd8f8 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Date.php @@ -0,0 +1,135 @@ +addRule('date_format:'.$format); + } + + /** + * Ensure the date is before today. + */ + public function beforeToday(): static + { + return $this->before('today'); + } + + /** + * Ensure the date is after today. + */ + public function afterToday(): static + { + return $this->after('today'); + } + + /** + * Ensure the date is before or equal to today. + */ + public function todayOrBefore(): static + { + return $this->beforeOrEqual('today'); + } + + /** + * Ensure the date is after or equal to today. + */ + public function todayOrAfter(): static + { + return $this->afterOrEqual('today'); + } + + /** + * Ensure the date is before the given date or date field. + */ + public function before(DateTimeInterface|string $date): static + { + return $this->addRule('before:'.$this->formatDate($date)); + } + + /** + * Ensure the date is after the given date or date field. + */ + public function after(DateTimeInterface|string $date): static + { + return $this->addRule('after:'.$this->formatDate($date)); + } + + /** + * Ensure the date is on or before the specified date or date field. + */ + public function beforeOrEqual(DateTimeInterface|string $date): static + { + return $this->addRule('before_or_equal:'.$this->formatDate($date)); + } + + /** + * Ensure the date is on or after the given date or date field. + */ + public function afterOrEqual(DateTimeInterface|string $date): static + { + return $this->addRule('after_or_equal:'.$this->formatDate($date)); + } + + /** + * Ensure the date is between two dates or date fields. + */ + public function between(DateTimeInterface|string $from, DateTimeInterface|string $to): static + { + return $this->after($from)->before($to); + } + + /** + * Ensure the date is between or equal to two dates or date fields. + */ + public function betweenOrEqual(DateTimeInterface|string $from, DateTimeInterface|string $to): static + { + return $this->afterOrEqual($from)->beforeOrEqual($to); + } + + /** + * Add custom rules to the validation rules array. + */ + protected function addRule(array|string $rules): static + { + $this->constraints = array_merge($this->constraints, Arr::wrap($rules)); + + return $this; + } + + /** + * Format the date for the validation rule. + */ + protected function formatDate(DateTimeInterface|string $date): string + { + return $date instanceof DateTimeInterface + ? $date->format('Y-m-d') + : $date; + } + + /** + * Convert the rule to a validation string. + */ + public function __toString(): string + { + return implode('|', $this->constraints); + } +} diff --git a/tests/Validation/ValidationDateRuleTest.php b/tests/Validation/ValidationDateRuleTest.php new file mode 100644 index 000000000000..6c903a6f956a --- /dev/null +++ b/tests/Validation/ValidationDateRuleTest.php @@ -0,0 +1,138 @@ +assertEquals('date', (string) $rule); + + $rule = new Date; + $this->assertSame('date', (string) $rule); + } + + public function testDateFormatRule() + { + $rule = Rule::date()->format('d/m/Y'); + $this->assertEquals('date|date_format:d/m/Y', (string) $rule); + } + + public function testAfterTodayRule() + { + $rule = Rule::date()->afterToday(); + $this->assertEquals('date|after:today', (string) $rule); + + $rule = Rule::date()->todayOrAfter(); + $this->assertEquals('date|after_or_equal:today', (string) $rule); + } + + public function testBeforeTodayRule() + { + $rule = Rule::date()->beforeToday(); + $this->assertEquals('date|before:today', (string) $rule); + + $rule = Rule::date()->todayOrBefore(); + $this->assertEquals('date|before_or_equal:today', (string) $rule); + } + + public function testAfterSpecificDateRule() + { + $rule = Rule::date()->after(Carbon::parse('2024-01-01')); + $this->assertEquals('date|after:2024-01-01', (string) $rule); + } + + public function testBeforeSpecificDateRule() + { + $rule = Rule::date()->before(Carbon::parse('2024-01-01')); + $this->assertEquals('date|before:2024-01-01', (string) $rule); + } + + public function testAfterOrEqualSpecificDateRule() + { + $rule = Rule::date()->afterOrEqual(Carbon::parse('2024-01-01')); + $this->assertEquals('date|after_or_equal:2024-01-01', (string) $rule); + } + + public function testBeforeOrEqualSpecificDateRule() + { + $rule = Rule::date()->beforeOrEqual(Carbon::parse('2024-01-01')); + $this->assertEquals('date|before_or_equal:2024-01-01', (string) $rule); + } + + public function testBetweenDatesRule() + { + $rule = Rule::date()->between(Carbon::parse('2024-01-01'), Carbon::parse('2024-02-01')); + $this->assertEquals('date|after:2024-01-01|before:2024-02-01', (string) $rule); + } + + public function testBetweenOrEqualDatesRule() + { + $rule = Rule::date()->betweenOrEqual('2024-01-01', '2024-02-01'); + $this->assertEquals('date|after_or_equal:2024-01-01|before_or_equal:2024-02-01', (string) $rule); + } + + public function testChainedRules() + { + $rule = Rule::date('Y-m-d H:i:s') + ->format('Y-m-d') + ->after('2024-01-01 00:00:00') + ->before('2025-01-01 00:00:00'); + $this->assertEquals('date|date_format:Y-m-d|after:2024-01-01 00:00:00|before:2025-01-01 00:00:00', (string) $rule); + + $rule = Rule::date() + ->format('Y-m-d') + ->when(true, function ($rule) { + $rule->after('2024-01-01'); + }) + ->unless(true, function ($rule) { + $rule->before('2025-01-01'); + }); + $this->assertSame('date|date_format:Y-m-d|after:2024-01-01', (string) $rule); + } + + public function testDateValidation() + { + $trans = new Translator(new ArrayLoader, 'en'); + + $rule = Rule::date(); + + $validator = new Validator( + $trans, + ['date' => 'not a date'], + ['date' => $rule] + ); + + $this->assertSame( + $trans->get('validation.date'), + $validator->errors()->first('date') + ); + + $validator = new Validator( + $trans, + ['date' => '2024-01-01'], + ['date' => $rule] + ); + + $this->assertEmpty($validator->errors()->first('date')); + + $rule = Rule::date()->between('2024-01-01', '2025-01-01'); + + $validator = new Validator( + $trans, + ['date' => '2024-02-01'], + ['date' => (string) $rule] + ); + + $this->assertEmpty($validator->errors()->first('date')); + } +} From f958f330417a46c72f35df9b49a629219d541749 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 23 Jan 2025 15:14:43 +0000 Subject: [PATCH 05/14] Apply fixes from StyleCI --- src/Illuminate/Validation/Rule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Rule.php b/src/Illuminate/Validation/Rule.php index 5e367f64cb6c..c9d9a2bad92e 100644 --- a/src/Illuminate/Validation/Rule.php +++ b/src/Illuminate/Validation/Rule.php @@ -180,7 +180,7 @@ public static function date() { return new Date; } - + /** * Get an email rule builder instance. * From d7c6b8d615b8deefe5f1f390c579bcc6313f8050 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 23 Jan 2025 16:36:14 -0600 Subject: [PATCH 06/14] [11.x] start syncing StyleCI rules to Pint (#54326) * start syncing StyleCI rules to Pint starting with the simple ones * wip * wip * wip * wip * wip * wip --- pint.json | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/pint.json b/pint.json index 304eebba7ebd..e3c66eb705f4 100644 --- a/pint.json +++ b/pint.json @@ -1,7 +1,128 @@ { "preset": "empty", "rules": { - "method_chaining_indentation": true + "array_indentation": true, + "binary_operator_spaces": { + "default": "single_space" + }, + "blank_line_after_namespace": true, + "blank_line_after_opening_tag": true, + "blank_line_before_statement": { + "statements": [ + "return" + ] + }, + "blank_line_between_import_groups": true, + "cast_spaces": true, + "class_reference_name_casing": true, + "clean_namespace": true, + "compact_nullable_type_declaration": true, + "concat_space": true, + "constant_case": { + "case": "lower" + }, + "declare_equal_normalize": true, + "elseif": true, + "encoding": true, + "full_opening_tag": true, + "function_declaration": true, + "heredoc_to_nowdoc": true, + "include": true, + "indentation_type": true, + "integer_literal_case": true, + "line_ending": true, + "lowercase_cast": true, + "lowercase_keywords": true, + "lowercase_static_reference": true, + "magic_constant_casing": true, + "magic_method_casing": true, + "method_argument_space": { + "on_multiline": "ignore" + }, + "method_chaining_indentation": true, + "native_function_casing": true, + "native_type_declaration_casing": true, + "no_alternative_syntax": true, + "no_binary_string": true, + "no_blank_lines_after_class_opening": true, + "no_blank_lines_after_phpdoc": true, + "no_closing_tag": true, + "no_empty_phpdoc": true, + "no_empty_statement": true, + "no_extra_blank_lines": { + "tokens": [ + "extra", + "throw", + "use" + ] + }, + "no_leading_import_slash": true, + "no_leading_namespace_whitespace": true, + "no_multiline_whitespace_around_double_arrow": true, + "no_short_bool_cast": true, + "no_singleline_whitespace_before_semicolons": true, + "no_space_around_double_colon": true, + "no_spaces_after_function_name": true, + "no_trailing_whitespace": true, + "no_trailing_whitespace_in_comment": true, + "no_unneeded_braces": true, + "no_unneeded_control_parentheses": true, + "no_unneeded_import_alias": true, + "no_unset_cast": true, + "no_unused_imports": true, + "no_useless_return": true, + "no_whitespace_before_comma_in_array": true, + "no_whitespace_in_blank_line": true, + "normalize_index_brace": true, + "not_operator_with_successor_space": true, + "nullable_type_declaration_for_default_null_value": true, + "object_operator_without_whitespace": true, + "ordered_imports": { + "sort_algorithm": "alpha", + "imports_order": [ + "const", + "class", + "function" + ] + }, + "phpdoc_indent": true, + "phpdoc_inline_tag_normalizer": true, + "phpdoc_no_access": true, + "phpdoc_no_package": true, + "phpdoc_no_useless_inheritdoc": true, + "phpdoc_return_self_reference": true, + "phpdoc_scalar": true, + "phpdoc_single_line_var_spacing": true, + "phpdoc_summary": true, + "phpdoc_trim": true, + "phpdoc_types": true, + "phpdoc_var_without_name": true, + "return_type_declaration": { + "space_before": "none" + }, + "short_scalar_cast": true, + "single_blank_line_at_eof": true, + "single_class_element_per_statement": true, + "single_line_after_imports": true, + "single_line_comment_style": true, + "single_quote": true, + "space_after_semicolon": true, + "standardize_not_equals": true, + "switch_case_semicolon_to_colon": true, + "switch_case_space": true, + "switch_continue_to_break": true, + "ternary_operator_spaces": true, + "trim_array_spaces": true, + "type_declaration_spaces": true, + "types_spaces": true, + "unary_operator_spaces": true, + "visibility_required": { + "elements": [ + "method", + "property" + ] + }, + "whitespace_after_comma_in_array": true }, "exclude": [ "tests" From 79b44b168da164191950aab79ba1689f0087ccda Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 23 Jan 2025 16:39:11 -0600 Subject: [PATCH 07/14] [11.x] apply our new Pint rule to the `/tests` directory (#54325) * apply our new pint rule to the `/tests` directory I originally omitted these files to keep the PR smaller, but adding back now for consistent styling throughout repo. these are purely indentation whitespace changes. the `bad-syntax-strategy.php` file is not valid PHP so we need to omit it, or it throws a Pint error. * indentation fixes --- pint.json | 4 +- tests/Broadcasting/AblyBroadcasterTest.php | 16 +-- tests/Broadcasting/BroadcasterTest.php | 48 ++++---- tests/Broadcasting/PusherBroadcasterTest.php | 24 ++-- tests/Broadcasting/RedisBroadcasterTest.php | 12 +- tests/Bus/BusBatchTest.php | 56 ++++----- tests/Console/View/ComponentsTest.php | 18 +-- tests/Container/ContainerTest.php | 14 +-- ...eEloquentHasManyThroughIntegrationTest.php | 74 +++++------ .../DatabaseEloquentIntegrationTest.php | 4 +- .../DatabaseMigrationMakeCommandTest.php | 24 ++-- .../Database/DatabaseMySqlSchemaStateTest.php | 6 +- tests/Database/DatabaseQueryBuilderTest.php | 76 ++++++------ .../Console/RouteListCommandTest.php | 2 +- .../Foundation/FoundationFormRequestTest.php | 10 +- tests/Http/HttpClientTest.php | 2 +- .../Database/EloquentCursorPaginateTest.php | 4 +- .../EloquentPivotSerializationTest.php | 4 +- .../Database/EloquentPivotTest.php | 14 +-- .../Testing/ArtisanCommandTest.php | 74 +++++------ tests/Mail/MailMailableDataTest.php | 2 +- tests/Mail/MailMailableTest.php | 2 +- .../NotificationMailMessageTest.php | 6 +- tests/Pipeline/PipelineTest.php | 16 +-- tests/Process/ProcessTest.php | 22 ++-- tests/Routing/RouteRegistrarTest.php | 116 +++++++++--------- tests/Support/SleepTest.php | 2 +- .../SupportLazyCollectionIsLazyTest.php | 2 +- tests/Support/SupportTestingMailFakeTest.php | 4 +- tests/Validation/ValidationFactoryTest.php | 4 +- 30 files changed, 331 insertions(+), 331 deletions(-) diff --git a/pint.json b/pint.json index e3c66eb705f4..453fd4b31462 100644 --- a/pint.json +++ b/pint.json @@ -124,7 +124,7 @@ }, "whitespace_after_comma_in_array": true }, - "exclude": [ - "tests" + "notPath": [ + "tests/Foundation/fixtures/bad-syntax-strategy.php" ] } diff --git a/tests/Broadcasting/AblyBroadcasterTest.php b/tests/Broadcasting/AblyBroadcasterTest.php index 4cf4458ae824..ea30f005069d 100644 --- a/tests/Broadcasting/AblyBroadcasterTest.php +++ b/tests/Broadcasting/AblyBroadcasterTest.php @@ -41,7 +41,7 @@ public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCal }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('private-test') @@ -82,7 +82,7 @@ public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCa }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('presence-test') @@ -125,17 +125,17 @@ protected function getMockRequestWithUserForChannel($channel) $request->shouldReceive('all')->andReturn(['channel_name' => $channel, 'socket_id' => 'abcd.1234']); $request->shouldReceive('input') - ->with('callback', false) - ->andReturn(false); + ->with('callback', false) + ->andReturn(false); $user = m::mock('User'); $user->shouldReceive('getAuthIdentifierForBroadcasting') - ->andReturn(42); + ->andReturn(42); $user->shouldReceive('getAuthIdentifier') - ->andReturn(42); + ->andReturn(42); $request->shouldReceive('user') - ->andReturn($user); + ->andReturn($user); return $request; } @@ -150,7 +150,7 @@ protected function getMockRequestWithoutUserForChannel($channel) $request->shouldReceive('all')->andReturn(['channel_name' => $channel]); $request->shouldReceive('user') - ->andReturn(null); + ->andReturn(null); return $request; } diff --git a/tests/Broadcasting/BroadcasterTest.php b/tests/Broadcasting/BroadcasterTest.php index 91e64d4d4323..57312935ccdb 100644 --- a/tests/Broadcasting/BroadcasterTest.php +++ b/tests/Broadcasting/BroadcasterTest.php @@ -206,9 +206,9 @@ public function testRetrieveUserWithoutGuard() $request = m::mock(Request::class); $request->shouldReceive('user') - ->once() - ->withNoArgs() - ->andReturn(new DummyUser); + ->once() + ->withNoArgs() + ->andReturn(new DummyUser); $this->assertInstanceOf( DummyUser::class, @@ -224,9 +224,9 @@ public function testRetrieveUserWithOneGuardUsingAStringForSpecifyingGuard() $request = m::mock(Request::class); $request->shouldReceive('user') - ->once() - ->with('myguard') - ->andReturn(new DummyUser); + ->once() + ->with('myguard') + ->andReturn(new DummyUser); $this->assertInstanceOf( DummyUser::class, @@ -245,14 +245,14 @@ public function testRetrieveUserWithMultipleGuardsAndRespectGuardsOrder() $request = m::mock(Request::class); $request->shouldReceive('user') - ->once() - ->with('myguard1') - ->andReturn(null); + ->once() + ->with('myguard1') + ->andReturn(null); $request->shouldReceive('user') - ->twice() - ->with('myguard2') - ->andReturn(new DummyUser) - ->ordered('user'); + ->twice() + ->with('myguard2') + ->andReturn(new DummyUser) + ->ordered('user'); $this->assertInstanceOf( DummyUser::class, @@ -273,11 +273,11 @@ public function testRetrieveUserDontUseDefaultGuardWhenOneGuardSpecified() $request = m::mock(Request::class); $request->shouldReceive('user') - ->once() - ->with('myguard') - ->andReturn(null); + ->once() + ->with('myguard') + ->andReturn(null); $request->shouldNotReceive('user') - ->withNoArgs(); + ->withNoArgs(); $this->broadcaster->retrieveUser($request, 'somechannel'); } @@ -290,15 +290,15 @@ public function testRetrieveUserDontUseDefaultGuardWhenMultipleGuardsSpecified() $request = m::mock(Request::class); $request->shouldReceive('user') - ->once() - ->with('myguard1') - ->andReturn(null); + ->once() + ->with('myguard1') + ->andReturn(null); $request->shouldReceive('user') - ->once() - ->with('myguard2') - ->andReturn(null); + ->once() + ->with('myguard2') + ->andReturn(null); $request->shouldNotReceive('user') - ->withNoArgs(); + ->withNoArgs(); $this->broadcaster->retrieveUser($request, 'somechannel'); } diff --git a/tests/Broadcasting/PusherBroadcasterTest.php b/tests/Broadcasting/PusherBroadcasterTest.php index d00b86d87629..9c5f3673a340 100644 --- a/tests/Broadcasting/PusherBroadcasterTest.php +++ b/tests/Broadcasting/PusherBroadcasterTest.php @@ -32,7 +32,7 @@ public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCal }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('private-test') @@ -73,7 +73,7 @@ public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCa }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('presence-test') @@ -115,8 +115,8 @@ public function testValidAuthenticationResponseCallPusherSocketAuthMethodWithPri ]; $this->pusher->shouldReceive('socket_auth') - ->once() - ->andReturn(json_encode($data)); + ->once() + ->andReturn(json_encode($data)); $this->assertEquals( $data, @@ -137,8 +137,8 @@ public function testValidAuthenticationResponseCallPusherPresenceAuthMethodWithP ]; $this->pusher->shouldReceive('presence_auth') - ->once() - ->andReturn(json_encode($data)); + ->once() + ->andReturn(json_encode($data)); $this->assertEquals( $data, @@ -181,17 +181,17 @@ protected function getMockRequestWithUserForChannel($channel) $request->shouldReceive('all')->andReturn(['channel_name' => $channel, 'socket_id' => 'abcd.1234']); $request->shouldReceive('input') - ->with('callback', false) - ->andReturn(false); + ->with('callback', false) + ->andReturn(false); $user = m::mock('User'); $user->shouldReceive('getAuthIdentifierForBroadcasting') - ->andReturn(42); + ->andReturn(42); $user->shouldReceive('getAuthIdentifier') - ->andReturn(42); + ->andReturn(42); $request->shouldReceive('user') - ->andReturn($user); + ->andReturn($user); return $request; } @@ -206,7 +206,7 @@ protected function getMockRequestWithoutUserForChannel($channel) $request->shouldReceive('all')->andReturn(['channel_name' => $channel]); $request->shouldReceive('user') - ->andReturn(null); + ->andReturn(null); return $request; } diff --git a/tests/Broadcasting/RedisBroadcasterTest.php b/tests/Broadcasting/RedisBroadcasterTest.php index 7422c5547818..87960ba034ff 100644 --- a/tests/Broadcasting/RedisBroadcasterTest.php +++ b/tests/Broadcasting/RedisBroadcasterTest.php @@ -41,7 +41,7 @@ public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCal }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('private-test') @@ -82,7 +82,7 @@ public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCa }); $this->broadcaster->shouldReceive('validAuthenticationResponse') - ->once(); + ->once(); $this->broadcaster->auth( $this->getMockRequestWithUserForChannel('presence-test') @@ -172,12 +172,12 @@ protected function getMockRequestWithUserForChannel($channel) $user = m::mock('User'); $user->shouldReceive('getAuthIdentifierForBroadcasting') - ->andReturn(42); + ->andReturn(42); $user->shouldReceive('getAuthIdentifier') - ->andReturn(42); + ->andReturn(42); $request->shouldReceive('user') - ->andReturn($user); + ->andReturn($user); return $request; } @@ -192,7 +192,7 @@ protected function getMockRequestWithoutUserForChannel($channel) $request->shouldReceive('all')->andReturn(['channel_name' => $channel]); $request->shouldReceive('user') - ->andReturn(null); + ->andReturn(null); return $request; } diff --git a/tests/Bus/BusBatchTest.php b/tests/Bus/BusBatchTest.php index 3fe602a38656..855ce91bb2b3 100644 --- a/tests/Bus/BusBatchTest.php +++ b/tests/Bus/BusBatchTest.php @@ -101,8 +101,8 @@ public function test_jobs_can_be_added_to_the_batch() }; $queue->shouldReceive('connection')->once() - ->with('test-connection') - ->andReturn($connection = m::mock(stdClass::class)); + ->with('test-connection') + ->andReturn($connection = m::mock(stdClass::class)); $connection->shouldReceive('bulk')->once()->with(m::on(function ($args) use ($job, $secondJob) { return @@ -191,8 +191,8 @@ public function test_successful_jobs_can_be_recorded() }; $queue->shouldReceive('connection')->once() - ->with('test-connection') - ->andReturn($connection = m::mock(stdClass::class)); + ->with('test-connection') + ->andReturn($connection = m::mock(stdClass::class)); $connection->shouldReceive('bulk')->once(); @@ -231,8 +231,8 @@ public function test_failed_jobs_can_be_recorded_while_not_allowing_failures() }; $queue->shouldReceive('connection')->once() - ->with('test-connection') - ->andReturn($connection = m::mock(stdClass::class)); + ->with('test-connection') + ->andReturn($connection = m::mock(stdClass::class)); $connection->shouldReceive('bulk')->once(); @@ -273,8 +273,8 @@ public function test_failed_jobs_can_be_recorded_while_allowing_failures() }; $queue->shouldReceive('connection')->once() - ->with('test-connection') - ->andReturn($connection = m::mock(stdClass::class)); + ->with('test-connection') + ->andReturn($connection = m::mock(stdClass::class)); $connection->shouldReceive('bulk')->once(); @@ -472,26 +472,26 @@ protected function createTestBatch($queue, $allowFailures = false) $repository = new DatabaseBatchRepository(new BatchFactory($queue), DB::connection(), 'job_batches'); $pendingBatch = (new PendingBatch(new Container, collect())) - ->progress(function (Batch $batch) { - $_SERVER['__progress.batch'] = $batch; - $_SERVER['__progress.count']++; - }) - ->then(function (Batch $batch) { - $_SERVER['__then.batch'] = $batch; - $_SERVER['__then.count']++; - }) - ->catch(function (Batch $batch, $e) { - $_SERVER['__catch.batch'] = $batch; - $_SERVER['__catch.exception'] = $e; - $_SERVER['__catch.count']++; - }) - ->finally(function (Batch $batch) { - $_SERVER['__finally.batch'] = $batch; - $_SERVER['__finally.count']++; - }) - ->allowFailures($allowFailures) - ->onConnection('test-connection') - ->onQueue('test-queue'); + ->progress(function (Batch $batch) { + $_SERVER['__progress.batch'] = $batch; + $_SERVER['__progress.count']++; + }) + ->then(function (Batch $batch) { + $_SERVER['__then.batch'] = $batch; + $_SERVER['__then.count']++; + }) + ->catch(function (Batch $batch, $e) { + $_SERVER['__catch.batch'] = $batch; + $_SERVER['__catch.exception'] = $e; + $_SERVER['__catch.count']++; + }) + ->finally(function (Batch $batch) { + $_SERVER['__finally.batch'] = $batch; + $_SERVER['__finally.count']++; + }) + ->allowFailures($allowFailures) + ->onConnection('test-connection') + ->onQueue('test-queue'); return $repository->store($pendingBatch); } diff --git a/tests/Console/View/ComponentsTest.php b/tests/Console/View/ComponentsTest.php index f04e9f684a9b..ef710e51effd 100644 --- a/tests/Console/View/ComponentsTest.php +++ b/tests/Console/View/ComponentsTest.php @@ -75,17 +75,17 @@ public function testConfirm() $output = m::mock(OutputStyle::class); $output->shouldReceive('confirm') - ->with('Question?', false) - ->once() - ->andReturnTrue(); + ->with('Question?', false) + ->once() + ->andReturnTrue(); $result = with(new Components\Confirm($output))->render('Question?'); $this->assertTrue($result); $output->shouldReceive('confirm') - ->with('Question?', true) - ->once() - ->andReturnTrue(); + ->with('Question?', true) + ->once() + ->andReturnTrue(); $result = with(new Components\Confirm($output))->render('Question?', true); $this->assertTrue($result); @@ -96,9 +96,9 @@ public function testChoice() $output = m::mock(OutputStyle::class); $output->shouldReceive('askQuestion') - ->with(m::type(ChoiceQuestion::class)) - ->once() - ->andReturn('a'); + ->with(m::type(ChoiceQuestion::class)) + ->once() + ->andReturn('a'); $result = with(new Components\Choice($output))->render('Question?', ['a', 'b']); $this->assertSame('a', $result); diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index 53cf9b6713ac..7c99b0cbea21 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -516,13 +516,13 @@ public function testContainerGetFactory() public function testMakeWithMethodIsAnAliasForMakeMethod() { $mock = $this->getMockBuilder(Container::class) - ->onlyMethods(['make']) - ->getMock(); + ->onlyMethods(['make']) + ->getMock(); $mock->expects($this->once()) - ->method('make') - ->with(ContainerDefaultValueStub::class, ['default' => 'laurence']) - ->willReturn(new stdClass); + ->method('make') + ->with(ContainerDefaultValueStub::class, ['default' => 'laurence']) + ->willReturn(new stdClass); $result = $mock->makeWith(ContainerDefaultValueStub::class, ['default' => 'laurence']); @@ -672,8 +672,8 @@ public function testMethodLevelContextualBinding() $container->bind(IContainerContractStub::class, ContainerImplementationStubTwo::class); $container->when(ContainerContextualBindingCallTarget::class) - ->needs(IContainerContractStub::class) - ->give(ContainerImplementationStub::class); + ->needs(IContainerContractStub::class) + ->give(ContainerImplementationStub::class); $result = $container->call([new ContainerContextualBindingCallTarget, 'work']); diff --git a/tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php b/tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php index 2b5535c5c808..7d5b184372db 100644 --- a/tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php +++ b/tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php @@ -136,11 +136,11 @@ public function testWithWhereHasOnARelationWithCustomIntermediateAndLocalKey() public function testFindMethod() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->createMany([ - ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], - ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->createMany([ + ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], + ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], + ]); $country = HasManyThroughTestCountry::first(); $post = $country->posts()->find(1); @@ -155,11 +155,11 @@ public function testFindMethod() public function testFindManyMethod() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->createMany([ - ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], - ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->createMany([ + ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], + ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], + ]); $country = HasManyThroughTestCountry::first(); @@ -184,7 +184,7 @@ public function testFindOrFailThrowsAnException() $this->expectExceptionMessage('No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost] 1'); HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']); HasManyThroughTestCountry::first()->posts()->findOrFail(1); } @@ -195,8 +195,8 @@ public function testFindOrFailWithManyThrowsAnException() $this->expectExceptionMessage('No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost] 1, 2'); HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); HasManyThroughTestCountry::first()->posts()->findOrFail([1, 2]); } @@ -207,8 +207,8 @@ public function testFindOrFailWithManyUsingCollectionThrowsAnException() $this->expectExceptionMessage('No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost] 1, 2'); HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); HasManyThroughTestCountry::first()->posts()->findOrFail(new Collection([1, 2])); } @@ -216,8 +216,8 @@ public function testFindOrFailWithManyUsingCollectionThrowsAnException() public function testFindOrMethod() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']); $result = HasManyThroughTestCountry::first()->posts()->findOr(1, fn () => 'callback result'); $this->assertInstanceOf(HasManyThroughTestPost::class, $result); @@ -236,11 +236,11 @@ public function testFindOrMethod() public function testFindOrMethodWithMany() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->createMany([ - ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], - ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->createMany([ + ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], + ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], + ]); $result = HasManyThroughTestCountry::first()->posts()->findOr([1, 2], fn () => 'callback result'); $this->assertInstanceOf(Collection::class, $result); @@ -263,11 +263,11 @@ public function testFindOrMethodWithMany() public function testFindOrMethodWithManyUsingCollection() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->createMany([ - ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], - ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->createMany([ + ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], + ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], + ]); $result = HasManyThroughTestCountry::first()->posts()->findOr(new Collection([1, 2]), fn () => 'callback result'); $this->assertInstanceOf(Collection::class, $result); @@ -500,11 +500,11 @@ public function testEagerLoadingLoadsRelatedModelsCorrectly() protected function seedData() { HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) - ->posts()->createMany([ - ['title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], - ['title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us']) + ->posts()->createMany([ + ['title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'], + ['title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'], + ]); } protected function seedDataExtended() @@ -533,11 +533,11 @@ protected function seedDataExtended() protected function seedDefaultData() { HasManyThroughDefaultTestCountry::create(['id' => 1, 'name' => 'United States of America']) - ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com']) - ->posts()->createMany([ - ['title' => 'A title', 'body' => 'A body'], - ['title' => 'Another title', 'body' => 'Another body'], - ]); + ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com']) + ->posts()->createMany([ + ['title' => 'A title', 'body' => 'A body'], + ['title' => 'Another title', 'body' => 'Another body'], + ]); } /** diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 26541e631c3b..cc01fefa4bc6 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -1175,7 +1175,7 @@ public function testHasWithNonWhereBindings() $user = EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); $user->posts()->create(['name' => 'Post 2']) - ->photos()->create(['name' => 'photo.jpg']); + ->photos()->create(['name' => 'photo.jpg']); $query = EloquentTestUser::has('postWithPhotos'); @@ -2322,7 +2322,7 @@ class EloquentTestUserWithCustomFriendPivot extends EloquentTestUser public function friends() { return $this->belongsToMany(EloquentTestUser::class, 'friends', 'user_id', 'friend_id') - ->using(EloquentTestFriendPivot::class)->withPivot('user_id', 'friend_id', 'friend_level_id'); + ->using(EloquentTestFriendPivot::class)->withPivot('user_id', 'friend_id', 'friend_level_id'); } } diff --git a/tests/Database/DatabaseMigrationMakeCommandTest.php b/tests/Database/DatabaseMigrationMakeCommandTest.php index 2ac5dde1b453..79eb535074a5 100755 --- a/tests/Database/DatabaseMigrationMakeCommandTest.php +++ b/tests/Database/DatabaseMigrationMakeCommandTest.php @@ -28,8 +28,8 @@ public function testBasicCreateDumpsAutoload() $app->useDatabasePath(__DIR__); $command->setLaravel($app); $creator->shouldReceive('create')->once() - ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) - ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); + ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) + ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); $this->runCommand($command, ['name' => 'create_foo']); } @@ -44,8 +44,8 @@ public function testBasicCreateGivesCreatorProperArguments() $app->useDatabasePath(__DIR__); $command->setLaravel($app); $creator->shouldReceive('create')->once() - ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) - ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); + ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) + ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); $this->runCommand($command, ['name' => 'create_foo']); } @@ -60,8 +60,8 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenNameIsStudlyCase() $app->useDatabasePath(__DIR__); $command->setLaravel($app); $creator->shouldReceive('create')->once() - ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) - ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); + ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true) + ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); $this->runCommand($command, ['name' => 'CreateFoo']); } @@ -76,8 +76,8 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenTableIsSet() $app->useDatabasePath(__DIR__); $command->setLaravel($app); $creator->shouldReceive('create')->once() - ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true) - ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); + ->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true) + ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php'); $this->runCommand($command, ['name' => 'create_foo', '--create' => 'users']); } @@ -92,8 +92,8 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenCreateTablePattern $app->useDatabasePath(__DIR__); $command->setLaravel($app); $creator->shouldReceive('create')->once() - ->with('create_users_table', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true) - ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_users_table.php'); + ->with('create_users_table', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true) + ->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_users_table.php'); $this->runCommand($command, ['name' => 'create_users_table']); } @@ -108,8 +108,8 @@ public function testCanSpecifyPathToCreateMigrationsIn() $command->setLaravel($app); $app->setBasePath('/home/laravel'); $creator->shouldReceive('create')->once() - ->with('create_foo', '/home/laravel/vendor/laravel-package/migrations', 'users', true) - ->andReturn('/home/laravel/vendor/laravel-package/migrations/2021_04_23_110457_create_foo.php'); + ->with('create_foo', '/home/laravel/vendor/laravel-package/migrations', 'users', true) + ->andReturn('/home/laravel/vendor/laravel-package/migrations/2021_04_23_110457_create_foo.php'); $this->runCommand($command, ['name' => 'create_foo', '--path' => 'vendor/laravel-package/migrations', '--create' => 'users']); } diff --git a/tests/Database/DatabaseMySqlSchemaStateTest.php b/tests/Database/DatabaseMySqlSchemaStateTest.php index 7d797f9287d4..3a9c7db3896c 100644 --- a/tests/Database/DatabaseMySqlSchemaStateTest.php +++ b/tests/Database/DatabaseMySqlSchemaStateTest.php @@ -99,9 +99,9 @@ public function testExecuteDumpProcessForDepth() $mockVariables = []; $schemaState = $this->getMockBuilder(MySqlSchemaState::class) - ->disableOriginalConstructor() - ->onlyMethods(['makeProcess']) - ->getMock(); + ->disableOriginalConstructor() + ->onlyMethods(['makeProcess']) + ->getMock(); $schemaState->method('makeProcess')->willReturn($mockProcess); diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 096b82450d25..a8caf61f6016 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -3578,9 +3578,9 @@ public function testSubqueriesBindings() $builder = $this->getBuilder()->select('*')->from('users')->where('email', '=', function ($q) { $q->select(new Raw('max(id)')) - ->from('users')->where('email', '=', 'bar') - ->orderByRaw('email like ?', '%.com') - ->groupBy('id')->having('id', '=', 4); + ->from('users')->where('email', '=', 'bar') + ->orderByRaw('email like ?', '%.com') + ->groupBy('id')->having('id', '=', 4); })->orWhere('id', '=', 'foo')->groupBy('id')->having('id', '=', 5); $this->assertEquals([0 => 'bar', 1 => 4, 2 => '%.com', 3 => 'foo', 4 => 5], $builder->getBindings()); } @@ -4075,9 +4075,9 @@ public function testUpdateFromMethodWithJoinsOnPostgres() $result = $builder->from('users') ->join('orders', function ($join) { $join->on('users.id', '=', 'orders.user_id') - ->where('users.id', '=', 1); + ->where('users.id', '=', 1); })->where('name', 'baz') - ->updateFrom(['email' => 'foo', 'name' => 'bar']); + ->updateFrom(['email' => 'foo', 'name' => 'bar']); $this->assertEquals(1, $result); } @@ -4427,11 +4427,11 @@ public function testMySqlUpdateWrappingJson() $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once()) - ->method('update') - ->with( - 'update `users` set `name` = json_set(`name`, \'$."first_name"\', ?), `name` = json_set(`name`, \'$."last_name"\', ?) where `active` = ?', - ['John', 'Doe', 1] - ); + ->method('update') + ->with( + 'update `users` set `name` = json_set(`name`, \'$."first_name"\', ?), `name` = json_set(`name`, \'$."last_name"\', ?) where `active` = ?', + ['John', 'Doe', 1] + ); $builder = new Builder($connection, $grammar, $processor); @@ -4445,11 +4445,11 @@ public function testMySqlUpdateWrappingNestedJson() $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once()) - ->method('update') - ->with( - 'update `users` set `meta` = json_set(`meta`, \'$."name"."first_name"\', ?), `meta` = json_set(`meta`, \'$."name"."last_name"\', ?) where `active` = ?', - ['John', 'Doe', 1] - ); + ->method('update') + ->with( + 'update `users` set `meta` = json_set(`meta`, \'$."name"."first_name"\', ?), `meta` = json_set(`meta`, \'$."name"."last_name"\', ?) where `active` = ?', + ['John', 'Doe', 1] + ); $builder = new Builder($connection, $grammar, $processor); @@ -4463,16 +4463,16 @@ public function testMySqlUpdateWrappingJsonArray() $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once()) - ->method('update') - ->with( - 'update `users` set `options` = ?, `meta` = json_set(`meta`, \'$."tags"\', cast(? as json)), `group_id` = 45, `created_at` = ? where `active` = ?', - [ - json_encode(['2fa' => false, 'presets' => ['laravel', 'vue']]), - json_encode(['white', 'large']), - new DateTime('2019-08-06'), - 1, - ] - ); + ->method('update') + ->with( + 'update `users` set `options` = ?, `meta` = json_set(`meta`, \'$."tags"\', cast(? as json)), `group_id` = 45, `created_at` = ? where `active` = ?', + [ + json_encode(['2fa' => false, 'presets' => ['laravel', 'vue']]), + json_encode(['white', 'large']), + new DateTime('2019-08-06'), + 1, + ] + ); $builder = new Builder($connection, $grammar, $processor); $builder->from('users')->where('active', 1)->update([ @@ -4490,14 +4490,14 @@ public function testMySqlUpdateWrappingJsonPathArrayIndex() $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once()) - ->method('update') - ->with( - 'update `users` set `options` = json_set(`options`, \'$[1]."2fa"\', false), `meta` = json_set(`meta`, \'$."tags"[0][2]\', ?) where `active` = ?', - [ - 'large', - 1, - ] - ); + ->method('update') + ->with( + 'update `users` set `options` = json_set(`options`, \'$[1]."2fa"\', false), `meta` = json_set(`meta`, \'$."tags"[0][2]\', ?) where `active` = ?', + [ + 'large', + 1, + ] + ); $builder = new Builder($connection, $grammar, $processor); $builder->from('users')->where('active', 1)->update([ @@ -4513,11 +4513,11 @@ public function testMySqlUpdateWithJsonPreparesBindingsCorrectly() $connection = m::mock(ConnectionInterface::class); $connection->shouldReceive('update') - ->once() - ->with( - 'update `users` set `options` = json_set(`options`, \'$."enable"\', false), `updated_at` = ? where `id` = ?', - ['2015-05-26 22:02:06', 0] - ); + ->once() + ->with( + 'update `users` set `options` = json_set(`options`, \'$."enable"\', false), `updated_at` = ? where `id` = ?', + ['2015-05-26 22:02:06', 0] + ); $builder = new Builder($connection, $grammar, $processor); $builder->from('users')->where('id', '=', 0)->update(['options->enable' => false, 'updated_at' => '2015-05-26 22:02:06']); diff --git a/tests/Foundation/Console/RouteListCommandTest.php b/tests/Foundation/Console/RouteListCommandTest.php index 6033aadc2940..a1a93fa155ee 100644 --- a/tests/Foundation/Console/RouteListCommandTest.php +++ b/tests/Foundation/Console/RouteListCommandTest.php @@ -57,7 +57,7 @@ protected function setUp(): void $router->get('/sub-example', function () { return 'Hello World'; })->domain('sub') - ->middleware('exampleMiddleware'); + ->middleware('exampleMiddleware'); $router->get('/example-group', function () { return 'Hello Group'; diff --git a/tests/Foundation/FoundationFormRequestTest.php b/tests/Foundation/FoundationFormRequestTest.php index 9dd164585b5d..8827b8f92f66 100644 --- a/tests/Foundation/FoundationFormRequestTest.php +++ b/tests/Foundation/FoundationFormRequestTest.php @@ -272,7 +272,7 @@ protected function createRequest($payload = [], $class = FoundationTestFormReque $request = $class::create('/', 'GET', $payload); return $request->setRedirector($this->createMockRedirector($request)) - ->setContainer($container); + ->setContainer($container); } /** @@ -284,7 +284,7 @@ protected function createRequest($payload = [], $class = FoundationTestFormReque protected function createValidationFactory($container) { $translator = m::mock(Translator::class)->shouldReceive('get') - ->zeroOrMoreTimes()->andReturn('error')->getMock(); + ->zeroOrMoreTimes()->andReturn('error')->getMock(); return new ValidationFactory($translator, $container); } @@ -300,13 +300,13 @@ protected function createMockRedirector($request) $redirector = $this->mocks['redirector'] = m::mock(Redirector::class); $redirector->shouldReceive('getUrlGenerator')->zeroOrMoreTimes() - ->andReturn($generator = $this->createMockUrlGenerator()); + ->andReturn($generator = $this->createMockUrlGenerator()); $redirector->shouldReceive('to')->zeroOrMoreTimes() - ->andReturn($this->createMockRedirectResponse()); + ->andReturn($this->createMockRedirectResponse()); $generator->shouldReceive('previous')->zeroOrMoreTimes() - ->andReturn('previous'); + ->andReturn('previous'); return $redirector; } diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 21c9718c2da6..77570b385254 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -727,7 +727,7 @@ public function testFilesCanBeAttached() $this->factory->fake(); $this->factory->attach('foo', 'data', 'file.txt', ['X-Test-Header' => 'foo']) - ->post('http://foo.com/file'); + ->post('http://foo.com/file'); $this->factory->assertSent(function (Request $request) { return $request->url() === 'http://foo.com/file' && diff --git a/tests/Integration/Database/EloquentCursorPaginateTest.php b/tests/Integration/Database/EloquentCursorPaginateTest.php index 54480f90bf76..fb6d83b899b4 100644 --- a/tests/Integration/Database/EloquentCursorPaginateTest.php +++ b/tests/Integration/Database/EloquentCursorPaginateTest.php @@ -164,7 +164,7 @@ public function testPaginationWithMultipleWhereClauses() $this->assertCount( 1, $anotherQuery->cursorPaginate(5, ['*'], 'cursor', new Cursor(['id' => 3])) - ->items() + ->items() ); } @@ -239,7 +239,7 @@ public function testPaginationWithAliasedOrderBy() $this->assertCount( 4, $anotherQuery->cursorPaginate(10, ['*'], 'cursor', new Cursor(['user_id' => 2])) - ->items() + ->items() ); } diff --git a/tests/Integration/Database/EloquentPivotSerializationTest.php b/tests/Integration/Database/EloquentPivotSerializationTest.php index f308072f6004..52fc6a3dc985 100644 --- a/tests/Integration/Database/EloquentPivotSerializationTest.php +++ b/tests/Integration/Database/EloquentPivotSerializationTest.php @@ -164,7 +164,7 @@ public function collaborators() public function tags() { return $this->morphToMany(PivotSerializationTestTag::class, 'taggable', 'taggables', 'taggable_id', 'tag_id') - ->using(PivotSerializationTestTagAttachment::class); + ->using(PivotSerializationTestTagAttachment::class); } } @@ -175,7 +175,7 @@ class PivotSerializationTestTag extends Model public function projects() { return $this->morphedByMany(PivotSerializationTestProject::class, 'taggable', 'taggables', 'tag_id', 'taggable_id') - ->using(PivotSerializationTestTagAttachment::class); + ->using(PivotSerializationTestTagAttachment::class); } } diff --git a/tests/Integration/Database/EloquentPivotTest.php b/tests/Integration/Database/EloquentPivotTest.php index 2757992f6927..a45ca0fe78f7 100644 --- a/tests/Integration/Database/EloquentPivotTest.php +++ b/tests/Integration/Database/EloquentPivotTest.php @@ -91,17 +91,17 @@ class PivotTestUser extends Model public function activeSubscriptions() { return $this->belongsToMany(PivotTestProject::class, 'subscriptions', 'user_id', 'project_id') - ->withPivotValue('status', 'active') - ->withPivot('status') - ->using(PivotTestSubscription::class); + ->withPivotValue('status', 'active') + ->withPivot('status') + ->using(PivotTestSubscription::class); } public function inactiveSubscriptions() { return $this->belongsToMany(PivotTestProject::class, 'subscriptions', 'user_id', 'project_id') - ->withPivotValue('status', 'inactive') - ->withPivot('status') - ->using(PivotTestSubscription::class); + ->withPivotValue('status', 'inactive') + ->withPivot('status') + ->using(PivotTestSubscription::class); } } @@ -114,7 +114,7 @@ public function collaborators() return $this->belongsToMany( PivotTestUser::class, 'collaborators', 'project_id', 'user_id' )->withPivot('permissions') - ->using(PivotTestCollaborator::class); + ->using(PivotTestCollaborator::class); } public function contributors() diff --git a/tests/Integration/Testing/ArtisanCommandTest.php b/tests/Integration/Testing/ArtisanCommandTest.php index 08cd327e0582..fc26269e227f 100644 --- a/tests/Integration/Testing/ArtisanCommandTest.php +++ b/tests/Integration/Testing/ArtisanCommandTest.php @@ -73,24 +73,24 @@ public function test_console_command_that_fails() public function test_console_command_that_passes_with_output() { $this->artisan('survey') - ->expectsQuestion('What is your name?', 'Taylor Otwell') - ->expectsQuestion('Which language do you prefer?', 'PHP') - ->expectsOutput('Your name is Taylor Otwell and you prefer PHP.') - ->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.') - ->assertExitCode(0); + ->expectsQuestion('What is your name?', 'Taylor Otwell') + ->expectsQuestion('Which language do you prefer?', 'PHP') + ->expectsOutput('Your name is Taylor Otwell and you prefer PHP.') + ->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.') + ->assertExitCode(0); } public function test_console_command_that_passes_with_repeating_output() { $this->artisan('slim') - ->expectsQuestion('Who?', 'Taylor') - ->expectsQuestion('What?', 'Taylor') - ->expectsQuestion('Huh?', 'Taylor') - ->expectsOutput('Taylor') - ->doesntExpectOutput('Otwell') - ->expectsOutput('Taylor') - ->expectsOutput('Taylor') - ->assertExitCode(0); + ->expectsQuestion('Who?', 'Taylor') + ->expectsQuestion('What?', 'Taylor') + ->expectsQuestion('Huh?', 'Taylor') + ->expectsOutput('Taylor') + ->doesntExpectOutput('Otwell') + ->expectsOutput('Taylor') + ->expectsOutput('Taylor') + ->assertExitCode(0); } public function test_console_command_that_fails_from_unexpected_output() @@ -99,10 +99,10 @@ public function test_console_command_that_fails_from_unexpected_output() $this->expectExceptionMessage('Output "Your name is Taylor Otwell and you prefer PHP." was printed.'); $this->artisan('survey') - ->expectsQuestion('What is your name?', 'Taylor Otwell') - ->expectsQuestion('Which language do you prefer?', 'PHP') - ->doesntExpectOutput('Your name is Taylor Otwell and you prefer PHP.') - ->assertExitCode(0); + ->expectsQuestion('What is your name?', 'Taylor Otwell') + ->expectsQuestion('Which language do you prefer?', 'PHP') + ->doesntExpectOutput('Your name is Taylor Otwell and you prefer PHP.') + ->assertExitCode(0); } public function test_console_command_that_fails_from_unexpected_output_substring() @@ -111,8 +111,8 @@ public function test_console_command_that_fails_from_unexpected_output_substring $this->expectExceptionMessage('Output "Taylor Otwell" was printed.'); $this->artisan('contains') - ->doesntExpectOutputToContain('Taylor Otwell') - ->assertExitCode(0); + ->doesntExpectOutputToContain('Taylor Otwell') + ->assertExitCode(0); } public function test_console_command_that_fails_from_missing_output() @@ -122,10 +122,10 @@ public function test_console_command_that_fails_from_missing_output() $this->ignoringMockOnceExceptions(function () { $this->artisan('survey') - ->expectsQuestion('What is your name?', 'Taylor Otwell') - ->expectsQuestion('Which language do you prefer?', 'Ruby') - ->expectsOutput('Your name is Taylor Otwell and you prefer PHP.') - ->assertExitCode(0); + ->expectsQuestion('What is your name?', 'Taylor Otwell') + ->expectsQuestion('Which language do you prefer?', 'Ruby') + ->expectsOutput('Your name is Taylor Otwell and you prefer PHP.') + ->assertExitCode(0); }); } @@ -135,9 +135,9 @@ public function test_console_command_that_fails_from_exit_code_mismatch() $this->expectExceptionMessage('Expected status code 1 but received 0.'); $this->artisan('survey') - ->expectsQuestion('What is your name?', 'Taylor Otwell') - ->expectsQuestion('Which language do you prefer?', 'PHP') - ->assertExitCode(1); + ->expectsQuestion('What is your name?', 'Taylor Otwell') + ->expectsQuestion('Which language do you prefer?', 'PHP') + ->assertExitCode(1); } public function test_console_command_that_fails_from_unordered_output() @@ -146,21 +146,21 @@ public function test_console_command_that_fails_from_unordered_output() $this->ignoringMockOnceExceptions(function () { $this->artisan('slim') - ->expectsQuestion('Who?', 'Taylor') - ->expectsQuestion('What?', 'Danger') - ->expectsQuestion('Huh?', 'Otwell') - ->expectsOutput('Taylor') - ->expectsOutput('Otwell') - ->expectsOutput('Danger') - ->assertExitCode(0); + ->expectsQuestion('Who?', 'Taylor') + ->expectsQuestion('What?', 'Danger') + ->expectsQuestion('Huh?', 'Otwell') + ->expectsOutput('Taylor') + ->expectsOutput('Otwell') + ->expectsOutput('Danger') + ->assertExitCode(0); }); } public function test_console_command_that_passes_if_the_output_contains() { $this->artisan('contains') - ->expectsOutputToContain('Taylor Otwell') - ->assertExitCode(0); + ->expectsOutputToContain('Taylor Otwell') + ->assertExitCode(0); } public function test_console_command_that_passes_if_outputs_something() @@ -270,8 +270,8 @@ public function test_console_command_that_fails_if_the_output_does_not_contain() $this->ignoringMockOnceExceptions(function () { $this->artisan('contains') - ->expectsOutputToContain('Otwell Taylor') - ->assertExitCode(0); + ->expectsOutputToContain('Otwell Taylor') + ->assertExitCode(0); }); } diff --git a/tests/Mail/MailMailableDataTest.php b/tests/Mail/MailMailableDataTest.php index 01737705b033..282aa2f125e0 100644 --- a/tests/Mail/MailMailableDataTest.php +++ b/tests/Mail/MailMailableDataTest.php @@ -24,7 +24,7 @@ public function testMailableDataIsNotLost() $mailable = new MailableStub; $mailable->build(function ($m) use ($testData) { $m->view('view', $testData) - ->text('text-view'); + ->text('text-view'); }); $this->assertSame($testData, $mailable->buildViewData()); } diff --git a/tests/Mail/MailMailableTest.php b/tests/Mail/MailMailableTest.php index 4d461319da77..9de9abc40f97 100644 --- a/tests/Mail/MailMailableTest.php +++ b/tests/Mail/MailMailableTest.php @@ -1209,7 +1209,7 @@ class WelcomeMailableStub extends Mailable public function build() { $this->with('first_name', 'Taylor') - ->withLastName('Otwell'); + ->withLastName('Otwell'); } } diff --git a/tests/Notifications/NotificationMailMessageTest.php b/tests/Notifications/NotificationMailMessageTest.php index 7a59cfd8890d..b901f0aab297 100644 --- a/tests/Notifications/NotificationMailMessageTest.php +++ b/tests/Notifications/NotificationMailMessageTest.php @@ -75,7 +75,7 @@ public function testCcIsSetCorrectly() $message = new MailMessage; $message->cc('test@example.com') - ->cc('test@example.com', 'Test'); + ->cc('test@example.com', 'Test'); $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->cc); @@ -94,7 +94,7 @@ public function testBccIsSetCorrectly() $message = new MailMessage; $message->bcc('test@example.com') - ->bcc('test@example.com', 'Test'); + ->bcc('test@example.com', 'Test'); $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->bcc); @@ -113,7 +113,7 @@ public function testReplyToIsSetCorrectly() $message = new MailMessage; $message->replyTo('test@example.com') - ->replyTo('test@example.com', 'Test'); + ->replyTo('test@example.com', 'Test'); $this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->replyTo); diff --git a/tests/Pipeline/PipelineTest.php b/tests/Pipeline/PipelineTest.php index 6e155f01f49e..1d392aab5b94 100644 --- a/tests/Pipeline/PipelineTest.php +++ b/tests/Pipeline/PipelineTest.php @@ -20,11 +20,11 @@ public function testPipelineBasicUsage() }; $result = (new Pipeline(new Container)) - ->send('foo') - ->through([PipelineTestPipeOne::class, $pipeTwo]) - ->then(function ($piped) { - return $piped; - }); + ->send('foo') + ->through([PipelineTestPipeOne::class, $pipeTwo]) + ->then(function ($piped) { + return $piped; + }); $this->assertSame('foo', $result); $this->assertSame('foo', $_SERVER['__test.pipe.one']); @@ -235,9 +235,9 @@ public function testPipelineThrowsExceptionOnResolveWithoutContainer() public function testPipelineThenReturnMethodRunsPipelineThenReturnsPassable() { $result = (new Pipeline(new Container)) - ->send('foo') - ->through([PipelineTestPipeOne::class]) - ->thenReturn(); + ->send('foo') + ->through([PipelineTestPipeOne::class]) + ->thenReturn(); $this->assertSame('foo', $result); $this->assertSame('foo', $_SERVER['__test.pipe.one']); diff --git a/tests/Process/ProcessTest.php b/tests/Process/ProcessTest.php index 8b51dad64f9a..16ed54aa934d 100644 --- a/tests/Process/ProcessTest.php +++ b/tests/Process/ProcessTest.php @@ -319,8 +319,8 @@ public function testProcessFakeSequences() $factory->fake([ 'ls *' => $factory->sequence() - ->push('ls command 1') - ->push('ls command 2'), + ->push('ls command 1') + ->push('ls command 2'), 'cat *' => 'cat command', ]); @@ -340,9 +340,9 @@ public function testProcessFakeSequencesCanReturnEmptyResultsWhenSequenceIsEmpty $factory->fake([ 'ls *' => $factory->sequence() - ->push('ls command 1') - ->push('ls command 2') - ->dontFailWhenEmpty(), + ->push('ls command 1') + ->push('ls command 2') + ->dontFailWhenEmpty(), ]); $result = $factory->run('ls -la'); @@ -363,8 +363,8 @@ public function testProcessFakeSequencesCanThrowWhenSequenceIsEmpty() $factory->fake([ 'ls *' => $factory->sequence() - ->push('ls command 1') - ->push('ls command 2'), + ->push('ls command 1') + ->push('ls command 2'), ]); $result = $factory->run('ls -la'); @@ -716,10 +716,10 @@ public function testFakeInvokedProcessOutputWithLatestOutput() $factory->fake(function () use ($factory) { return $factory->describe() - ->output('ONE') - ->output('TWO') - ->output('THREE') - ->runsFor(iterations: 3); + ->output('ONE') + ->output('TWO') + ->output('THREE') + ->runsFor(iterations: 3); }); $process = $factory->start('echo "ONE"; sleep 1; echo "TWO"; sleep 1; echo "THREE"; sleep 1;'); diff --git a/tests/Routing/RouteRegistrarTest.php b/tests/Routing/RouteRegistrarTest.php index 465f92cd26f8..83ff3392459c 100644 --- a/tests/Routing/RouteRegistrarTest.php +++ b/tests/Routing/RouteRegistrarTest.php @@ -246,7 +246,7 @@ public function testCanRegisterRouteWithArrayAndClosureUsesAction() public function testCanRegisterRouteWithControllerAction() { $this->router->middleware('controller-middleware') - ->get('users', RouteRegistrarControllerStub::class.'@index'); + ->get('users', RouteRegistrarControllerStub::class.'@index'); $this->seeResponse('controller', Request::create('users', 'GET')); $this->seeMiddleware('controller-middleware'); @@ -255,7 +255,7 @@ public function testCanRegisterRouteWithControllerAction() public function testCanRegisterRouteWithControllerActionArray() { $this->router->middleware('controller-middleware') - ->get('users', [RouteRegistrarControllerStub::class, 'index']); + ->get('users', [RouteRegistrarControllerStub::class, 'index']); $this->seeResponse('controller', Request::create('users', 'GET')); $this->seeMiddleware('controller-middleware'); @@ -519,7 +519,7 @@ public function testRegisteringNonApprovedAttributesThrows() public function testCanRegisterResource() { $this->router->middleware('resource-middleware') - ->resource('users', RouteRegistrarControllerStub::class); + ->resource('users', RouteRegistrarControllerStub::class); $this->seeResponse('deleted', Request::create('users/1', 'DELETE')); $this->seeMiddleware('resource-middleware'); @@ -611,8 +611,8 @@ public function testCanRegisterResourceWithMissingOption() public function testCanAccessRegisteredResourceRoutesAsRouteCollection() { $resource = $this->router->middleware('resource-middleware') - ->resource('users', RouteRegistrarControllerStub::class) - ->register(); + ->resource('users', RouteRegistrarControllerStub::class) + ->register(); $this->assertCount(7, $resource->getRoutes()); @@ -628,7 +628,7 @@ public function testCanAccessRegisteredResourceRoutesAsRouteCollection() public function testCanLimitMethodsOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->only('index', 'show', 'destroy'); + ->only('index', 'show', 'destroy'); $this->assertCount(3, $this->router->getRoutes()); @@ -640,7 +640,7 @@ public function testCanLimitMethodsOnRegisteredResource() public function testCanExcludeMethodsOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->except(['index', 'create', 'store', 'show', 'edit']); + ->except(['index', 'create', 'store', 'show', 'edit']); $this->assertCount(2, $this->router->getRoutes()); @@ -651,8 +651,8 @@ public function testCanExcludeMethodsOnRegisteredResource() public function testCanLimitAndExcludeMethodsOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->only('index', 'show', 'destroy') - ->except('destroy'); + ->only('index', 'show', 'destroy') + ->except('destroy'); $this->assertCount(2, $this->router->getRoutes()); @@ -700,7 +700,7 @@ public function testCanSetScopedOptionOnRegisteredResource() public function testCanExcludeMethodsOnRegisteredApiResource() { $this->router->apiResource('users', RouteRegistrarControllerStub::class) - ->except(['index', 'show', 'store']); + ->except(['index', 'show', 'store']); $this->assertCount(2, $this->router->getRoutes()); @@ -812,18 +812,18 @@ public function testUserCanRegisterApiResourceWithOnlyOption() public function testCanNameRoutesOnRegisteredResource() { $this->router->resource('comments', RouteRegistrarControllerStub::class) - ->only('create', 'store')->names('reply'); + ->only('create', 'store')->names('reply'); $this->router->resource('users', RouteRegistrarControllerStub::class) - ->only('create', 'store')->names([ - 'create' => 'user.build', - 'store' => 'user.save', - ]); + ->only('create', 'store')->names([ + 'create' => 'user.build', + 'store' => 'user.save', + ]); $this->router->resource('posts', RouteRegistrarControllerStub::class) - ->only('create', 'destroy') - ->name('create', 'posts.make') - ->name('destroy', 'posts.remove'); + ->only('create', 'destroy') + ->name('create', 'posts.make') + ->name('destroy', 'posts.remove'); $this->assertTrue($this->router->getRoutes()->hasNamedRoute('reply.create')); $this->assertTrue($this->router->getRoutes()->hasNamedRoute('reply.store')); @@ -836,10 +836,10 @@ public function testCanNameRoutesOnRegisteredResource() public function testCanOverrideParametersOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->parameters(['users' => 'admin_user']); + ->parameters(['users' => 'admin_user']); $this->router->resource('posts', RouteRegistrarControllerStub::class) - ->parameter('posts', 'topic'); + ->parameter('posts', 'topic'); $this->assertStringContainsString('admin_user', $this->router->getRoutes()->getByName('users.show')->uri); $this->assertStringContainsString('topic', $this->router->getRoutes()->getByName('posts.show')->uri); @@ -848,7 +848,7 @@ public function testCanOverrideParametersOnRegisteredResource() public function testCanSetMiddlewareOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->middleware(RouteRegistrarMiddlewareStub::class); + ->middleware(RouteRegistrarMiddlewareStub::class); $this->seeMiddleware(RouteRegistrarMiddlewareStub::class); } @@ -856,10 +856,10 @@ public function testCanSetMiddlewareOnRegisteredResource() public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->middleware('default') - ->middlewareFor('index', RouteRegistrarMiddlewareStub::class) - ->middlewareFor(['create', 'store'], 'one') - ->middlewareFor(['edit'], ['one', 'two']); + ->middleware('default') + ->middlewareFor('index', RouteRegistrarMiddlewareStub::class) + ->middlewareFor(['create', 'store'], 'one') + ->middlewareFor(['edit'], ['one', 'two']); $this->assertEquals($this->router->getRoutes()->getByName('users.index')->gatherMiddleware(), ['default', RouteRegistrarMiddlewareStub::class]); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->gatherMiddleware(), ['default', 'one']); @@ -870,10 +870,10 @@ public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredResource() $this->assertEquals($this->router->getRoutes()->getByName('users.destroy')->gatherMiddleware(), ['default']); $this->router->resource('users', RouteRegistrarControllerStub::class) - ->middlewareFor('index', RouteRegistrarMiddlewareStub::class) - ->middlewareFor(['create', 'store'], 'one') - ->middlewareFor(['edit'], ['one', 'two']) - ->middleware('default'); + ->middlewareFor('index', RouteRegistrarMiddlewareStub::class) + ->middlewareFor(['create', 'store'], 'one') + ->middlewareFor(['edit'], ['one', 'two']) + ->middleware('default'); $this->assertEquals($this->router->getRoutes()->getByName('users.index')->gatherMiddleware(), [RouteRegistrarMiddlewareStub::class, 'default']); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->gatherMiddleware(), ['one', 'default']); @@ -887,9 +887,9 @@ public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredResource() public function testResourceWithoutMiddlewareRegistration() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->only('index') - ->middleware(['one', 'two']) - ->withoutMiddleware('one'); + ->only('index') + ->middleware(['one', 'two']) + ->withoutMiddleware('one'); $this->seeResponse('controller', Request::create('users', 'GET')); @@ -899,10 +899,10 @@ public function testResourceWithoutMiddlewareRegistration() public function testCanSetExcludedMiddlewareForSpecifiedMethodsOnRegisteredResource() { $this->router->resource('users', RouteRegistrarControllerStub::class) - ->withoutMiddleware('one') - ->withoutMiddlewareFor('index', 'two') - ->withoutMiddlewareFor(['create', 'store'], 'three') - ->withoutMiddlewareFor(['edit'], ['four', 'five']); + ->withoutMiddleware('one') + ->withoutMiddlewareFor('index', 'two') + ->withoutMiddlewareFor(['create', 'store'], 'three') + ->withoutMiddlewareFor(['edit'], ['four', 'five']); $this->assertEquals($this->router->getRoutes()->getByName('users.index')->excludedMiddleware(), ['one', 'two']); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->excludedMiddleware(), ['one', 'three']); @@ -924,9 +924,9 @@ public function __toString() }; $this->router->resource('users', RouteRegistrarControllerStub::class) - ->only('index') - ->middleware([$one, 'two']) - ->withoutMiddleware('one'); + ->only('index') + ->middleware([$one, 'two']) + ->withoutMiddleware('one'); $this->seeResponse('controller', Request::create('users', 'GET')); @@ -942,7 +942,7 @@ public function testResourceWheres() ]; $this->router->resource('users', RouteRegistrarControllerStub::class) - ->where($wheres); + ->where($wheres); /** @var \Illuminate\Routing\Route $route */ foreach ($this->router->getRoutes() as $route) { @@ -1398,12 +1398,12 @@ public function testApiSingletonCanIncludeAnySingletonMethods() public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredSingletonResource() { $this->router->singleton('users', RouteRegistrarControllerStub::class) - ->creatable() - ->destroyable() - ->middleware('default') - ->middlewareFor('show', RouteRegistrarMiddlewareStub::class) - ->middlewareFor(['create', 'store'], 'one') - ->middlewareFor(['edit'], ['one', 'two']); + ->creatable() + ->destroyable() + ->middleware('default') + ->middlewareFor('show', RouteRegistrarMiddlewareStub::class) + ->middlewareFor(['create', 'store'], 'one') + ->middlewareFor(['edit'], ['one', 'two']); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->gatherMiddleware(), ['default', 'one']); $this->assertEquals($this->router->getRoutes()->getByName('users.store')->gatherMiddleware(), ['default', 'one']); @@ -1413,12 +1413,12 @@ public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredSingletonReso $this->assertEquals($this->router->getRoutes()->getByName('users.destroy')->gatherMiddleware(), ['default']); $this->router->singleton('users', RouteRegistrarControllerStub::class) - ->creatable() - ->destroyable() - ->middlewareFor('show', RouteRegistrarMiddlewareStub::class) - ->middlewareFor(['create', 'store'], 'one') - ->middlewareFor(['edit'], ['one', 'two']) - ->middleware('default'); + ->creatable() + ->destroyable() + ->middlewareFor('show', RouteRegistrarMiddlewareStub::class) + ->middlewareFor(['create', 'store'], 'one') + ->middlewareFor(['edit'], ['one', 'two']) + ->middleware('default'); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->gatherMiddleware(), ['one', 'default']); $this->assertEquals($this->router->getRoutes()->getByName('users.store')->gatherMiddleware(), ['one', 'default']); @@ -1431,12 +1431,12 @@ public function testCanSetMiddlewareForSpecifiedMethodsOnRegisteredSingletonReso public function testCanSetExcludedMiddlewareForSpecifiedMethodsOnRegisteredSingletonResource() { $this->router->singleton('users', RouteRegistrarControllerStub::class) - ->creatable() - ->destroyable() - ->withoutMiddleware('one') - ->withoutMiddlewareFor('show', 'two') - ->withoutMiddlewareFor(['create', 'store'], 'three') - ->withoutMiddlewareFor(['edit'], ['four', 'five']); + ->creatable() + ->destroyable() + ->withoutMiddleware('one') + ->withoutMiddlewareFor('show', 'two') + ->withoutMiddlewareFor(['create', 'store'], 'three') + ->withoutMiddlewareFor(['edit'], ['four', 'five']); $this->assertEquals($this->router->getRoutes()->getByName('users.create')->excludedMiddleware(), ['one', 'three']); $this->assertEquals($this->router->getRoutes()->getByName('users.store')->excludedMiddleware(), ['one', 'three']); diff --git a/tests/Support/SleepTest.php b/tests/Support/SleepTest.php index 809ba41b8629..228364891008 100644 --- a/tests/Support/SleepTest.php +++ b/tests/Support/SleepTest.php @@ -152,7 +152,7 @@ public function testItCanChainDurations() Sleep::fake(); $sleep = Sleep::for(1)->second() - ->and(500)->microseconds(); + ->and(500)->microseconds(); $this->assertSame((float) $sleep->duration->totalMicroseconds, 1000500.0); } diff --git a/tests/Support/SupportLazyCollectionIsLazyTest.php b/tests/Support/SupportLazyCollectionIsLazyTest.php index 66cda339158e..328ca23b2af4 100644 --- a/tests/Support/SupportLazyCollectionIsLazyTest.php +++ b/tests/Support/SupportLazyCollectionIsLazyTest.php @@ -1583,7 +1583,7 @@ public function testWhereInstanceOfIsLazy() { $data = $this->make(['a' => 0])->concat( $this->make([['a' => 1], ['a' => 2], ['a' => 3], ['a' => 4]]) - ->mapInto(stdClass::class) + ->mapInto(stdClass::class) ); $this->assertDoesNotEnumerateCollection($data, function ($collection) { diff --git a/tests/Support/SupportTestingMailFakeTest.php b/tests/Support/SupportTestingMailFakeTest.php index 07189bb92efc..4a37c2a729ce 100644 --- a/tests/Support/SupportTestingMailFakeTest.php +++ b/tests/Support/SupportTestingMailFakeTest.php @@ -396,7 +396,7 @@ class MailableStub extends Mailable public function build() { $this->with('first_name', 'Taylor') - ->withLastName('Otwell'); + ->withLastName('Otwell'); } } @@ -414,7 +414,7 @@ class QueueableMailableStub extends Mailable implements ShouldQueue public function build() { $this->with('first_name', 'Taylor') - ->withLastName('Otwell'); + ->withLastName('Otwell'); } } diff --git a/tests/Validation/ValidationFactoryTest.php b/tests/Validation/ValidationFactoryTest.php index 4101e200d773..deb9134b150b 100755 --- a/tests/Validation/ValidationFactoryTest.php +++ b/tests/Validation/ValidationFactoryTest.php @@ -64,8 +64,8 @@ public function testValidateCallsValidateOnTheValidator() $factory = m::mock(Factory::class.'[make]', [$translator]); $factory->shouldReceive('make')->once() - ->with(['foo' => 'bar', 'baz' => 'boom'], ['foo' => 'required'], [], []) - ->andReturn($validator); + ->with(['foo' => 'bar', 'baz' => 'boom'], ['foo' => 'required'], [], []) + ->andReturn($validator); $validator->shouldReceive('validate')->once()->andReturn(['foo' => 'bar']); From 8a463205a18dea527042d9a9b18883ca95c8a6c5 Mon Sep 17 00:00:00 2001 From: Richard Fletcher Date: Fri, 24 Jan 2025 15:40:04 +0000 Subject: [PATCH 08/14] fix(Collection::pop()): count < 1 (#54340) * fix(Collection::pop()): count < 1 If $count = 0 then this method was returning the same as if $count=1. If count<0 then things got worse than that. I think that in this case pop of <1 makes no sense and either we should throw an error, or we should return an empty result. I've gone with an empty result as I can see that being returned by the function anyway. * Update Collection.php --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Collections/Collection.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 9b95b18f949d..eba7aaee6155 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -986,6 +986,10 @@ public function select($keys) */ public function pop($count = 1) { + if ($count < 1) { + return new static; + } + if ($count === 1) { return array_pop($this->items); } From c61bac0f2a8c885eeb8cffa9c055240f8e3f3957 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 24 Jan 2025 15:40:32 +0000 Subject: [PATCH 09/14] Apply fixes from StyleCI --- src/Illuminate/Collections/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index eba7aaee6155..01e1114ed84b 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -986,10 +986,10 @@ public function select($keys) */ public function pop($count = 1) { - if ($count < 1) { + if ($count < 1) { return new static; } - + if ($count === 1) { return array_pop($this->items); } From 86eae446b9fa9f3db8627e8b6bd29d72b291d3e4 Mon Sep 17 00:00:00 2001 From: Dennis Koster Date: Fri, 24 Jan 2025 16:43:19 +0100 Subject: [PATCH 10/14] Patch CVE-2025-22145 in nesbot/carbon package (#54335) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 76e2d34ad034..39ea6589a7f7 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "league/flysystem-local": "^3.25.1", "league/uri": "^7.5.1", "monolog/monolog": "^3.0", - "nesbot/carbon": "^2.72.2|^3.4", + "nesbot/carbon": "^2.72.6|^3.8.4", "nunomaduro/termwind": "^2.0", "psr/container": "^1.1.1|^2.0.1", "psr/log": "^1.0|^2.0|^3.0", From b030dbb3c77aa553b976a8fae4ce823c3459e702 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jan 2025 10:08:55 -0600 Subject: [PATCH 11/14] disable retain visibility on r2 --- src/Illuminate/Filesystem/FilesystemManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index dfdab7c6e7f8..ed139a81eb41 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -324,6 +324,10 @@ protected function createFlysystem(FlysystemAdapter $adapter, array $config) $adapter = new PathPrefixedAdapter($adapter, $config['prefix']); } + if (str_contains($config['endpoint'] ?? '', 'r2.cloudflarestorage.com')) { + $config['retain_visibility'] = false; + } + return new Flysystem($adapter, Arr::only($config, [ 'directory_visibility', 'disable_asserts', From 48b82c29c6c7e724d05cd22b0a8e539ed4102204 Mon Sep 17 00:00:00 2001 From: Jeppe Knockaert Date: Fri, 24 Jan 2025 17:15:29 +0100 Subject: [PATCH 12/14] [11.x] Prevent unintended serialization and compression (#54337) * Prevent unintended serialization and compression * formatting --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Cache/RedisStore.php | 17 ++++++++++++++++- tests/Integration/Cache/RedisStoreTest.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index d84c9a505965..ebdd0febbd82 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -432,6 +432,10 @@ public function setPrefix($prefix) protected function pack($value, $connection) { if ($connection instanceof PhpRedisConnection) { + if ($this->shouldBeStoredWithoutSerialization($value)) { + return $value; + } + if ($connection->serialized()) { return $connection->pack([$value])[0]; } @@ -452,7 +456,18 @@ protected function pack($value, $connection) */ protected function serialize($value) { - return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value) ? $value : serialize($value); + return $this->shouldBeStoredWithoutSerialization($value) ? $value : serialize($value); + } + + /** + * Determine if the given value should be stored as plain value. + * + * @param mixed $value + * @return bool + */ + protected function shouldBeStoredWithoutSerialization($value): bool + { + return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value); } /** diff --git a/tests/Integration/Cache/RedisStoreTest.php b/tests/Integration/Cache/RedisStoreTest.php index 8df8b4ee3f9c..25ee5ccbe721 100644 --- a/tests/Integration/Cache/RedisStoreTest.php +++ b/tests/Integration/Cache/RedisStoreTest.php @@ -249,4 +249,20 @@ public function testPutManyCallsPutWhenClustered() 'fizz' => 'buz', ], 10); } + + public function testIncrementWithSerializationEnabled() + { + /** @var \Illuminate\Cache\RedisStore $store */ + $store = Cache::store('redis'); + /** @var \Redis $client */ + $client = $store->connection()->client(); + $client->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); + + $store->flush(); + $store->add('foo', 1, 10); + $this->assertEquals(1, $store->get('foo')); + + $store->increment('foo'); + $this->assertEquals(2, $store->get('foo')); + } } From f4043fe4d090bf40b90637bdd52dd0a8d95d2c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Debrauwer?= Date: Fri, 24 Jan 2025 17:16:27 +0100 Subject: [PATCH 13/14] [11.x] Pass collection of models to `whereMorphedTo` / `whereNotMorphedTo` (#54324) * where(Not)MorphedTo with collection * Extra tests * Allow arrays * Fix docblocks --- .../Concerns/QueriesRelationships.php | 40 +++-- .../Database/DatabaseEloquentBuilderTest.php | 156 +++++++++++++++++- 2 files changed, 182 insertions(+), 14 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php index 1e602ff35cb8..e064689a8f54 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php @@ -536,7 +536,7 @@ public function orWhereMorphDoesntHaveRelation($relation, $types, $column, $oper * Add a morph-to relationship condition to the query. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation - * @param \Illuminate\Database\Eloquent\Model|string|null $model + * @param \Illuminate\Database\Eloquent\Model|iterable|string|null $model * @return $this */ public function whereMorphedTo($relation, $model, $boolean = 'and') @@ -559,9 +559,19 @@ public function whereMorphedTo($relation, $model, $boolean = 'and') return $this->where($relation->qualifyColumn($relation->getMorphType()), $model, null, $boolean); } - return $this->where(function ($query) use ($relation, $model) { - $query->where($relation->qualifyColumn($relation->getMorphType()), $model->getMorphClass()) - ->where($relation->qualifyColumn($relation->getForeignKeyName()), $model->getKey()); + $models = BaseCollection::wrap($model); + + if ($models->isEmpty()) { + throw new InvalidArgumentException('Collection given to whereMorphedTo method may not be empty.'); + } + + return $this->where(function ($query) use ($relation, $models) { + $models->groupBy(fn ($model) => $model->getMorphClass())->each(function ($models) use ($query, $relation) { + $query->orWhere(function ($query) use ($relation, $models) { + $query->where($relation->qualifyColumn($relation->getMorphType()), $models->first()->getMorphClass()) + ->whereIn($relation->qualifyColumn($relation->getForeignKeyName()), $models->map->getKey()); + }); + }); }, null, null, $boolean); } @@ -569,7 +579,7 @@ public function whereMorphedTo($relation, $model, $boolean = 'and') * Add a not morph-to relationship condition to the query. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation - * @param \Illuminate\Database\Eloquent\Model|string $model + * @param \Illuminate\Database\Eloquent\Model|iterable|string $model * @return $this */ public function whereNotMorphedTo($relation, $model, $boolean = 'and') @@ -588,9 +598,19 @@ public function whereNotMorphedTo($relation, $model, $boolean = 'and') return $this->whereNot($relation->qualifyColumn($relation->getMorphType()), '<=>', $model, $boolean); } - return $this->whereNot(function ($query) use ($relation, $model) { - $query->where($relation->qualifyColumn($relation->getMorphType()), '<=>', $model->getMorphClass()) - ->where($relation->qualifyColumn($relation->getForeignKeyName()), '<=>', $model->getKey()); + $models = BaseCollection::wrap($model); + + if ($models->isEmpty()) { + throw new InvalidArgumentException('Collection given to whereNotMorphedTo method may not be empty.'); + } + + return $this->whereNot(function ($query) use ($relation, $models) { + $models->groupBy(fn ($model) => $model->getMorphClass())->each(function ($models) use ($query, $relation) { + $query->orWhere(function ($query) use ($relation, $models) { + $query->where($relation->qualifyColumn($relation->getMorphType()), '<=>', $models->first()->getMorphClass()) + ->whereNotIn($relation->qualifyColumn($relation->getForeignKeyName()), $models->map->getKey()); + }); + }); }, null, null, $boolean); } @@ -598,7 +618,7 @@ public function whereNotMorphedTo($relation, $model, $boolean = 'and') * Add a morph-to relationship condition to the query with an "or where" clause. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation - * @param \Illuminate\Database\Eloquent\Model|string|null $model + * @param \Illuminate\Database\Eloquent\Model|iterable|string|null $model * @return $this */ public function orWhereMorphedTo($relation, $model) @@ -610,7 +630,7 @@ public function orWhereMorphedTo($relation, $model) * Add a not morph-to relationship condition to the query with an "or where" clause. * * @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation - * @param \Illuminate\Database\Eloquent\Model|string $model + * @param \Illuminate\Database\Eloquent\Model|iterable|string $model * @return $this */ public function orWhereNotMorphedTo($relation, $model) diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 6ce852dd3f71..a84cd851eb0e 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -1774,10 +1774,47 @@ public function testWhereMorphedTo() $builder = $model->whereMorphedTo('morph', $relatedModel); - $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" = ?)', $builder->toSql()); + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql()); $this->assertEquals([$relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testWhereMorphedToCollection() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $secondRelatedModel->id = 2; + + $builder = $model->whereMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel])); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)))', $builder->toSql()); + $this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $secondRelatedModel->getKey()], $builder->getBindings()); + } + + public function testWhereMorphedToCollectionWithDifferentModels() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelFarRelatedStub; + $secondRelatedModel->id = 2; + + $thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $thirdRelatedModel->id = 3; + + $builder = $model->whereMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql()); + $this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings()); + } + public function testWhereMorphedToNull() { $model = new EloquentBuilderTestModelParentStub; @@ -1797,10 +1834,47 @@ public function testWhereNotMorphedTo() $builder = $model->whereNotMorphedTo('morph', $relatedModel); - $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" <=> ?)', $builder->toSql()); + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql()); $this->assertEquals([$relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testWhereNotMorphedToCollection() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $secondRelatedModel->id = 2; + + $builder = $model->whereNotMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel])); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)))', $builder->toSql()); + $this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $secondRelatedModel->getKey()], $builder->getBindings()); + } + + public function testWhereNotMorphedToCollectionWithDifferentModels() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelFarRelatedStub; + $secondRelatedModel->id = 2; + + $thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $thirdRelatedModel->id = 3; + + $builder = $model->whereNotMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql()); + $this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings()); + } + public function testOrWhereMorphedTo() { $model = new EloquentBuilderTestModelParentStub; @@ -1811,10 +1885,47 @@ public function testOrWhereMorphedTo() $builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', $relatedModel); - $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" = ?)', $builder->toSql()); + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql()); $this->assertEquals(['baz', $relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testOrWhereMorphedToCollection() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $secondRelatedModel->id = 2; + + $builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel])); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)))', $builder->toSql()); + $this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $secondRelatedModel->getKey()], $builder->getBindings()); + } + + public function testOrWhereMorphedToCollectionWithDifferentModels() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelFarRelatedStub; + $secondRelatedModel->id = 2; + + $thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $thirdRelatedModel->id = 3; + + $builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql()); + $this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings()); + } + public function testOrWhereMorphedToNull() { $model = new EloquentBuilderTestModelParentStub; @@ -1836,10 +1947,47 @@ public function testOrWhereNotMorphedTo() $builder = $model->where('bar', 'baz')->orWhereNotMorphedTo('morph', $relatedModel); - $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or not ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" <=> ?)', $builder->toSql()); + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql()); $this->assertEquals(['baz', $relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings()); } + public function testOrWhereNotMorphedToCollection() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $secondRelatedModel->id = 2; + + $builder = $model->where('bar', 'baz')->orWhereNotMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel])); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)))', $builder->toSql()); + $this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $secondRelatedModel->getKey()], $builder->getBindings()); + } + + public function testOrWhereNotMorphedToCollectionWithDifferentModels() + { + $model = new EloquentBuilderTestModelParentStub; + $this->mockConnectionForModel($model, ''); + + $firstRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $firstRelatedModel->id = 1; + + $secondRelatedModel = new EloquentBuilderTestModelFarRelatedStub; + $secondRelatedModel->id = 2; + + $thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub; + $thirdRelatedModel->id = 3; + + $builder = $model->where('bar', 'baz')->orWhereNotMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]); + + $this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql()); + $this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings()); + } + public function testWhereMorphedToClass() { $model = new EloquentBuilderTestModelParentStub; From 599a28196d284fee158cc10086fd56ac625ad7a3 Mon Sep 17 00:00:00 2001 From: taylorotwell <463230+taylorotwell@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:17:42 +0000 Subject: [PATCH 14/14] Update version to v11.40.0 --- src/Illuminate/Foundation/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 77bf7e2de6e1..cd91699f9f7e 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -45,7 +45,7 @@ class Application extends Container implements ApplicationContract, CachesConfig * * @var string */ - const VERSION = '11.39.1'; + const VERSION = '11.40.0'; /** * The base path for the Laravel installation.