Skip to content

Commit 1ca3acf

Browse files
committed
Merge branch '10.x' into 11.x
# Conflicts: # CHANGELOG.md # src/Illuminate/Foundation/Application.php
2 parents 5104bce + 35f07d3 commit 1ca3acf

File tree

9 files changed

+106
-10
lines changed

9 files changed

+106
-10
lines changed

src/Illuminate/Collections/Collection.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
88
use Illuminate\Support\Traits\EnumeratesValues;
99
use Illuminate\Support\Traits\Macroable;
10+
use InvalidArgumentException;
1011
use stdClass;
1112
use Traversable;
1213

@@ -1166,17 +1167,27 @@ public function after($value, $strict = false)
11661167
*
11671168
* @param int $count
11681169
* @return static<int, TValue>|TValue|null
1170+
*
1171+
* @throws \InvalidArgumentException
11691172
*/
11701173
public function shift($count = 1)
11711174
{
1172-
if ($count === 1) {
1173-
return array_shift($this->items);
1175+
if ($count < 0) {
1176+
throw new InvalidArgumentException('Number of shifted items may not be less than zero.');
11741177
}
11751178

11761179
if ($this->isEmpty()) {
1180+
return null;
1181+
}
1182+
1183+
if ($count === 0) {
11771184
return new static;
11781185
}
11791186

1187+
if ($count === 1) {
1188+
return array_shift($this->items);
1189+
}
1190+
11801191
$results = [];
11811192

11821193
$collectionCount = $this->count();

src/Illuminate/Console/Command.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,13 @@ protected function commandIsolationMutex()
242242
*/
243243
protected function resolveCommand($command)
244244
{
245-
if (! class_exists($command)) {
246-
return $this->getApplication()->find($command);
247-
}
245+
if (is_string($command)) {
246+
if (! class_exists($command)) {
247+
return $this->getApplication()->find($command);
248+
}
248249

249-
$command = $this->laravel->make($command);
250+
$command = $this->laravel->make($command);
251+
}
250252

251253
if ($command instanceof SymfonyCommand) {
252254
$command->setApplication($this->getApplication());

src/Illuminate/Database/Schema/MySqlSchemaState.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function dump(Connection $connection, $path)
2626

2727
$this->removeAutoIncrementingState($path);
2828

29-
$this->appendMigrationData($path);
29+
if ($this->hasMigrationTable()) {
30+
$this->appendMigrationData($path);
31+
}
3032
}
3133

3234
/**

src/Illuminate/Database/Schema/PostgresSchemaState.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public function dump(Connection $connection, $path)
1717
{
1818
$commands = collect([
1919
$this->baseDumpCommand().' --schema-only > '.$path,
20-
$this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path,
2120
]);
2221

22+
if ($this->hasMigrationTable()) {
23+
$commands->push($this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path);
24+
}
25+
2326
$commands->map(function ($command, $path) {
2427
$this->makeProcess($command)->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [
2528
'LARAVEL_LOAD_PATH' => $path,

src/Illuminate/Database/Schema/SchemaState.php

+10
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public function makeProcess(...$arguments)
9494
return call_user_func($this->processFactory, ...$arguments);
9595
}
9696

97+
/**
98+
* Determine if the current connection has a migration table.
99+
*
100+
* @return bool
101+
*/
102+
public function hasMigrationTable(): bool
103+
{
104+
return $this->connection->getSchemaBuilder()->hasTable($this->migrationTable);
105+
}
106+
97107
/**
98108
* Specify the name of the application's migration table.
99109
*

src/Illuminate/Database/Schema/SqliteSchemaState.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function dump(Connection $connection, $path)
2828

2929
$this->files->put($path, implode(PHP_EOL, $migrations).PHP_EOL);
3030

31-
$this->appendMigrationData($path);
31+
if ($this->hasMigrationTable()) {
32+
$this->appendMigrationData($path);
33+
}
3234
}
3335

3436
/**

src/Illuminate/Mail/MailManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected function createSesTransport(array $config)
261261
* Create an instance of the Symfony Amazon SES V2 Transport driver.
262262
*
263263
* @param array $config
264-
* @return \Illuminate\Mail\Transport\Se2VwTransport
264+
* @return \Illuminate\Mail\Transport\SesV2Transport
265265
*/
266266
protected function createSesV2Transport(array $config)
267267
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Console;
4+
5+
use Illuminate\Foundation\Console\ViewClearCommand;
6+
use Illuminate\Support\Facades\Artisan;
7+
use Orchestra\Testbench\TestCase;
8+
use PHPUnit\Framework\Attributes\TestWith;
9+
10+
class CallCommandsTest extends TestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
$this->afterApplicationCreated(function () {
15+
Artisan::command('test:a', function () {
16+
$this->call('view:clear');
17+
});
18+
19+
Artisan::command('test:b', function () {
20+
$this->call(ViewClearCommand::class);
21+
});
22+
23+
Artisan::command('test:c', function () {
24+
$this->call($this->laravel->make(ViewClearCommand::class));
25+
});
26+
});
27+
28+
parent::setUp();
29+
}
30+
31+
#[TestWith(['test:a'])]
32+
#[TestWith(['test:b'])]
33+
#[TestWith(['test:c'])]
34+
public function testItCanCallCommands(string $command)
35+
{
36+
$this->artisan($command)->assertSuccessful();
37+
}
38+
}

tests/Support/SupportCollectionTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,34 @@ public function testShiftReturnsAndRemovesFirstXItemsInCollection()
347347
$this->assertSame('baz', $data->first());
348348

349349
$this->assertEquals(new Collection(['foo', 'bar', 'baz']), (new Collection(['foo', 'bar', 'baz']))->shift(6));
350+
351+
$data = new Collection(['foo', 'bar', 'baz']);
352+
353+
$this->assertEquals(new Collection([]), $data->shift(0));
354+
$this->assertEquals(collect(['foo', 'bar', 'baz']), $data);
355+
356+
$this->expectException('InvalidArgumentException');
357+
(new Collection(['foo', 'bar', 'baz']))->shift(-1);
358+
359+
$this->expectException('InvalidArgumentException');
360+
(new Collection(['foo', 'bar', 'baz']))->shift(-2);
361+
}
362+
363+
public function testShiftReturnsNullOnEmptyCollection()
364+
{
365+
$itemFoo = new \stdClass();
366+
$itemFoo->text = 'f';
367+
$itemBar = new \stdClass();
368+
$itemBar->text = 'x';
369+
370+
$items = collect([$itemFoo, $itemBar]);
371+
372+
$foo = $items->shift();
373+
$bar = $items->shift();
374+
375+
$this->assertSame('f', $foo?->text);
376+
$this->assertSame('x', $bar?->text);
377+
$this->assertNull($items->shift());
350378
}
351379

352380
#[DataProvider('collectionClassProvider')]

0 commit comments

Comments
 (0)