diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index ee48d37daff0..8d58dc5d1202 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString; use Illuminate\Support\Traits\EnumeratesValues; use Illuminate\Support\Traits\Macroable; +use InvalidArgumentException; use stdClass; use Traversable; @@ -1166,17 +1167,27 @@ public function after($value, $strict = false) * * @param int $count * @return static|TValue|null + * + * @throws \InvalidArgumentException */ public function shift($count = 1) { - if ($count === 1) { - return array_shift($this->items); + if ($count < 0) { + throw new InvalidArgumentException('Number of shifted items may not be less than zero.'); } if ($this->isEmpty()) { + return null; + } + + if ($count === 0) { return new static; } + if ($count === 1) { + return array_shift($this->items); + } + $results = []; $collectionCount = $this->count(); diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 2713562fb162..a9b3cfcc4942 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -242,11 +242,13 @@ protected function commandIsolationMutex() */ protected function resolveCommand($command) { - if (! class_exists($command)) { - return $this->getApplication()->find($command); - } + if (is_string($command)) { + if (! class_exists($command)) { + return $this->getApplication()->find($command); + } - $command = $this->laravel->make($command); + $command = $this->laravel->make($command); + } if ($command instanceof SymfonyCommand) { $command->setApplication($this->getApplication()); diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 2514c18bd6c1..5bed2f003974 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -26,7 +26,9 @@ public function dump(Connection $connection, $path) $this->removeAutoIncrementingState($path); - $this->appendMigrationData($path); + if ($this->hasMigrationTable()) { + $this->appendMigrationData($path); + } } /** diff --git a/src/Illuminate/Database/Schema/PostgresSchemaState.php b/src/Illuminate/Database/Schema/PostgresSchemaState.php index b3f9361bc92b..70ccd25b5fd3 100644 --- a/src/Illuminate/Database/Schema/PostgresSchemaState.php +++ b/src/Illuminate/Database/Schema/PostgresSchemaState.php @@ -17,9 +17,12 @@ public function dump(Connection $connection, $path) { $commands = collect([ $this->baseDumpCommand().' --schema-only > '.$path, - $this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path, ]); + if ($this->hasMigrationTable()) { + $commands->push($this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path); + } + $commands->map(function ($command, $path) { $this->makeProcess($command)->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [ 'LARAVEL_LOAD_PATH' => $path, diff --git a/src/Illuminate/Database/Schema/SchemaState.php b/src/Illuminate/Database/Schema/SchemaState.php index c21f4ba762e4..2b2236af8801 100644 --- a/src/Illuminate/Database/Schema/SchemaState.php +++ b/src/Illuminate/Database/Schema/SchemaState.php @@ -94,6 +94,16 @@ public function makeProcess(...$arguments) return call_user_func($this->processFactory, ...$arguments); } + /** + * Determine if the current connection has a migration table. + * + * @return bool + */ + public function hasMigrationTable(): bool + { + return $this->connection->getSchemaBuilder()->hasTable($this->migrationTable); + } + /** * Specify the name of the application's migration table. * diff --git a/src/Illuminate/Database/Schema/SqliteSchemaState.php b/src/Illuminate/Database/Schema/SqliteSchemaState.php index 10efc7c0aba9..4b66542923e4 100644 --- a/src/Illuminate/Database/Schema/SqliteSchemaState.php +++ b/src/Illuminate/Database/Schema/SqliteSchemaState.php @@ -28,7 +28,9 @@ public function dump(Connection $connection, $path) $this->files->put($path, implode(PHP_EOL, $migrations).PHP_EOL); - $this->appendMigrationData($path); + if ($this->hasMigrationTable()) { + $this->appendMigrationData($path); + } } /** diff --git a/src/Illuminate/Mail/MailManager.php b/src/Illuminate/Mail/MailManager.php index ea530c83fe82..a9b72f419834 100644 --- a/src/Illuminate/Mail/MailManager.php +++ b/src/Illuminate/Mail/MailManager.php @@ -261,7 +261,7 @@ protected function createSesTransport(array $config) * Create an instance of the Symfony Amazon SES V2 Transport driver. * * @param array $config - * @return \Illuminate\Mail\Transport\Se2VwTransport + * @return \Illuminate\Mail\Transport\SesV2Transport */ protected function createSesV2Transport(array $config) { diff --git a/tests/Integration/Console/CallCommandsTest.php b/tests/Integration/Console/CallCommandsTest.php new file mode 100644 index 000000000000..4724b538aec1 --- /dev/null +++ b/tests/Integration/Console/CallCommandsTest.php @@ -0,0 +1,38 @@ +afterApplicationCreated(function () { + Artisan::command('test:a', function () { + $this->call('view:clear'); + }); + + Artisan::command('test:b', function () { + $this->call(ViewClearCommand::class); + }); + + Artisan::command('test:c', function () { + $this->call($this->laravel->make(ViewClearCommand::class)); + }); + }); + + parent::setUp(); + } + + #[TestWith(['test:a'])] + #[TestWith(['test:b'])] + #[TestWith(['test:c'])] + public function testItCanCallCommands(string $command) + { + $this->artisan($command)->assertSuccessful(); + } +} diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 0b1a0f6fcb67..c345699818ad 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -347,6 +347,34 @@ public function testShiftReturnsAndRemovesFirstXItemsInCollection() $this->assertSame('baz', $data->first()); $this->assertEquals(new Collection(['foo', 'bar', 'baz']), (new Collection(['foo', 'bar', 'baz']))->shift(6)); + + $data = new Collection(['foo', 'bar', 'baz']); + + $this->assertEquals(new Collection([]), $data->shift(0)); + $this->assertEquals(collect(['foo', 'bar', 'baz']), $data); + + $this->expectException('InvalidArgumentException'); + (new Collection(['foo', 'bar', 'baz']))->shift(-1); + + $this->expectException('InvalidArgumentException'); + (new Collection(['foo', 'bar', 'baz']))->shift(-2); + } + + public function testShiftReturnsNullOnEmptyCollection() + { + $itemFoo = new \stdClass(); + $itemFoo->text = 'f'; + $itemBar = new \stdClass(); + $itemBar->text = 'x'; + + $items = collect([$itemFoo, $itemBar]); + + $foo = $items->shift(); + $bar = $items->shift(); + + $this->assertSame('f', $foo?->text); + $this->assertSame('x', $bar?->text); + $this->assertNull($items->shift()); } #[DataProvider('collectionClassProvider')]