Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/8.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlindaruk committed Mar 29, 2022
2 parents 1bc1d8d + dffcec0 commit 7c185dd
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ protected function getSeconds($ttl)
$duration = Carbon::now()->diffInRealSeconds($duration, false);
}

return (int) $duration > 0 ? $duration : 0;
return (int) ($duration > 0 ? $duration : 0);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ public function nth($step, $offset = 0)

$position = 0;

foreach ($this->items as $item) {
if ($position % $step === $offset) {
foreach ($this->slice($offset)->items as $item) {
if ($position % $step === 0) {
$new[] = $item;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ public function nth($step, $offset = 0)
return new static(function () use ($step, $offset) {
$position = 0;

foreach ($this as $item) {
if ($position % $step === $offset) {
foreach ($this->slice($offset) as $item) {
if ($position % $step === 0) {
yield $item;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ protected function reconnectIfMissingConnection()
public function disconnect()
{
$this->setPdo(null)->setReadPdo(null);

$this->doctrineConnection = null;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ protected function handleLazyLoadingViolation($key)
return call_user_func(static::$lazyLoadingViolationCallback, $this, $key);
}

if (! $this->exists || $this->wasRecentlyCreated) {
return;
}

throw new LazyLoadingViolationException($this, $key);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ public static function preventLazyLoading($value = true)
/**
* Register a callback that is responsible for handling lazy loading violations.
*
* @param callable $callback
* @param callable|null $callback
* @return void
*/
public static function handleLazyLoadingViolationUsing(callable $callback)
public static function handleLazyLoadingViolationUsing(?callable $callback)
{
static::$lazyLoadingViolationCallback = $callback;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
*
* @var string
*/
const VERSION = '8.83.5';
const VERSION = '8.83.6';

/**
* The base path for the Laravel installation.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function bootstrap(Application $app)
// First we will see if we have a cache configuration file. If we do, we'll load
// the configuration items from that file so that it is very quick. Otherwise
// we will need to spin through every configuration file and load them all.
if (is_file($cached = $app->getCachedConfigPath())) {
if (file_exists($cached = $app->getCachedConfigPath())) {
$items = require $cached;

$loadedFromCache = true;
Expand Down
12 changes: 12 additions & 0 deletions tests/Encryption/EncrypterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ public function testExceptionThrownWhenPayloadIsInvalid()
$e->decrypt($payload);
}

public function testDecryptionExceptionIsThrownWhenUnexpectedTagIsAdded()
{
$this->expectException(DecryptException::class);
$this->expectExceptionMessage('Unable to use tag because the cipher algorithm does not support AEAD.');

$e = new Encrypter(str_repeat('a', 16));
$payload = $e->encrypt('foo');
$decodedPayload = json_decode(base64_decode($payload));
$decodedPayload->tag = 'set-manually';
$e->decrypt(base64_encode(json_encode($decodedPayload)));
}

public function testExceptionThrownWithDifferentKey()
{
$this->expectException(DecryptException::class);
Expand Down
30 changes: 30 additions & 0 deletions tests/Integration/Database/EloquentStrictLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public function testStrictModeWithCustomCallbackOnLazyLoading()
$models = EloquentStrictLoadingTestModel1::get();

$models[0]->modelTwos;

Model::handleLazyLoadingViolationUsing(null);
}

public function testStrictModeWithOverriddenHandlerOnLazyLoading()
Expand All @@ -141,6 +143,21 @@ public function testStrictModeWithOverriddenHandlerOnLazyLoading()

$models[0]->modelTwos;
}

public function testStrictModeDoesntThrowAnExceptionOnManuallyMadeModel()
{
$model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::make();
$model2 = EloquentStrictLoadingTestModel2::make();
$model1->modelTwos->push($model2);

$this->assertInstanceOf(Collection::class, $model1->modelTwos);
}

public function testStrictModeDoesntThrowAnExceptionOnRecentlyCreatedModel()
{
$model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::create();
$this->assertInstanceOf(Collection::class, $model1->modelTwos);
}
}

class EloquentStrictLoadingTestModel1 extends Model
Expand Down Expand Up @@ -172,6 +189,19 @@ protected function handleLazyLoadingViolation($key)
}
}

class EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading extends Model
{
public $table = 'test_model1';
public $timestamps = false;
public $preventsLazyLoading = true;
protected $guarded = [];

public function modelTwos()
{
return $this->hasMany(EloquentStrictLoadingTestModel2::class, 'model_1_id');
}
}

class EloquentStrictLoadingTestModel2 extends Model
{
public $table = 'test_model2';
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,8 @@ public function testNth($collection)
$this->assertEquals(['b', 'f'], $data->nth(4, 1)->all());
$this->assertEquals(['c'], $data->nth(4, 2)->all());
$this->assertEquals(['d'], $data->nth(4, 3)->all());
$this->assertEquals(['c', 'e'], $data->nth(2, 2)->all());
$this->assertEquals(['c', 'd', 'e', 'f'], $data->nth(1, 2)->all());
}

/**
Expand Down

0 comments on commit 7c185dd

Please sign in to comment.