Skip to content

Commit dddc27f

Browse files
committed
Merge branch '8.x' into 9.x
# Conflicts: # tests/Integration/Database/EloquentStrictLoadingTest.php
2 parents ba14364 + 888947c commit dddc27f

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ protected function handleLazyLoadingViolation($key)
520520
return call_user_func(static::$lazyLoadingViolationCallback, $this, $key);
521521
}
522522

523+
if (! $this->exists || $this->wasRecentlyCreated) {
524+
return;
525+
}
526+
523527
throw new LazyLoadingViolationException($this, $key);
524528
}
525529

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ public static function preventLazyLoading($value = true)
384384
/**
385385
* Register a callback that is responsible for handling lazy loading violations.
386386
*
387-
* @param callable $callback
387+
* @param callable|null $callback
388388
* @return void
389389
*/
390-
public static function handleLazyLoadingViolationUsing(callable $callback)
390+
public static function handleLazyLoadingViolationUsing(?callable $callback)
391391
{
392392
static::$lazyLoadingViolationCallback = $callback;
393393
}

tests/Encryption/EncrypterTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ public function testExceptionThrownWhenPayloadIsInvalid()
160160
$e->decrypt($payload);
161161
}
162162

163+
public function testDecryptionExceptionIsThrownWhenUnexpectedTagIsAdded()
164+
{
165+
$this->expectException(DecryptException::class);
166+
$this->expectExceptionMessage('Unable to use tag because the cipher algorithm does not support AEAD.');
167+
168+
$e = new Encrypter(str_repeat('a', 16));
169+
$payload = $e->encrypt('foo');
170+
$decodedPayload = json_decode(base64_decode($payload));
171+
$decodedPayload->tag = 'set-manually';
172+
$e->decrypt(base64_encode(json_encode($decodedPayload)));
173+
}
174+
163175
public function testExceptionThrownWithDifferentKey()
164176
{
165177
$this->expectException(DecryptException::class);

tests/Integration/Database/EloquentStrictLoadingTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ public function testStrictModeWithOverriddenHandlerOnLazyLoading()
145145

146146
$models[0]->modelTwos;
147147
}
148+
149+
public function testStrictModeDoesntThrowAnExceptionOnManuallyMadeModel()
150+
{
151+
$model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::make();
152+
$model2 = EloquentStrictLoadingTestModel2::make();
153+
$model1->modelTwos->push($model2);
154+
155+
$this->assertInstanceOf(Collection::class, $model1->modelTwos);
156+
}
157+
158+
public function testStrictModeDoesntThrowAnExceptionOnRecentlyCreatedModel()
159+
{
160+
$model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::create();
161+
$this->assertInstanceOf(Collection::class, $model1->modelTwos);
162+
}
148163
}
149164

150165
class EloquentStrictLoadingTestModel1 extends Model
@@ -176,6 +191,19 @@ protected function handleLazyLoadingViolation($key)
176191
}
177192
}
178193

194+
class EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading extends Model
195+
{
196+
public $table = 'test_model1';
197+
public $timestamps = false;
198+
public $preventsLazyLoading = true;
199+
protected $guarded = [];
200+
201+
public function modelTwos()
202+
{
203+
return $this->hasMany(EloquentStrictLoadingTestModel2::class, 'model_1_id');
204+
}
205+
}
206+
179207
class EloquentStrictLoadingTestModel2 extends Model
180208
{
181209
public $table = 'test_model2';

0 commit comments

Comments
 (0)