Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Sep 8, 2021
2 parents 9ee0a4b + d73de59 commit 05bba7c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/Illuminate/Auth/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,20 @@ public function via($notifiable)
*/
public function toMail($notifiable)
{
$url = $this->resetUrl($notifiable);

if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token, $url);
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}

return $this->buildMailMessage($url);
}

/**
* Get the password reset URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function resetUrl($notifiable)
{
if (static::$createUrlCallback) {
return call_user_func(static::$createUrlCallback, $notifiable, $this->token);
$url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
} else {
return url(route('password.reset', [
$url = url(route('password.reset', [
'token' => $this->token,
'email' => $notifiable->getEmailForPasswordReset(),
], false));
}

return $this->buildMailMessage($url);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,19 @@ public function value($column)
}
}

/**
* Get a single column's value from the first result of the query or throw an exception.
*
* @param string|\Illuminate\Database\Query\Expression $column
* @return mixed
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function valueOrFail($column)
{
return $this->firstOrFail([$column])->{Str::afterLast($column, '.')};
}

/**
* Execute the query as a "select" statement.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,29 @@ public function testValueMethodWithModelNotFound()
$this->assertNull($builder->value('name'));
}

public function testValueOrFailMethodWithModelFound()
{
$builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]);
$mockModel = new stdClass;
$mockModel->name = 'foo';
$builder->shouldReceive('first')->with(['name'])->andReturn($mockModel);

$this->assertSame('foo', $builder->valueOrFail('name'));
}

public function testValueOrFailMethodWithModelNotFoundThrowsModelNotFoundException()
{
$this->expectException(ModelNotFoundException::class);

$builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]);
$model = $this->getMockModel();
$model->shouldReceive('getKeyType')->once()->andReturn('int');
$builder->setModel($model);
$builder->getQuery()->shouldReceive('where')->once()->with('foo_table.foo', '=', 'bar');
$builder->shouldReceive('first')->with(['column'])->andReturn(null);
$builder->whereKey('bar')->valueOrFail('column');
}

public function testChunkWithLastChunkComplete()
{
$builder = m::mock(Builder::class.'[forPage,get]', [$this->getMockQueryBuilder()]);
Expand Down

0 comments on commit 05bba7c

Please sign in to comment.