Skip to content

Commit

Permalink
Merge branch '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 Apr 30, 2024
2 parents 5c57ac1 + a57dca1 commit 4228a4b
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 19 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

outputs:
version: ${{ steps.version.outputs.version }}
notes: ${{ steps.cleaned-notes.outputs.release-notes }}
notes: ${{ steps.cleaned-notes.outputs.notes }}

steps:
- name: Checkout repository
Expand Down Expand Up @@ -90,10 +90,11 @@ jobs:
- name: Cleanup release notes
id: cleaned-notes
run: |
NOTES="${{ steps.generated-notes.outputs.release-notes }}"
NOTES=$(echo $NOTES | sed '/## What/d')
NOTES=$(echo $NOTES | sed '/## New Contributors/,$d')
echo "release-notes=${NOTES}" >> "$GITHUB_OUTPUT"
RELEASE_NOTES=$(echo $RELEASE_NOTES | sed '/## What/d')
RELEASE_NOTES=$(echo $RELEASE_NOTES | sed '/## New Contributors/,$d')
echo "notes=${RELEASE_NOTES}" >> "$GITHUB_OUTPUT"
env:
RELEASE_NOTES: ${{ steps.generated-notes.outputs.release-notes }}

- name: Create release
uses: softprops/action-gh-release@v2
Expand All @@ -102,7 +103,7 @@ jobs:
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body: ${{ steps.cleaned-notes.outputs.release-notes }}
body: ${{ steps.cleaned-notes.outputs.notes }}
target_commitish: ${{ github.ref_name }}
make_latest: 'legacy'

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Database/DetectsLostConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function causedByLostConnection(Throwable $e)

return Str::contains($message, [
'server has gone away',
'Server has gone away',
'no connection to the server',
'Lost connection',
'is dead or not enabled',
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public function createOneQuietly($attributes = [])
*/
public function createMany(int|iterable|null $records = null)
{
if (is_null($records)) {
$records = $this->count ?? 1;
}
$records ??= ($this->count ?? 1);

$this->count = null;

if (is_numeric($records)) {
$records = array_fill(0, $records, []);
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public function findOr($id, $columns = ['*'], ?Closure $callback = null)
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Model|static
* @return \Illuminate\Database\Eloquent\Model|static|null
*/
public function firstWhere($column, $operator = null, $value = null, $boolean = 'and')
{
Expand All @@ -795,7 +795,7 @@ public function firstWhere($column, $operator = null, $value = null, $boolean =
* Execute the query and get the first result.
*
* @param array $columns
* @return mixed
* @return \Illuminate\Database\Eloquent\Model|static|null
*/
public function first($columns = ['*'])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function updateOrCreate(array $attributes, array $values = [])
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Model|static
* @return \Illuminate\Database\Eloquent\Model|static|null
*/
public function firstWhere($column, $operator = null, $value = null, $boolean = 'and')
{
Expand All @@ -331,7 +331,7 @@ public function firstWhere($column, $operator = null, $value = null, $boolean =
* Execute the query and get the first related model.
*
* @param array $columns
* @return mixed
* @return \Illuminate\Database\Eloquent\Model|static|null
*/
public function first($columns = ['*'])
{
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ public function storagePath($path = '')
return $this->joinPaths($this->storagePath ?: $_ENV['LARAVEL_STORAGE_PATH'], $path);
}

if (isset($_SERVER['LARAVEL_STORAGE_PATH'])) {
return $this->joinPaths($this->storagePath ?: $_SERVER['LARAVEL_STORAGE_PATH'], $path);
}

return $this->joinPaths($this->storagePath ?: $this->basePath('storage'), $path);
}

Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ protected function makeReplacements($line, array $replace)
$shouldReplace = [];

foreach ($replace as $key => $value) {
if ($value instanceof Closure) {
$line = preg_replace_callback(
'/<'.$key.'>(.*?)<\/'.$key.'>/',
fn ($args) => $value($args[1]),
$line
);

continue;
}

if (is_object($value) && isset($this->stringableHandlers[get_class($value)])) {
$value = call_user_func($this->stringableHandlers[get_class($value)], $value);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,30 @@ public function test_basic_model_can_be_created()
$users = FactoryTestUserFactory::new()->createMany(2);
$this->assertInstanceOf(Collection::class, $users);
$this->assertCount(2, $users);
$this->assertInstanceOf(FactoryTestUser::class, $users->first());

$users = FactoryTestUserFactory::times(2)->createMany();
$this->assertInstanceOf(Collection::class, $users);
$this->assertCount(2, $users);
$this->assertInstanceOf(FactoryTestUser::class, $users->first());

$users = FactoryTestUserFactory::times(2)->createMany();
$this->assertInstanceOf(Collection::class, $users);
$this->assertCount(2, $users);
$this->assertInstanceOf(FactoryTestUser::class, $users->first());

$users = FactoryTestUserFactory::times(3)->createMany([
['name' => 'Taylor Otwell'],
['name' => 'Jeffrey Way'],
]);
$this->assertInstanceOf(Collection::class, $users);
$this->assertCount(2, $users);
$this->assertInstanceOf(FactoryTestUser::class, $users->first());

$users = FactoryTestUserFactory::new()->createMany();
$this->assertInstanceOf(Collection::class, $users);
$this->assertCount(1, $users);
$this->assertInstanceOf(FactoryTestUser::class, $users->first());

$users = FactoryTestUserFactory::times(10)->create();
$this->assertCount(10, $users);
Expand Down
6 changes: 3 additions & 3 deletions tests/Routing/RoutingUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public function testSignedUrl()

$this->assertTrue($url->hasValidSignature($request));

$request = Request::create($url->signedRoute('foo').'?tempered=true');
$request = Request::create($url->signedRoute('foo').'?tampered=true');

$this->assertFalse($url->hasValidSignature($request));
}
Expand Down Expand Up @@ -827,7 +827,7 @@ public function testSignedRelativeUrl()

$this->assertTrue($url->hasValidSignature($request, false));

$request = Request::create($url->signedRoute('foo', [], null, false).'?tempered=true');
$request = Request::create($url->signedRoute('foo', [], null, false).'?tampered=true');

$this->assertFalse($url->hasValidSignature($request, false));
}
Expand Down Expand Up @@ -906,7 +906,7 @@ public function testSignedUrlWithKeyResolver()

$this->assertTrue($url->hasValidSignature($request));

$request = Request::create($url->signedRoute('foo').'?tempered=true');
$request = Request::create($url->signedRoute('foo').'?tampered=true');

$this->assertFalse($url->hasValidSignature($request));

Expand Down
14 changes: 11 additions & 3 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

class SupportStrTest extends TestCase
{
public function testStringCanBeLimitedByWords()
public function testStringCanBeLimitedByWords(): void
{
$this->assertSame('Taylor...', Str::words('Taylor Otwell', 1));
$this->assertSame('Taylor___', Str::words('Taylor Otwell', 1, '___'));
$this->assertSame('Taylor Otwell', Str::words('Taylor Otwell', 3));
$this->assertSame('Taylor Otwell', Str::words('Taylor Otwell', -1, '...'));
$this->assertSame('', Str::words('', 3, '...'));
}

public function testStringCanBeLimitedByWordsNonAscii()
Expand Down Expand Up @@ -114,11 +116,13 @@ public function testStringApa()
$this->assertSame(' ', Str::apa(' '));
}

public function testStringWithoutWordsDoesntProduceError()
public function testStringWithoutWordsDoesntProduceError(): void
{
$nbsp = chr(0xC2).chr(0xA0);
$this->assertSame(' ', Str::words(' '));
$this->assertEquals($nbsp, Str::words($nbsp));
$this->assertSame(' ', Str::words(' '));
$this->assertSame("\t\t\t", Str::words("\t\t\t"));
}

public function testStringAscii()
Expand Down Expand Up @@ -265,7 +269,7 @@ public function testStrBefore()
$this->assertSame('han', Str::before('han2nah', 2));
}

public function testStrBeforeLast()
public function testStrBeforeLast(): void
{
$this->assertSame('yve', Str::beforeLast('yvette', 'tte'));
$this->assertSame('yvet', Str::beforeLast('yvette', 't'));
Expand All @@ -276,6 +280,10 @@ public function testStrBeforeLast()
$this->assertSame('yv0et', Str::beforeLast('yv0et0te', '0'));
$this->assertSame('yv0et', Str::beforeLast('yv0et0te', 0));
$this->assertSame('yv2et', Str::beforeLast('yv2et2te', 2));
$this->assertSame('', Str::beforeLast('', 'test'));
$this->assertSame('', Str::beforeLast('yvette', 'yvette'));
$this->assertSame('laravel', Str::beforeLast('laravel framework', ' '));
$this->assertSame('yvette', Str::beforeLast("yvette\tyv0et0te", "\t"));
}

public function testStrBetween()
Expand Down
36 changes: 36 additions & 0 deletions tests/Translation/TranslationTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,42 @@ public function testGetJsonReplacesWithStringable()
);
}

public function testTagReplacements()
{
$t = new Translator($this->getLoader(), 'en');

$t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'We have some nice <docs-link>documentation</docs-link>', '*')->andReturn([]);

$this->assertSame(
'We have some nice <a href="https://laravel.com/docs">documentation</a>',
$t->get(
'We have some nice <docs-link>documentation</docs-link>',
[
'docs-link' => fn ($children) => "<a href=\"https://laravel.com/docs\">$children</a>",
]
)
);
}

public function testTagReplacementsHandleMultipleOfSameTag()
{
$t = new Translator($this->getLoader(), 'en');

$t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
$t->getLoader()->shouldReceive('load')->once()->with('en', '<bold-this>bold</bold-this> something else <bold-this>also bold</bold-this>', '*')->andReturn([]);

$this->assertSame(
'<b>bold</b> something else <b>also bold</b>',
$t->get(
'<bold-this>bold</bold-this> something else <bold-this>also bold</bold-this>',
[
'bold-this' => fn ($children) => "<b>$children</b>",
]
)
);
}

public function testDetermineLocalesUsingMethod()
{
$t = new Translator($this->getLoader(), 'en');
Expand Down

0 comments on commit 4228a4b

Please sign in to comment.