Code cleanup.

This commit is contained in:
James Cole
2018-04-02 14:17:11 +02:00
parent 4cea5d65a6
commit f96f38b172
44 changed files with 87 additions and 100 deletions

View File

@@ -2395,7 +2395,7 @@ class TransactionControllerTest extends TestCase
'description' => 'Some transaction #' . random_int(1, 1000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'tags' => join(',', $tags),
'tags' => implode(',', $tags),
'transactions' => [
[
'amount' => '10',

View File

@@ -370,7 +370,7 @@ class ProfileControllerTest extends TestCase
{
$token = '';
$currentToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
if (!is_null($currentToken)) {
if (null !== $currentToken) {
$token = $currentToken->data;
}
$this->be($this->user());

View File

@@ -97,7 +97,7 @@ class BulkControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$route = route('transactions.bulk.edit', implode(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);
@@ -133,7 +133,7 @@ class BulkControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$route = route('transactions.bulk.edit', implode(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);

View File

@@ -162,7 +162,7 @@ class MassControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.mass.edit', join(',', $allIds));
$route = route('transactions.mass.edit', implode(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);
@@ -204,7 +204,7 @@ class MassControllerTest extends TestCase
$allIds = $collection->pluck('id')->toArray();
$this->be($this->user());
$response = $this->get(route('transactions.mass.edit', join(',', $allIds)));
$response = $this->get(route('transactions.mass.edit', implode(',', $allIds)));
$response->assertStatus(200);
$response->assertSee('Edit a number of transactions');
$response->assertSessionHas('error', 'You have selected no valid transactions to edit.');

View File

@@ -99,9 +99,7 @@ abstract class TestCase extends BaseTestCase
*/
public function demoUser(): User
{
$user = User::find(4);
return $user;
return User::find(4);
}
/**
@@ -109,9 +107,7 @@ abstract class TestCase extends BaseTestCase
*/
public function emptyUser(): User
{
$user = User::find(2);
return $user;
return User::find(2);
}
/**
@@ -119,9 +115,7 @@ abstract class TestCase extends BaseTestCase
*/
public function user(): User
{
$user = User::find(1);
return $user;
return User::find(1);
}
/**
@@ -145,10 +139,8 @@ abstract class TestCase extends BaseTestCase
*/
protected function overload(string $class)
{
$externalMock = Mockery::mock('overload:' . $class);
//$this->app->instance($class, $externalMock);
return $externalMock;
return Mockery::mock('overload:' . $class);
}
/**

View File

@@ -212,7 +212,7 @@ class AccountFactoryTest extends TestCase
// find opening balance:
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(100, floatval($account->transactions()->first()->amount));
$this->assertEquals(100, (float)$account->transactions()->first()->amount);
}
/**
@@ -361,7 +361,7 @@ class AccountFactoryTest extends TestCase
// find opening balance:
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(-100, floatval($account->transactions()->first()->amount));
$this->assertEquals(-100, (float)$account->transactions()->first()->amount);
}
/**

View File

@@ -45,7 +45,7 @@ class AttachmentHelperTest extends TestCase
{
$attachment = Attachment::first();
$helper = new AttachmentHelper;
$path = $path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, intval($attachment->id));
$path = $path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, (int)$attachment->id);
$this->assertEquals($helper->getAttachmentLocation($attachment), $path);
}

View File

@@ -57,7 +57,7 @@ class AssetAccountIbansTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
53 => 'Else',
17 => 'IBAN (Something)',
];

View File

@@ -57,7 +57,7 @@ class AssetAccountsTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
19 => 'Else',
23 => 'Something (IBAN)',

View File

@@ -58,7 +58,7 @@ class BillsTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
9 => 'Else [match]',
5 => 'Something [hi,bye]',
];

View File

@@ -55,7 +55,7 @@ class BudgetsTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
4 => 'Else',
8 => 'Something',

View File

@@ -55,7 +55,7 @@ class CategoriesTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
17 => 'Else',
9 => 'Something',

View File

@@ -59,7 +59,7 @@ class OpposingAccountIbansTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
17 => 'Else',
21 => 'IBAN (Something)',
];

View File

@@ -59,7 +59,7 @@ class OpposingAccountsTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
9 => 'Else',
13 => 'Something (IBAN)',
];

View File

@@ -55,7 +55,7 @@ class TagsTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
14 => 'Else',
12 => 'Something',
];

View File

@@ -57,7 +57,7 @@ class TransactionCurrenciesTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => (string)trans('import.map_do_not_map'),
11 => 'Else (DEF)',
9 => 'Something (ABC)',

View File

@@ -27,7 +27,7 @@ use FireflyIII\Import\Object\ImportAccount;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Mockery;
use Tests\TestCase;

View File

@@ -77,7 +77,7 @@ class AuthenticateTest extends TestCase
$this->be($user);
$response = $this->get('/_test/authenticate');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
$response->assertSessionHas('logoutMessage', strval(trans('firefly.block_account_logout')));
$response->assertSessionHas('logoutMessage', (string)trans('firefly.block_account_logout'));
$response->assertRedirect(route('login'));
}
@@ -94,7 +94,7 @@ class AuthenticateTest extends TestCase
$this->be($user);
$response = $this->get('/_test/authenticate');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
$response->assertSessionHas('logoutMessage', strval(trans('firefly.email_changed_logout')));
$response->assertSessionHas('logoutMessage', (string)trans('firefly.email_changed_logout'));
$response->assertRedirect(route('login'));
}

View File

@@ -1241,7 +1241,7 @@ class BinderTest extends TestCase
}
);
$names = join(',', $tags->pluck('tag')->toArray());
$names = implode(',', $tags->pluck('tag')->toArray());
$this->be($this->user());

View File

@@ -65,7 +65,7 @@ class IsSandstormUserTest extends TestCase
$response = $this->get('/_test/is-sandstorm');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
$response->assertSessionHas('warning', strval(trans('firefly.sandstorm_not_available')));
$response->assertSessionHas('warning', (string)trans('firefly.sandstorm_not_available'));
$response->assertRedirect(route('index'));
putenv('SANDSTORM=0');
}

View File

@@ -128,7 +128,7 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_amount' => null,
'budget_id' => null,
'budget_name' => null,
'destination_id' => intval($source->account_id),
'destination_id' => (int)$source->account_id,
'destination_name' => null,
'category_id' => null,
'category_name' => null,
@@ -167,7 +167,7 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_amount' => '12.34',
'budget_id' => null,
'budget_name' => null,
'destination_id' => intval($source->account_id),
'destination_id' => (int)$source->account_id,
'destination_name' => null,
'category_id' => null,
'category_name' => null,
@@ -210,7 +210,7 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_amount' => null,
'budget_id' => null,
'budget_name' => null,
'source_id' => intval($source->account_id),
'source_id' => (int)$source->account_id,
'source_name' => null,
'category_id' => null,
'category_name' => null,

View File

@@ -44,7 +44,7 @@ class AppendNotesTest extends TestCase
$note = $journal->notes()->first();
$start = 'Default note text';
$toAppend = 'This is appended';
if (is_null($note)) {
if (null === $note) {
$note = new Note();
$note->noteable()->associate($journal);
}
@@ -71,7 +71,7 @@ class AppendNotesTest extends TestCase
// give journal some notes.
$journal = TransactionJournal::find(4);
$note = $journal->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$note->forceDelete();
}
$toAppend = 'This is appended';

View File

@@ -42,7 +42,7 @@ class ClearNotesTest extends TestCase
// give journal a note:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
if (null === $note) {
$note = new Note;
$note->noteable()->associate($journal);
}

View File

@@ -44,7 +44,7 @@ class PrependNotesTest extends TestCase
$note = $journal->notes()->first();
$start = 'Default note text';
$toPrepend = 'This is prepended';
if (is_null($note)) {
if (null === $note) {
$note = new Note();
$note->noteable()->associate($journal);
}
@@ -71,7 +71,7 @@ class PrependNotesTest extends TestCase
// give journal some notes.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$note->forceDelete();
}
$toPrepend = 'This is appended';

View File

@@ -41,7 +41,7 @@ class RemoveAllTagsTest extends TestCase
{
// find journal with at least one tag
$journalIds = DB::table('tag_transaction_journal')->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$journalId = intval($journalIds[0]);
$journalId = (int)$journalIds[0];
/** @var TransactionJournal $journal */
$journal = TransactionJournal::find($journalId);

View File

@@ -42,7 +42,7 @@ class RemoveTagTest extends TestCase
// find journal with at least one tag
$journalIds = DB::table('tag_transaction_journal')->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$journalId = intval($journalIds[0]);
$journalId = (int)$journalIds[0];
/** @var TransactionJournal $journal */
$journal = TransactionJournal::find($journalId);
$originalCount = $journal->tags()->count();

View File

@@ -42,7 +42,7 @@ class SetNotesTest extends TestCase
// give journal a note:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
if (null === $note) {
$note = new Note;
$note->noteable()->associate($journal);
}

View File

@@ -36,9 +36,12 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
$transaction = null;
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
} while (null === $transaction);
$account = $transaction->account;
$trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
$result = $trigger->triggered($journal);
@@ -50,8 +53,12 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$transaction = null;
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
} while (null === $transaction);
$account = $transaction->account;
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);

View File

@@ -74,7 +74,7 @@ class ToAccountEndsTest extends TestCase
{
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountEnds::makeFromStrings(strval(random_int(1, 234)), false);
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);
}