Fix test coverage.

This commit is contained in:
James Cole 2018-08-24 21:14:17 +02:00
parent 20490fcd80
commit 29a81eb05e
4 changed files with 55 additions and 6 deletions

View File

@ -141,9 +141,11 @@ class UserEventHandler
$uri = route('profile.confirm-email-change', [$token->data]);
try {
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}
@ -165,9 +167,11 @@ class UserEventHandler
$uri = route('profile.undo-email-change', [$token->data, hash('sha256', $oldEmail)]);
try {
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}
@ -190,9 +194,11 @@ class UserEventHandler
// send email.
try {
Mail::to($email)->send(new RequestedNewPasswordMail($url, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}
@ -217,9 +223,11 @@ class UserEventHandler
// send email.
try {
Mail::to($email)->send(new RegisteredUserMail($uri, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
}
return true;

View File

@ -271,6 +271,7 @@ class SplitControllerTest extends TestCase
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
@ -368,6 +369,7 @@ class SplitControllerTest extends TestCase
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
@ -424,6 +426,7 @@ class SplitControllerTest extends TestCase
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);

View File

@ -34,9 +34,10 @@ use FireflyIII\Models\Role;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Mail;
use Mockery;
use Tests\TestCase;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class UserEventHandlerTest
@ -151,6 +152,26 @@ class UserEventHandlerTest extends TestCase
$this->assertTrue(true);
}
/**
* @covers \FireflyIII\Handlers\Events\UserEventHandler
*/
public function testDemoUserBackToEnglish(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$user = $this->emptyUser();
$event = new Login($user, true);
$listener = new UserEventHandler();
// mock stuff
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(true);
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->once();
Preferences::shouldReceive('mark')->once();
$listener->demoUserBackToEnglish($event);
$this->assertTrue(true);
}
/**
* @covers \FireflyIII\Handlers\Events\UserEventHandler
* @covers \FireflyIII\Events\UserChangedEmail

View File

@ -32,9 +32,9 @@ use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Services\Github\Object\Release;
use FireflyIII\Services\Github\Request\UpdateRequest;
use Log;
use Mockery;
use Tests\TestCase;
use Log;
/**
* Class VersionCheckEventHandlerTest
@ -52,7 +52,8 @@ class VersionCheckEventHandlerTest extends TestCase
/**
*
* @covers \FireflyIII\Events\RequestedVersionCheckStatus
* @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
*/
public function testCheckForUpdatesError(): void
{
@ -114,7 +115,8 @@ class VersionCheckEventHandlerTest extends TestCase
}
/**
*
* @covers \FireflyIII\Events\RequestedVersionCheckStatus
* @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
*/
public function testCheckForUpdatesNoAdmin(): void
{
@ -156,7 +158,22 @@ class VersionCheckEventHandlerTest extends TestCase
}
/**
*
* @covers \FireflyIII\Events\RequestedVersionCheckStatus
* @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
*/
public function testCheckForUpdatesSandstorm(): void
{
putenv('SANDSTORM=1');
$event = new RequestedVersionCheckStatus($this->user());
$handler = new VersionCheckEventHandler;
$handler->checkForUpdates($event);
putenv('SANDSTORM=0');
}
/**
* @covers \FireflyIII\Events\RequestedVersionCheckStatus
* @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
*/
public function testCheckForUpdatesTooRecent(): void
{