Skip to content

Commit

Permalink
Merge branch '10.x' into 11.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/Illuminate/Foundation/Application.php
  • Loading branch information
driesvints committed Jun 21, 2024
2 parents 5104bce + 35f07d3 commit 1ca3acf
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1166,17 +1167,27 @@ public function after($value, $strict = false)
*
* @param int $count
* @return static<int, TValue>|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();
Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function dump(Connection $connection, $path)

$this->removeAutoIncrementingState($path);

$this->appendMigrationData($path);
if ($this->hasMigrationTable()) {
$this->appendMigrationData($path);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Database/Schema/PostgresSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Schema/SchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/SqliteSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
38 changes: 38 additions & 0 deletions tests/Integration/Console/CallCommandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Illuminate\Tests\Integration\Console;

use Illuminate\Foundation\Console\ViewClearCommand;
use Illuminate\Support\Facades\Artisan;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\TestWith;

class CallCommandsTest extends TestCase
{
protected function setUp(): void
{
$this->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();
}
}
28 changes: 28 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down

0 comments on commit 1ca3acf

Please sign in to comment.