Improve randomness in test data to prevent key collisions.

This commit is contained in:
James Cole
2018-07-14 16:41:07 +02:00
parent ff403dfa2e
commit 3d1523a060
50 changed files with 283 additions and 283 deletions

View File

@@ -138,7 +138,7 @@ class AttachmentControllerTest extends TestCase
'user_id' => $this->user()->id,
'attachable_id' => 1,
'attachable_type' => TransactionJournal::class,
'md5' => md5('Hello' . random_int(1, 1000)),
'md5' => md5('Hello' . random_int(1, 10000)),
'filename' => 'some name',
'mime' => 'text/plain',
'size' => 5,
@@ -230,7 +230,7 @@ class AttachmentControllerTest extends TestCase
// data to submit
$data = [
'filename' => 'Some new att',
'description' => sprintf('Attempt #%d', random_int(1, 1000)),
'description' => sprintf('Attempt #%d', random_int(1, 10000)),
'model' => TransactionJournal::class,
'model_id' => 1,
];
@@ -265,7 +265,7 @@ class AttachmentControllerTest extends TestCase
// data to submit
$data = [
'filename' => $attachment->filename,
'description' => sprintf('Attempt #%d', random_int(1, 1000)),
'description' => sprintf('Attempt #%d', random_int(1, 10000)),
'model' => TransactionJournal::class,
'model_id' => 1,
];

View File

@@ -142,8 +142,8 @@ class BillControllerTest extends TestCase
// data to submit:
$data = [
'name' => 'New bill #' . random_int(1, 1000),
'match' => 'some,words,' . random_int(1, 1000),
'name' => 'New bill #' . random_int(1, 10000),
'match' => 'some,words,' . random_int(1, 10000),
'amount_min' => '66.34',
'amount_max' => '45.67',
'date' => '2018-01-01',
@@ -187,8 +187,8 @@ class BillControllerTest extends TestCase
$repository->shouldReceive('getRulesForBill')->withAnyArgs()->andReturn(new Collection());
// data to submit:
$data = [
'name' => 'New bill #' . random_int(1, 1000),
'match' => 'some,words,' . random_int(1, 1000),
'name' => 'New bill #' . random_int(1, 10000),
'match' => 'some,words,' . random_int(1, 10000),
'amount_min' => '12.34',
'amount_max' => '45.67',
'date' => '2018-01-01',
@@ -226,8 +226,8 @@ class BillControllerTest extends TestCase
$repository->shouldReceive('getRulesForBill')->withAnyArgs()->andReturn(new Collection());
// data to submit:
$data = [
'name' => 'New bill #' . random_int(1, 1000),
'match' => 'some,words,' . random_int(1, 1000),
'name' => 'New bill #' . random_int(1, 10000),
'match' => 'some,words,' . random_int(1, 10000),
'amount_min' => '12.34',
'amount_max' => '45.67',
'date' => '2018-01-01',

View File

@@ -96,7 +96,7 @@ class TransactionControllerTest extends TestCase
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -142,7 +142,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -240,7 +240,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Split journal #' . random_int(1, 1000),
'description' => 'Split journal #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -298,7 +298,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -345,7 +345,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('findByName')->andReturn(null);
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -390,7 +390,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -434,7 +434,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [],
@@ -474,7 +474,7 @@ class TransactionControllerTest extends TestCase
$data = [
'description' => 'Split journal #' . random_int(1, 1000),
'description' => 'Split journal #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -524,7 +524,7 @@ class TransactionControllerTest extends TestCase
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -580,7 +580,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_id' => $bill->id,
@@ -638,7 +638,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_name' => $bill->name,
@@ -696,7 +696,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -754,7 +754,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -812,7 +812,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -876,7 +876,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'piggy_bank_id' => $piggyBank->id,
@@ -942,7 +942,7 @@ class TransactionControllerTest extends TestCase
// submit with another account.
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'piggy_bank_name' => $piggyBank->name,
@@ -996,7 +996,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
@@ -1045,7 +1045,7 @@ class TransactionControllerTest extends TestCase
$data = [
'description' => 'Some deposit #' . random_int(1, 1000),
'description' => 'Some deposit #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
@@ -1101,7 +1101,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second]));
$data = [
'description' => 'Some transfer #' . random_int(1, 1000),
'description' => 'Some transfer #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'transfer',
'transactions' => [
@@ -1165,7 +1165,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$second]));
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1479,7 +1479,7 @@ class TransactionControllerTest extends TestCase
$bill = $this->user()->bills()->first();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_id' => $bill->id,
@@ -1520,7 +1520,7 @@ class TransactionControllerTest extends TestCase
$bill = $this->user()->bills()->first();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'bill_name' => $bill->name,
@@ -1559,7 +1559,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1567,7 +1567,7 @@ class TransactionControllerTest extends TestCase
'amount' => '10',
'currency_id' => 1,
'source_id' => $account->id,
'destination_name' => 'New expense account #' . random_int(1, 1000),
'destination_name' => 'New expense account #' . random_int(1, 10000),
],
@@ -1600,7 +1600,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1639,7 +1639,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1680,7 +1680,7 @@ class TransactionControllerTest extends TestCase
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1719,7 +1719,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'deposit',
'transactions' => [
@@ -1757,7 +1757,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1797,7 +1797,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1836,7 +1836,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1875,7 +1875,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1915,7 +1915,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -1954,7 +1954,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
// store date meta fields (if present):
@@ -1999,9 +1999,9 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$name = 'Some new category #' . random_int(1, 1000);
$name = 'Some new category #' . random_int(1, 10000);
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2041,7 +2041,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$name = 'New opposing account #' . random_int(1, 10000);
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2080,7 +2080,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'notes' => 'I am a note',
@@ -2119,7 +2119,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]), new Collection([$opposing]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2159,7 +2159,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2199,7 +2199,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some deposit #' . random_int(1, 1000),
'description' => 'Some deposit #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'deposit',
'piggy_bank_name' => $piggy->name,
@@ -2240,7 +2240,7 @@ class TransactionControllerTest extends TestCase
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some transfer #' . random_int(1, 1000),
'description' => 'Some transfer #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'transfer',
'piggy_bank_id' => $piggy->id,
@@ -2280,7 +2280,7 @@ class TransactionControllerTest extends TestCase
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some transfer #' . random_int(1, 1000),
'description' => 'Some transfer #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'transfer',
'piggy_bank_name' => $piggy->name,
@@ -2316,7 +2316,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2354,7 +2354,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'transactions' => [
@@ -2392,9 +2392,9 @@ class TransactionControllerTest extends TestCase
public function testSuccessStoreTags(): void
{
$tags = [
'TagOne' . random_int(1, 1000),
'TagTwoBlarg' . random_int(1, 1000),
'SomeThreeTag' . random_int(1, 1000),
'TagOne' . random_int(1, 10000),
'TagTwoBlarg' . random_int(1, 10000),
'SomeThreeTag' . random_int(1, 10000),
];
$journal = $this->user()->transactionJournals()->first();
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
@@ -2406,7 +2406,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'type' => 'withdrawal',
'tags' => implode(',', $tags),
@@ -2442,7 +2442,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
$data = [
'description' => 'Some deposit #' . random_int(1, 1000),
'description' => 'Some deposit #' . random_int(1, 10000),
'date' => '2018-01-01',
'transactions' => [
[
@@ -2484,7 +2484,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
$data = [
'description' => 'Some transaction #' . random_int(1, 1000),
'description' => 'Some transaction #' . random_int(1, 10000),
'date' => '2018-01-01',
'transactions' => [
[

View File

@@ -57,7 +57,7 @@ class UserControllerTest extends TestCase
public function testDelete(): void
{
// create a user first:
$user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
$user = User::create(['email' => 'some@newu' . random_int(1, 10000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
// call API
$response = $this->delete('/api/v1/users/' . $user->id);
@@ -76,7 +76,7 @@ class UserControllerTest extends TestCase
Passport::actingAs($this->emptyUser());
// create a user first:
$user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
$user = User::create(['email' => 'some@newu' . random_int(1, 10000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
// call API
$response = $this->delete('/api/v1/users/' . $user->id);
@@ -137,7 +137,7 @@ class UserControllerTest extends TestCase
public function testStoreBasic(): void
{
$data = [
'email' => 'some_new@user' . random_int(1, 1000) . '.com',
'email' => 'some_new@user' . random_int(1, 10000) . '.com',
'blocked' => 0,
];
@@ -192,11 +192,11 @@ class UserControllerTest extends TestCase
public function testUpdate(): void
{
// create a user first:
$user = User::create(['email' => 'some@newu' . random_int(1, 1000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
$user = User::create(['email' => 'some@newu' . random_int(1, 10000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
// data:
$data = [
'email' => 'some-new@email' . random_int(1, 1000) . '.com',
'email' => 'some-new@email' . random_int(1, 10000) . '.com',
'blocked' => 0,
];