Skip to content

Commit

Permalink
Modernize the LostControllerTest test
Browse files Browse the repository at this point in the history
Remove some depreciated at() calls

Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Mar 21, 2022
1 parent 0495ca9 commit b0a7991
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions tests/Core/Controller/LostControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
* @package OC\Core\Controller
*/
class LostControllerTest extends TestCase {

/** @var LostController */
private $lostController;
private LostController $lostController;
/** @var IUser */
private $existingUser;
/** @var IURLGenerator | MockObject */
Expand Down Expand Up @@ -117,18 +115,12 @@ protected function setUp(): void {
->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
});
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
->disableOriginalConstructor()->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
->disableOriginalConstructor()->getMock();
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
->disableOriginalConstructor()->getMock();
$this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()->getMock();
$this->encryptionManager = $this->getMockBuilder(IManager::class)
->disableOriginalConstructor()->getMock();
$this->defaults = $this->createMock(Defaults::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->mailer = $this->createMock(IMailer::class);
$this->request = $this->createMock(IRequest::class);
$this->encryptionManager = $this->createMock(IManager::class);
$this->encryptionManager->expects($this->any())
->method('isEnabled')
->willReturn(true);
Expand Down Expand Up @@ -252,11 +244,11 @@ public function testEmailSuccessful() {
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();
$message
->expects($this->at(0))
->expects($this->once())
->method('setTo')
->with(['[email protected]' => 'Existing User']);
$message
->expects($this->at(1))
->expects($this->once())
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);

Expand All @@ -269,20 +261,20 @@ public function testEmailSuccessful() {
->willReturn('text body');

$message
->expects($this->at(2))
->expects($this->once())
->method('useTemplate')
->with($emailTemplate);

$this->mailer
->expects($this->at(0))
->expects($this->once())
->method('createEMailTemplate')
->willReturn($emailTemplate);
$this->mailer
->expects($this->at(1))
->expects($this->once())
->method('createMessage')
->willReturn($message);
$this->mailer
->expects($this->at(2))
->expects($this->once())
->method('send')
->with($message);

Expand Down Expand Up @@ -314,11 +306,11 @@ public function testEmailWithMailSuccessful() {
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();
$message
->expects($this->at(0))
->expects($this->once())
->method('setTo')
->with(['[email protected]' => 'Existing User']);
$message
->expects($this->at(1))
->expects($this->once())
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);

Expand All @@ -331,20 +323,20 @@ public function testEmailWithMailSuccessful() {
->willReturn('text body');

$message
->expects($this->at(2))
->expects($this->once())
->method('useTemplate')
->with($emailTemplate);

$this->mailer
->expects($this->at(0))
->expects($this->once())
->method('createEMailTemplate')
->willReturn($emailTemplate);
$this->mailer
->expects($this->at(1))
->expects($this->once())
->method('createMessage')
->willReturn($message);
$this->mailer
->expects($this->at(2))
->expects($this->once())
->method('send')
->with($message);

Expand All @@ -370,11 +362,11 @@ public function testEmailCantSendException() {
->willReturn('https://example.tld/index.php/lostpassword/');
$message = $this->createMock(Message::class);
$message
->expects($this->at(0))
->expects($this->once())
->method('setTo')
->with(['[email protected]' => 'Existing User']);
$message
->expects($this->at(1))
->expects($this->once())
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);

Expand All @@ -387,20 +379,20 @@ public function testEmailCantSendException() {
->willReturn('text body');

$message
->expects($this->at(2))
->expects($this->once())
->method('useTemplate')
->with($emailTemplate);

$this->mailer
->expects($this->at(0))
->expects($this->once())
->method('createEMailTemplate')
->willReturn($emailTemplate);
$this->mailer
->expects($this->at(1))
->expects($this->once())
->method('createMessage')
->willReturn($message);
$this->mailer
->expects($this->at(2))
->expects($this->once())
->method('send')
->with($message)
->will($this->throwException(new \Exception()));
Expand Down

0 comments on commit b0a7991

Please sign in to comment.