Skip to content

Firefly III: a personal finances manager

Update test code.

James Colebc5aa4b4cd9e
diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php
index 5b791637ed..6a51a73345 100644
--- a/app/Repositories/Attachment/AttachmentRepository.php
+++ b/app/Repositories/Attachment/AttachmentRepository.php
@@ -179,7 +179,15 @@ class AttachmentRepository implements AttachmentRepositoryInterface
$attachment->filename = $data['filename'];
}
}
+ // update model (move attachment)
+ // should be validated already:
+ if (array_key_exists('attachable_type', $data) && array_key_exists('attachable_id', $data)) {
+ $attachment->attachable_id = (int)$data['attachable_id'];
+ $attachment->attachable_type = sprintf('FireflyIII\\Models\\%s', $data['attachable_type']);
+ }
+
$attachment->save();
+ $attachment->refresh();
if (array_key_exists('notes', $data)) {
$this->updateNote($attachment, (string)$data['notes']);
}
diff --git a/phpunit.xml b/phpunit.xml
index 1bccf75d92..62c925ba79 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -36,7 +36,7 @@
</coverage>
<testsuites>
<testsuite name="Api">
- <directory suffix="Test.php">./tests/Api/Models/Account</directory>
+ <directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
</testsuite>
</testsuites>
<php>
diff --git a/tests/Api/Models/Account/StoreControllerTest.php b/tests/Api/Models/Account/StoreControllerTest.php
index 99c7aa0924..7946da5477 100644
--- a/tests/Api/Models/Account/StoreControllerTest.php
+++ b/tests/Api/Models/Account/StoreControllerTest.php
@@ -29,7 +29,6 @@ use Tests\Objects\FieldSet;
use Tests\Objects\TestConfiguration;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
use Tests\Traits\TestHelpers;
/**
@@ -37,7 +36,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
@@ -58,27 +57,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this)));
}
- /**
- * @param array $submission
- *
- * storeDataProvider / emptyDataProvider
- *
- * @dataProvider emptyDataProvider
- */
- public function testStore(array $submission): void
- {
- if ([] === $submission) {
- $this->markTestSkipped('Empty provider.');
- }
- Log::debug('testStoreUpdated()');
- Log::debug('submission :', $submission['submission']);
- Log::debug('expected :', $submission['expected']);
- Log::debug('ignore :', $submission['ignore']);
- // run account store with a minimal data set:
- $address = route('api.v1.accounts.store');
- $this->updatedStoreAndCompare($address, $submission);
- }
-
/**
* @return array
*/
@@ -217,4 +195,25 @@ class StoreControllerTest extends TestCase
return $final;
}
+ /**
+ * @param array $submission
+ *
+ * storeDataProvider / emptyDataProvider
+ *
+ * @dataProvider emptyDataProvider
+ */
+ public function testStore(array $submission): void
+ {
+ if ([] === $submission) {
+ $this->markTestSkipped('Empty provider.');
+ }
+ Log::debug('testStoreUpdated()');
+ Log::debug('submission :', $submission['submission']);
+ Log::debug('expected :', $submission['expected']);
+ Log::debug('ignore :', $submission['ignore']);
+ // run account store with a minimal data set:
+ $address = route('api.v1.accounts.store');
+ $this->assertPOST($address, $submission);
+ }
+
}
\ No newline at end of file
diff --git a/tests/Api/Models/Account/UpdateControllerTest.php b/tests/Api/Models/Account/UpdateControllerTest.php
index 1f4c6db481..68412b07f9 100644
--- a/tests/Api/Models/Account/UpdateControllerTest.php
+++ b/tests/Api/Models/Account/UpdateControllerTest.php
@@ -29,7 +29,6 @@ use Tests\Objects\FieldSet;
use Tests\Objects\TestConfiguration;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
use Tests\Traits\TestHelpers;
@@ -38,39 +37,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
-
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Passport::actingAs($this->user());
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @param array $submission
- *
- * newStoreDataProvider / emptyDataProvider
- *
- * @dataProvider newUpdateDataProvider
- */
- public function testUpdate(array $submission): void
- {
- if ([] === $submission) {
- $this->markTestSkipped('Empty provider.');
- }
- Log::debug('testStoreUpdated()');
- Log::debug('submission :', $submission['submission']);
- Log::debug('expected :', $submission['expected']);
- Log::debug('ignore :', $submission['ignore']);
- Log::debug('parameters :', $submission['parameters']);
-
- $route = route('api.v1.accounts.update', $submission['parameters']);
- $this->updatedUpdateAndCompare($route, $submission);
- }
+ use TestHelpers, CollectsValues;
/**
* Only create optional sets.
@@ -157,28 +124,28 @@ class UpdateControllerTest extends TestCase
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
- $fieldSet = new FieldSet;
+ $fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
- $fieldSet = new FieldSet;
+ $fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('opening_balance', 'random-amount'));
$fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
$configuration->addOptionalFieldSet('ob', $fieldSet);
- $fieldSet = new FieldSet;
+ $fieldSet = new FieldSet;
$fieldSet->parameters = [7];
$fieldSet->addField(Field::createBasic('account_role', 'static-ccAsset'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'static-monthlyFull'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'random-past-date'));
$configuration->addOptionalFieldSet('cc1', $fieldSet);
- $fieldSet = new FieldSet;
- $fieldSet->parameters = [13];
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [13];
$field = new Field;
$field->fieldTitle = 'liability_type';
$field->fieldType = 'random-liability-type';
@@ -190,7 +157,7 @@ class UpdateControllerTest extends TestCase
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
$configuration->addOptionalFieldSet('liability-1', $fieldSet);
- $fieldSet = new FieldSet;
+ $fieldSet = new FieldSet;
$fieldSet->parameters = [13];
$fieldSet->addField(Field::createBasic('interest', 'random-percentage'));
$field = new Field;
@@ -223,4 +190,36 @@ class UpdateControllerTest extends TestCase
return $final;
}
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Passport::actingAs($this->user());
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @param array $submission
+ *
+ * newStoreDataProvider / emptyDataProvider
+ *
+ * @dataProvider newUpdateDataProvider
+ */
+ public function testUpdate(array $submission): void
+ {
+ if ([] === $submission) {
+ $this->markTestSkipped('Empty provider.');
+ }
+ Log::debug('testStoreUpdated()');
+ Log::debug('submission :', $submission['submission']);
+ Log::debug('expected :', $submission['expected']);
+ Log::debug('ignore :', $submission['ignore']);
+ Log::debug('parameters :', $submission['parameters']);
+
+ $route = route('api.v1.accounts.update', $submission['parameters']);
+ $this->assertPUT($route, $submission);
+ }
}
\ No newline at end of file
diff --git a/tests/Api/Models/Attachment/StoreControllerTest.php b/tests/Api/Models/Attachment/StoreControllerTest.php
index 5f03ae7152..2e2f3d51e9 100644
--- a/tests/Api/Models/Attachment/StoreControllerTest.php
+++ b/tests/Api/Models/Attachment/StoreControllerTest.php
@@ -22,12 +22,13 @@
namespace Tests\Api\Models\Attachment;
-use Faker\Factory;
use Laravel\Passport\Passport;
use Log;
+use Tests\Objects\Field;
+use Tests\Objects\FieldSet;
+use Tests\Objects\TestConfiguration;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +36,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
@@ -56,67 +57,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this)));
}
- /**
- * @return array
- */
- public function storeDataProvider(): array
- {
- $minimalSets = $this->minimalSets();
- $optionalSets = $this->optionalSets();
- $regenConfig = [];
-
- return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
- }
-
- /**
- * @return array
- */
- private function minimalSets(): array
- {
- $faker = Factory::create();
- $types = [
- 'Account',
- 'Budget',
- 'Bill',
- 'TransactionJournal',
- 'PiggyBank',
- 'Tag',
- ];
- $type = $types[rand(0, count($types) - 1)];
-
- return [
- 'default_file' => [
- 'parameters' => [],
- 'fields' => [
- 'filename' => join(' ', $faker->words(3)),
- 'attachable_type' => $type,
- 'attachable_id' => '1',
- ],
- ],
- ];
- }
-
- /**
- * @return \array[][]
- */
- private function optionalSets(): array
- {
- $faker = Factory::create();
-
- return [
- 'title' => [
- 'fields' => [
- 'title' => $faker->uuid,
- ],
- ],
- 'notes' => [
- 'fields' => [
- 'notes' => join(' ', $faker->words(5)),
- ],
- ],
- ];
- }
-
/**
* @param array $submission
*
@@ -127,10 +67,57 @@ class StoreControllerTest extends TestCase
public function testStore(array $submission): void
{
if ([] === $submission) {
- $this->markTestSkipped('Empty data provider');
+ $this->markTestSkipped('Empty provider.');
}
+ Log::debug('testStoreUpdated()');
+ Log::debug('submission :', $submission['submission']);
+ Log::debug('expected :', $submission['expected']);
+ Log::debug('ignore :', $submission['ignore']);
// run account store with a minimal data set:
- $route = 'api.v1.attachments.store';
- $this->storeAndCompare($route, $submission);
+ $address = route('api.v1.attachments.store');
+ $this->assertPOST($address, $submission);
+ }
+
+ /**
+ * @return array
+ */
+ public function storeDataProvider(): array
+ {
+ // some test configs:
+ $configuration = new TestConfiguration;
+
+ // default asset account test set:
+ $defaultAssetSet = new FieldSet();
+ $defaultAssetSet->title = 'default_file';
+ $defaultAssetSet->addField(Field::createBasic('filename', 'uuid'));
+ $defaultAssetSet->addField(Field::createBasic('attachable_type', 'random-attachment-type'));
+ $defaultAssetSet->addField(Field::createBasic('attachable_id', 'static-one'));
+ $configuration->addMandatoryFieldSet($defaultAssetSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('title', 'uuid'));
+ $configuration->addOptionalFieldSet('title', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->addField(Field::createBasic('notes', 'uuid'));
+ $configuration->addOptionalFieldSet('notes', $fieldSet);
+
+
+ // generate submissions
+ $array = $configuration->generateSubmissions();
+ $expected = $configuration->generateExpected($array);
+ $ignored = $configuration->ignores;
+
+ // now create a combination for each submission and associated data:
+ $final = [];
+ foreach ($array as $index => $submission) {
+ $final[] = [[
+ 'submission' => $submission,
+ 'expected' => $expected[$index],
+ 'ignore' => $ignored[$index],
+ ]];
+ }
+
+ return $final;
}
}
\ No newline at end of file
diff --git a/tests/Api/Models/Attachment/UpdateControllerTest.php b/tests/Api/Models/Attachment/UpdateControllerTest.php
index aa739e139b..bb52dbaae3 100644
--- a/tests/Api/Models/Attachment/UpdateControllerTest.php
+++ b/tests/Api/Models/Attachment/UpdateControllerTest.php
@@ -25,9 +25,11 @@ namespace Tests\Api\Models\Attachment;
use Faker\Factory;
use Laravel\Passport\Passport;
use Log;
+use Tests\Objects\Field;
+use Tests\Objects\FieldSet;
+use Tests\Objects\TestConfiguration;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +37,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
@@ -53,13 +55,17 @@ class UpdateControllerTest extends TestCase
*/
public function testUpdate(array $submission): void
{
- $ignore = [
- 'created_at',
- 'updated_at',
- ];
- $route = route('api.v1.attachments.update', [$submission['id']]);
-
- $this->updateAndCompare($route, $submission, $ignore);
+ if ([] === $submission) {
+ $this->markTestSkipped('Empty provider.');
+ }
+ Log::debug('testStoreUpdated()');
+ Log::debug('submission :', $submission['submission']);
+ Log::debug('expected :', $submission['expected']);
+ Log::debug('ignore :', $submission['ignore']);
+ Log::debug('parameters :', $submission['parameters']);
+
+ $route = route('api.v1.attachments.update', $submission['parameters']);
+ $this->assertPUT($route, $submission);
}
@@ -68,13 +74,48 @@ class UpdateControllerTest extends TestCase
*/
public function updateDataProvider(): array
{
- $submissions = [];
- $all = $this->updateDataSet();
- foreach ($all as $name => $data) {
- $submissions[] = [$data];
+ $configuration = new TestConfiguration;
+
+ // optional field sets (for all test configs)
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('filename', 'uuid'));
+ $configuration->addOptionalFieldSet('filename', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('title', 'uuid'));
+ $configuration->addOptionalFieldSet('title', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('notes', 'uuid'));
+ $configuration->addOptionalFieldSet('notes', $fieldSet);
+
+ $fieldSet = new FieldSet;
+ $fieldSet->parameters = [1];
+ $fieldSet->addField(Field::createBasic('attachable_type', 'static-journal-type'));
+ $fieldSet->addField(Field::createBasic('attachable_id', 'random-journal-id'));
+ $configuration->addOptionalFieldSet('attachable_type', $fieldSet);
+
+ // generate submissions
+ $array = $configuration->generateSubmissions();
+ $expected = $configuration->generateExpected($array);
+ $parameters = $configuration->parameters;
+ $ignored = $configuration->ignores;
+
+ // now create a combination for each submission and associated data:
+ $final = [];
+ foreach ($array as $index => $submission) {
+ $final[] = [[
+ 'submission' => $submission,
+ 'expected' => $expected[$index],
+ 'ignore' => $ignored[$index] ?? [],
+ 'parameters' => $parameters[$index],
+ ]];
}
- return $submissions;
+ return $final;
}
diff --git a/tests/Api/Models/AvailableBudget/StoreControllerTest.php b/tests/Api/Models/AvailableBudget/StoreControllerTest.php
index dbb1c569f2..8cae7c9f70 100644
--- a/tests/Api/Models/AvailableBudget/StoreControllerTest.php
+++ b/tests/Api/Models/AvailableBudget/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/AvailableBudget/UpdateControllerTest.php b/tests/Api/Models/AvailableBudget/UpdateControllerTest.php
index 3366aefdef..0c8e10ef15 100644
--- a/tests/Api/Models/AvailableBudget/UpdateControllerTest.php
+++ b/tests/Api/Models/AvailableBudget/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Bill/StoreControllerTest.php b/tests/Api/Models/Bill/StoreControllerTest.php
index 6c9829eec8..742974e09c 100644
--- a/tests/Api/Models/Bill/StoreControllerTest.php
+++ b/tests/Api/Models/Bill/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/Bill/UpdateControllerTest.php b/tests/Api/Models/Bill/UpdateControllerTest.php
index abca63ae6c..10512752aa 100644
--- a/tests/Api/Models/Bill/UpdateControllerTest.php
+++ b/tests/Api/Models/Bill/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Budget/StoreControllerTest.php b/tests/Api/Models/Budget/StoreControllerTest.php
index 9173df7e29..41d4f3cbeb 100644
--- a/tests/Api/Models/Budget/StoreControllerTest.php
+++ b/tests/Api/Models/Budget/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/Budget/UpdateControllerTest.php b/tests/Api/Models/Budget/UpdateControllerTest.php
index cf63712240..4c71ea5bab 100644
--- a/tests/Api/Models/Budget/UpdateControllerTest.php
+++ b/tests/Api/Models/Budget/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/BudgetLimit/StoreControllerTest.php b/tests/Api/Models/BudgetLimit/StoreControllerTest.php
index 172c9ea53f..9bc5fc1538 100644
--- a/tests/Api/Models/BudgetLimit/StoreControllerTest.php
+++ b/tests/Api/Models/BudgetLimit/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/BudgetLimit/UpdateControllerTest.php b/tests/Api/Models/BudgetLimit/UpdateControllerTest.php
index a3d9a7ca22..e48bec15b2 100644
--- a/tests/Api/Models/BudgetLimit/UpdateControllerTest.php
+++ b/tests/Api/Models/BudgetLimit/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Category/StoreControllerTest.php b/tests/Api/Models/Category/StoreControllerTest.php
index 94d6563512..087f997bd1 100644
--- a/tests/Api/Models/Category/StoreControllerTest.php
+++ b/tests/Api/Models/Category/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/Category/UpdateControllerTest.php b/tests/Api/Models/Category/UpdateControllerTest.php
index e2faa60da3..ba07eaed54 100644
--- a/tests/Api/Models/Category/UpdateControllerTest.php
+++ b/tests/Api/Models/Category/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/ObjectGroup/UpdateControllerTest.php b/tests/Api/Models/ObjectGroup/UpdateControllerTest.php
index dc78be105e..b4e83a47e0 100644
--- a/tests/Api/Models/ObjectGroup/UpdateControllerTest.php
+++ b/tests/Api/Models/ObjectGroup/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/PiggyBank/StoreControllerTest.php b/tests/Api/Models/PiggyBank/StoreControllerTest.php
index dcf879be11..1f14cc6618 100644
--- a/tests/Api/Models/PiggyBank/StoreControllerTest.php
+++ b/tests/Api/Models/PiggyBank/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/PiggyBank/UpdateControllerTest.php b/tests/Api/Models/PiggyBank/UpdateControllerTest.php
index 8408bbb901..4a1d7adbea 100644
--- a/tests/Api/Models/PiggyBank/UpdateControllerTest.php
+++ b/tests/Api/Models/PiggyBank/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Recurrence/StoreControllerTest.php b/tests/Api/Models/Recurrence/StoreControllerTest.php
index 67e7ee32ee..994782b2a0 100644
--- a/tests/Api/Models/Recurrence/StoreControllerTest.php
+++ b/tests/Api/Models/Recurrence/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/Recurrence/UpdateControllerTest.php b/tests/Api/Models/Recurrence/UpdateControllerTest.php
index dcf1f28bcc..b8253cf7db 100644
--- a/tests/Api/Models/Recurrence/UpdateControllerTest.php
+++ b/tests/Api/Models/Recurrence/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Rule/StoreControllerTest.php b/tests/Api/Models/Rule/StoreControllerTest.php
index 314f9da78c..1bf76edd88 100644
--- a/tests/Api/Models/Rule/StoreControllerTest.php
+++ b/tests/Api/Models/Rule/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/RuleGroup/StoreControllerTest.php b/tests/Api/Models/RuleGroup/StoreControllerTest.php
index 84a8056e78..2f54e628f3 100644
--- a/tests/Api/Models/RuleGroup/StoreControllerTest.php
+++ b/tests/Api/Models/RuleGroup/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/RuleGroup/UpdateControllerTest.php b/tests/Api/Models/RuleGroup/UpdateControllerTest.php
index dff0c96473..71acbb783e 100644
--- a/tests/Api/Models/RuleGroup/UpdateControllerTest.php
+++ b/tests/Api/Models/RuleGroup/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Tag/StoreControllerTest.php b/tests/Api/Models/Tag/StoreControllerTest.php
index aaef6095cb..a7777bf2c3 100644
--- a/tests/Api/Models/Tag/StoreControllerTest.php
+++ b/tests/Api/Models/Tag/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/Tag/UpdateControllerTest.php b/tests/Api/Models/Tag/UpdateControllerTest.php
index f7f03ca40e..67b3d19325 100644
--- a/tests/Api/Models/Tag/UpdateControllerTest.php
+++ b/tests/Api/Models/Tag/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/Transaction/StoreControllerTest.php b/tests/Api/Models/Transaction/StoreControllerTest.php
index dccec7acab..20696056d6 100644
--- a/tests/Api/Models/Transaction/StoreControllerTest.php
+++ b/tests/Api/Models/Transaction/StoreControllerTest.php
@@ -28,7 +28,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -36,7 +36,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/TransactionCurrency/StoreControllerTest.php b/tests/Api/Models/TransactionCurrency/StoreControllerTest.php
index f465b33571..81b72172bd 100644
--- a/tests/Api/Models/TransactionCurrency/StoreControllerTest.php
+++ b/tests/Api/Models/TransactionCurrency/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/TransactionCurrency/UpdateControllerTest.php b/tests/Api/Models/TransactionCurrency/UpdateControllerTest.php
index 78031f5705..008c0193f3 100644
--- a/tests/Api/Models/TransactionCurrency/UpdateControllerTest.php
+++ b/tests/Api/Models/TransactionCurrency/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/TransactionLink/StoreControllerTest.php b/tests/Api/Models/TransactionLink/StoreControllerTest.php
index 1c71f89695..af228a99a9 100644
--- a/tests/Api/Models/TransactionLink/StoreControllerTest.php
+++ b/tests/Api/Models/TransactionLink/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/TransactionLink/UpdateControllerTest.php b/tests/Api/Models/TransactionLink/UpdateControllerTest.php
index 2407ee7d53..03f8b3c8af 100644
--- a/tests/Api/Models/TransactionLink/UpdateControllerTest.php
+++ b/tests/Api/Models/TransactionLink/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Models/TransactionLinkType/StoreControllerTest.php b/tests/Api/Models/TransactionLinkType/StoreControllerTest.php
index c286491278..873eb0c21a 100644
--- a/tests/Api/Models/TransactionLinkType/StoreControllerTest.php
+++ b/tests/Api/Models/TransactionLinkType/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Models/TransactionLinkType/UpdateControllerTest.php b/tests/Api/Models/TransactionLinkType/UpdateControllerTest.php
index 4390f4a3cf..af0b70f778 100644
--- a/tests/Api/Models/TransactionLinkType/UpdateControllerTest.php
+++ b/tests/Api/Models/TransactionLinkType/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Api/Webhook/StoreControllerTest.php b/tests/Api/Webhook/StoreControllerTest.php
index 256e7bef8c..32bb1ffbfe 100644
--- a/tests/Api/Webhook/StoreControllerTest.php
+++ b/tests/Api/Webhook/StoreControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class StoreControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
* @return array
diff --git a/tests/Api/Webhook/UpdateControllerTest.php b/tests/Api/Webhook/UpdateControllerTest.php
index 0036294611..c59f83c015 100644
--- a/tests/Api/Webhook/UpdateControllerTest.php
+++ b/tests/Api/Webhook/UpdateControllerTest.php
@@ -27,7 +27,7 @@ use Laravel\Passport\Passport;
use Log;
use Tests\TestCase;
use Tests\Traits\CollectsValues;
-use Tests\Traits\RandomValues;
+
use Tests\Traits\TestHelpers;
/**
@@ -35,7 +35,7 @@ use Tests\Traits\TestHelpers;
*/
class UpdateControllerTest extends TestCase
{
- use RandomValues, TestHelpers, CollectsValues;
+ use TestHelpers, CollectsValues;
/**
*
diff --git a/tests/Objects/TestConfiguration.php b/tests/Objects/TestConfiguration.php
index c50053c0f3..56c6f86e40 100644
--- a/tests/Objects/TestConfiguration.php
+++ b/tests/Objects/TestConfiguration.php
@@ -376,8 +376,14 @@ class TestConfiguration
return 'ccAsset';
case 'static-monthlyFull':
return 'monthlyFull';
+ case 'static-one':
+ return 1;
+ case 'static-journal-type':
+ return 'TransactionJournal';
case 'random-liability-type':
return $faker->randomElement(['loan', 'debt', 'mortgage']);
+ case 'random-journal-id':
+ return $faker->numberBetween(1,25);
case 'random-amount':
return number_format($faker->randomFloat(2, 10, 100), 2);
case 'random-percentage':
@@ -411,6 +417,8 @@ class TestConfiguration
return $faker->numberBetween(1, 12);
case 'null':
return null;
+ case 'random-attachment-type':
+ return $faker->randomElement(['Account', 'Budget', 'Bill', 'TransactionJournal', 'PiggyBank','Tag',]);
}
}
diff --git a/tests/Traits/CollectsValues.php b/tests/Traits/CollectsValues.php
index ff78279d6d..5403888156 100644
--- a/tests/Traits/CollectsValues.php
+++ b/tests/Traits/CollectsValues.php
@@ -38,208 +38,4 @@ trait CollectsValues
{
return User::where('email', 'james@firefly')->first();
}
- //
- // /**
- // * @return User
- // */
- // public function nonAdminUser(): User
- // {
- // return User::where('email', 'no_admin@firefly')->first();
- // }
- //
- // /**
- // * @return Budget
- // */
- // public function getRandomBudget(): Budget
- // {
- // return $this->user()->budgets()->inRandomOrder()->first();
- // }
- //
- // /**
- // * @return Category
- // */
- // public function getRandomCategory(): Category
- // {
- // return $this->user()->categories()->inRandomOrder()->first();
- // }
- //
- // /**
- // * @return Bill
- // */
- // public function getRandomBill(): Bill
- // {
- // return $this->user()->bills()->inRandomOrder()->first();
- // }
- //
- // /**
- // * @return PiggyBank
- // */
- // public function getRandomPiggyBank(): PiggyBank
- // {
- // return $this->user()->piggyBanks()->inRandomOrder()->first();
- // }
- //
- //
- // /**
- // * @return Tag
- // */
- // public function getRandomTag(): Tag
- // {
- // return $this->user()->tags()->inRandomOrder()->first();
- // }
- //
- // /**
- // * @return TransactionJournal
- // */
- // public function getRandomWithdrawal(): TransactionJournal
- // {
- // return $this->getRandomJournal(TransactionType::WITHDRAWAL);
- // }
- //
- // /**
- // * @return TransactionJournal
- // */
- // public function getRandomTransfer(): TransactionJournal
- // {
- // return $this->getRandomJournal(TransactionType::TRANSFER);
- // }
- //
- // /**
- // * @return TransactionJournal
- // */
- // public function getRandomDeposit(): TransactionJournal
- // {
- // return $this->getRandomJournal(TransactionType::DEPOSIT);
- // }
- //
- // /**
- // * @param string $type
- // *
- // * @return TransactionJournal
- // * @throws FireflyException
- // */
- // private function getRandomJournal(string $type): TransactionJournal
- // {
- // $query = DB::table('transactions')
- // ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- // ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- // ->where('transaction_journals.user_id', $this->user()->id)
- // ->whereNull('transaction_journals.deleted_at')
- // ->whereNull('transactions.deleted_at')
- // ->where('transaction_types.type', $type)
- // ->groupBy('transactions.transaction_journal_id')
- // ->having('ct', '=', 2)
- // ->inRandomOrder()->take(1);
- // $result = $query->get(
- // [
- // 'transactions.transaction_journal_id',
- // 'transaction_journals.transaction_type_id',
- // DB::raw('COUNT(transaction_journal_id) as ct'),
- // ]
- // )->first();
- // if (null === $result) {
- // throw new FireflyException(sprintf('Cannot find suitable journal "%s" to use.', $type));
- // }
- //
- // return TransactionJournal::find((int)$result->transaction_journal_id);
- //
- // }
- //
- // /**
- // * @return TransactionCurrency
- // */
- // public function getEuro(): TransactionCurrency
- // {
- // return TransactionCurrency::whereCode('EUR')->first();
- // }
- //
- // /**
- // * @return TransactionCurrency
- // */
- // public function getRandomCurrency(): TransactionCurrency
- // {
- // return TransactionCurrency::where('code', '!=', 'EUR')->inRandomOrder()->first();
- // }
- //
- // /**
- // * @return TransactionCurrency
- // */
- // public function getDollar(): TransactionCurrency
- // {
- // return TransactionCurrency::whereCode('USD')->first();
- // }
- //
- // /**
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // public function getRandomAsset(?int $except = null): Account
- // {
- // return $this->getRandomAccount(AccountType::ASSET, $except);
- // }
- //
- // /**
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // public function getRandomDebt(?int $except = null): Account
- // {
- // return $this->getRandomAccount(AccountType::DEBT, $except);
- // }
- //
- // /**
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // public function getRandomLoan(?int $except = null): Account
- // {
- // return $this->getRandomAccount(AccountType::LOAN, $except);
- // }
- //
- // /**
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // public function getRandomRevenue(?int $except = null): Account
- // {
- // return $this->getRandomAccount(AccountType::REVENUE, $except);
- // }
- //
- // /**
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // public function getRandomExpense(?int $except = null): Account
- // {
- // return $this->getRandomAccount(AccountType::EXPENSE, $except);
- // }
- //
- // /**
- // * @param string $type
- // *
- // * @param int|null $except
- // *
- // * @return Account
- // */
- // private function getRandomAccount(string $type, ?int $except): Account
- // {
- // $query = Account::
- // leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
- // ->whereNull('accounts.deleted_at')
- // ->where('accounts.user_id', $this->user()->id)
- // ->where('account_types.type', $type)
- // ->inRandomOrder()->take(1);
- // if (null !== $except) {
- // $query->where('accounts.id', '!=', $except);
- // }
- //
- // return $query->first(['accounts.*']);
- // }
-
-
}
diff --git a/tests/Traits/FakeValues.php b/tests/Traits/FakeValues.php
deleted file mode 100644
index 54a5912141..0000000000
--- a/tests/Traits/FakeValues.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/*
- * FakeValues.php
- * Copyright (c) 2021 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace Tests\Traits;
-
-
-trait FakeValues
-{
- // /**
- // * @return string
- // */
- // protected function fakeName(): string {
- // return '';
- // }
-
-}
\ No newline at end of file
diff --git a/tests/Traits/MocksDefaultValues.php b/tests/Traits/MocksDefaultValues.php
deleted file mode 100644
index ecac0c158a..0000000000
--- a/tests/Traits/MocksDefaultValues.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/*
- * MocksDefaultValues.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Traits;
-
-/**
- * Trait MocksDefaultValues
- */
-trait MocksDefaultValues
-{
- // public function mockDefaultConfiguration(): void
- // {
- //
- // $falseConfig = new Configuration;
- // $falseConfig->data = false;
- //
- // $idConfig = new Configuration;
- // $idConfig->data = 'abc';
- //
- // FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig);
- // FireflyConfig::shouldReceive('get')->withArgs(['installation_id', null])->andReturn($idConfig);
- // }
-
-}
diff --git a/tests/Traits/RandomValues.php b/tests/Traits/RandomValues.php
deleted file mode 100644
index cabb72987b..0000000000
--- a/tests/Traits/RandomValues.php
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/*
- * RandomValues.php
- * Copyright (c) 2021 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace Tests\Traits;
-
-
-use Carbon\Carbon;
-
-/**
- * Trait RandomValues
- */
-trait RandomValues
-{
- /**
- * @param $k
- * @param $xs
- *
- * @return array|array[]
- */
- protected function combinationsOf($k, $xs): array
- {
- if ($k === 0) {
- return [[]];
- }
- if (count($xs) === 0) {
- return [];
- }
- $x = $xs[0];
- $xs1 = array_slice($xs, 1, count($xs) - 1);
- $res1 = $this->combinationsOf($k - 1, $xs1);
- for ($i = 0; $i < count($res1); $i++) {
- array_splice($res1[$i], 0, 0, $x);
- }
- $res2 = $this->combinationsOf($k, $xs1);
-
- return array_merge($res1, $res2);
- }
-
- /**
- * @return string
- */
- protected function getRandomAmount(): string
- {
- return number_format(rand(1000, 100000) / 100, '2', '.');
- }
-
- /**
- * @return string
- */
- protected function getRandomCurrencyCode(): string
- {
- return $this->randomFromArray(['EUR', 'USD', 'GBP']);
- }
-
- /**
- * @return string
- */
- protected function getRandomDateString(): string
- {
- $date = Carbon::now();
- $date->subDays(rand(10, 100));
-
- return $date->format('Y-m-d');
- }
-
- /**
- * @return string
- */
- protected function getRandomInterestPeriod(): string
- {
- return $this->randomFromArray(['daily', 'monthly', 'yearly']);
- }
-
- /**
- * @return string
- */
- protected function getRandomPercentage(): string
- {
- return rand(1, 10000) / 100;
- }
-
- /**
- * @return string
- */
- protected function randomAccountRole(): string
- {
- return $this->randomFromArray(['defaultAsset', 'sharedAsset', 'savingAsset']);
- }
-
- /**
- * @param array $array
- *
- * @return mixed
- */
- private function randomFromArray(array $array)
- {
- return $array[rand(0, count($array) - 1)];
- }
-
- /**
- * @return string
- */
- protected function randomLiabilityType(): string
- {
- return $this->randomFromArray(['loan', 'debt', 'mortgage']);
- }
-}
\ No newline at end of file
diff --git a/tests/Traits/TestHelpers.php b/tests/Traits/TestHelpers.php
index 33a55ff13c..239b3ff662 100644
--- a/tests/Traits/TestHelpers.php
+++ b/tests/Traits/TestHelpers.php
@@ -23,136 +23,16 @@ declare(strict_types=1);
namespace Tests\Traits;
-use Exception;
-use JsonException;
-use Log;
-
/**
* Trait TestHelpers
*/
trait TestHelpers
{
- /**
- * @return int
- */
- public function randomInt(): int
- {
- $result = 4;
- try {
- $result = random_int(1, 100000);
- } catch (Exception $e) {
- Log::debug(sprintf('Could not generate random number: %s', $e->getMessage()));
- }
-
- return $result;
- }
-
- /**
- * @param array $minimalSets
- * @param array $startOptionalSets
- * @param array $regenConfig
- *
- * @return array
- */
- protected function genericDataProvider(array $minimalSets, array $startOptionalSets, array $regenConfig): array
- {
- $submissions = [];
- /**
- * @var string $i
- * @var array $set
- */
- foreach ($minimalSets as $i => $set) {
- $body = [];
- foreach ($set['fields'] as $ii => $value) {
- $body[$ii] = $value;
- }
- // minimal set is part of all submissions:
- $submissions[] = [[
- 'fields' => $body,
- 'parameters' => $set['parameters'] ?? [],
- 'ignore' => $set['ignore'] ?? [],
- ]];
-
- // then loop and add fields:
- $optionalSets = $startOptionalSets;
- $keys = array_keys($optionalSets);
- $count = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
- for ($iii = 1; $iii <= $count; $iii++) {
- $combinations = $this->combinationsOf($iii, $keys);
- // expand body with N extra fields:
- foreach ($combinations as $iv => $extraFields) {
- $second = $body;
- $ignore = $set['ignore'] ?? []; // unused atm.
- foreach ($extraFields as $v => $extraField) {
- // now loop optional sets on $extraField and add whatever the config is:
- foreach ($optionalSets[$extraField]['fields'] as $vi => $newValue) {
- // if the newValue is an array, we must merge it with whatever may
- // or may not already be there. Its the optional field for one of the
- // (maybe existing?) fields:
- if (is_array($newValue) && array_key_exists($vi, $second) && is_array($second[$vi])) {
- // loop $second[$vi] and merge it with whatever is in $newValue[$someIndex]
- foreach ($second[$vi] as $vii => $iiValue) {
- $second[$vi][$vii] = $iiValue + $newValue[$vii];
- }
- }
- if (!is_array($newValue)) {
- $second[$vi] = $newValue;
- }
- }
- if (array_key_exists('remove_fields', $optionalSets[$extraField])) {
- foreach ($optionalSets[$extraField]['remove_fields'] as $removed) {
- unset($second[$removed]);
- }
- }
- }
-
- $second = $this->regenerateValues($second, $regenConfig);
- $submissions[] = [[
- 'fields' => $second,
- 'parameters' => $set['parameters'] ?? [],
- 'ignore' => $ignore,
- ]];
- }
- }
- unset($second);
- }
-
- return $submissions;
- }
-
- /**
- * @param $set
- * @param $opts
- *
- * @return array
- */
- protected function regenerateValues($set, $opts): array
- {
- foreach ($opts as $i => $func) {
- if (array_key_exists($i, $set)) {
- if (!is_array($set[$i])) {
- $set[$i] = $func();
- }
- if (is_array($set[$i])) {
- foreach ($set[$i] as $ii => $lines) {
- foreach ($lines as $iii => $value) {
- if (isset($opts[$i][$ii][$iii])) {
- $set[$i][$ii][$iii] = $opts[$i][$ii][$iii]();
- }
- }
- }
- }
- }
- }
-
- return $set;
- }
-
/**
* @param string $route
* @param array $content
*/
- protected function updatedStoreAndCompare(string $route, array $content): void
+ protected function assertPOST(string $route, array $content): void
{
$submission = $content['submission'];
$expected = $content['expected'];
@@ -168,7 +48,7 @@ trait TestHelpers
// get return and compare each field
$responseAttributes = $responseJson['data']['attributes'];
- $this->updatedCompareStorageArray($submission, $responseAttributes, $expected, $ignore);
+ $this->comparePOSTArray($submission, $responseAttributes, $expected, $ignore);
// ignore fields too!
}
@@ -179,11 +59,11 @@ trait TestHelpers
* @param array $expected
* @param array $ignore
*/
- protected function updatedCompareStorageArray(array $submission, array $response, array $expected, array $ignore): void
+ private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
{
foreach ($response as $key => $value) {
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
- $this->updatedCompareStorageArray($submission, $value, $expected[$key], $ignore[$key] ?? []);
+ $this->comparePOSTArray($submission, $value, $expected[$key], $ignore[$key] ?? []);
}
if (isset($expected[$key])) {
if (in_array($key, $ignore, true)) {
@@ -202,13 +82,6 @@ trait TestHelpers
$this->assertEquals($value, $expected[$key], $message);
}
-
- // if($value !== $expected[$key]) {
- // }
- // var_dump($key);
- // var_dump($value);
- // var_dump($expected[$key]);
- // exit;
}
}
@@ -219,47 +92,7 @@ trait TestHelpers
* @param string $route
* @param array $content
*/
- protected function storeAndCompare(string $route, array $content): void
- {
- $submission = $content['fields'];
- $parameters = $content['parameters'];
- $ignore = $content['ignore'];
- $response = $this->post(route($route, $parameters), $submission, ['Accept' => 'application/json']);
- $responseBody = $response->content();
- $responseJson = json_decode($responseBody, true);
- $status = $response->getStatusCode();
- $this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
-
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- // compare results:
- foreach ($responseJson['data']['attributes'] as $returnName => $returnValue) {
- if (array_key_exists($returnName, $submission) && !in_array($returnName, $ignore, true)) {
- // TODO still based on account routine:
- if ($this->ignoreCombination($route, $submission['type'] ?? 'blank', $returnName)) {
- continue;
- }
- // check if is array, if so we need something smart:
- if (is_array($returnValue) && is_array($submission[$returnName])) {
- $this->compareArray($submission, $returnName, $submission[$returnName], $returnValue);
- }
- if (!is_array($returnValue) && !is_array($submission[$returnName])) {
- $message = sprintf(
- "Main: Return value '%s' of key '%s' does not match submitted value '%s'.\n%s\n%s", $returnValue, $returnName, $submission[$returnName],
- json_encode($submission), $responseBody
- );
- $this->assertEquals($returnValue, $submission[$returnName], $message);
- }
-
- }
- }
- }
-
- /**
- * @param string $route
- * @param array $content
- */
- protected function updatedUpdateAndCompare(string $route, array $content): void
+ protected function assertPUT(string $route, array $content): void
{
$submission = $content['submission'];
$ignore = $content['ignore'];
@@ -272,21 +105,21 @@ trait TestHelpers
// get return and compare each field
$responseAttributes = $responseJson['data']['attributes'];
- $this->updatedCompareUpdatedArray($route, $submission, $responseAttributes, $ignore);
+ $this->comparePUTArray($route, $submission, $responseAttributes, $ignore);
}
/**
* @param string $url
- * @param array $submission
- * @param array $response
- * @param array $ignore
+ * @param array $submission
+ * @param array $response
+ * @param array $ignore
*/
- private function updatedCompareUpdatedArray(string $url, array $submission, array $response, array $ignore): void
+ private function comparePUTArray(string $url, array $submission, array $response, array $ignore): void
{
foreach ($response as $key => $value) {
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
- $this->updatedCompareUpdatedArray($url, $submission[$key], $value, $ignore[$key] ?? []);
+ $this->comparePUTArray($url, $submission[$key], $value, $ignore[$key] ?? []);
}
if (isset($submission[$key])) {
@@ -310,162 +143,4 @@ trait TestHelpers
}
}
}
-
- /**
- * Some specials:
- *
- * @param string $area
- * @param string $left
- * @param string $right
- *
- * @return bool
- */
- protected function ignoreCombination(string $area, string $left, string $right): bool
- {
- if ('api.v1.accounts.store' === $area) {
- if ('expense' === $left
- && in_array($right, ['order', 'virtual_balance', 'opening_balance', 'opening_balance_date'])) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @param string $route
- * @param array $submission
- *
- * @throws JsonException
- */
- protected function updateAndCompare(string $route, array $submission, array $ignored): void
- {
- // get original values:
- $response = $this->get($route, ['Accept' => 'application/json']);
- $status = $response->getStatusCode();
- $this->assertEquals($status, 200, sprintf(sprintf('%s failed with 404.', $route)));
- $response->assertStatus(200);
- $originalString = $response->content();
- $originalArray = json_decode($originalString, true, 512, JSON_THROW_ON_ERROR);
- $originalAttributes = $originalArray['data']['attributes'];
- // submit whatever is in submission:
- // loop the fields we will update in Firefly III:
- $submissionArray = [];
- $fieldsToUpdate = array_keys($submission['fields']);
- foreach ($fieldsToUpdate as $currentFieldName) {
- $submissionArray[$currentFieldName] = $submission['fields'][$currentFieldName]['test_value'];
- }
-
- Log::debug(sprintf('Will PUT %s to %s', json_encode($submissionArray), $route));
-
- $response = $this->put($route, $submissionArray, ['Accept' => 'application/json']);
- $responseString = $response->content();
- $status = $response->getStatusCode();
- $this->assertEquals($status, 200, sprintf("Submission: %s\nResponse: %s", json_encode($submissionArray), $responseString));
- //$response->assertStatus(200);
- $responseArray = json_decode($responseString, true, 512, JSON_THROW_ON_ERROR);
- $responseAttributes = $responseArray['data']['attributes'] ?? [];
-
- Log::debug(sprintf('Before: %s', json_encode($originalAttributes)));
- Log::debug(sprintf('AFTER : %s', json_encode($responseAttributes)));
-
- // loop it and compare:
- foreach ($responseAttributes as $rKey => $rValue) {
- // field should be ignored?
- if (in_array($rKey, $ignored) || in_array($rKey, $submission['extra_ignore'])) {
- continue;
- }
- // field in response was also in body:
- if (array_key_exists($rKey, $submissionArray)) {
- // comparison must be on array:
- if (is_array($submissionArray[$rKey]) && is_array($rValue)) {
- $this->compareArray($submissionArray, $rKey, $submissionArray[$rKey], $rValue);
- }
-
- if (!is_array($submissionArray[$rKey]) && !is_array($rValue)) {
- if ($submissionArray[$rKey] !== $rValue) {
-
- $message = sprintf(
- "Expected field '%s' to be %s but its %s\nOriginal: %s\nSubmission: %s\nResult: %s",
- $rKey,
- var_export($submissionArray[$rKey], true),
- var_export($rValue, true),
- $originalString,
- json_encode($submissionArray),
- $responseString
- );
- $this->assertTrue(false, $message);
- continue;
- }
- }
- continue;
- }
- // field in response was not in body, but should be the same:
- if (!array_key_exists($rKey, $submissionArray)) {
- // original has this key too:
- if (array_key_exists($rKey, $originalAttributes)) {
- // but we can ignore it!
- if (in_array($rKey, $submission['extra_ignore'])) {
- continue;
- }
- // but it is different?
- if ($originalAttributes[$rKey] !== $rValue) {
- $message = sprintf(
- "Untouched field '%s' should still be %s but changed to %s\nOriginal: %s\nSubmission: %s\nResult: %s",
- $rKey,
- var_export($originalAttributes[$rKey], true),
- var_export($rValue, true),
- $originalString,
- json_encode($submissionArray),
- $responseString
- );
-
-
- $this->assertTrue(false, $message);
- }
- }
- continue;
- }
-
- }
- }
-
- /**
- * @param array $fullOriginal
- * @param string $key
- * @param array $original
- * @param array $returned
- */
- protected function compareArray(array $fullOriginal, string $key, array $original, array $returned)
- {
- // TODO this should be configurable but OK
- if (in_array($key, ['transactions', 'repetitions'], true) && 0 === count($original) && 0 !== count($returned)) {
- // accept this.
- return;
- }
- $ignore = ['id', 'created_at', 'updated_at'];
- foreach ($returned as $objectKey => $object) {
- // each object is a transaction, a rule trigger, a rule action, whatever.
- // assume the original also contains this key:
- if (!array_key_exists($objectKey, $original)) {
- $message = sprintf('Sub: Original array "%s" does not have returned key %d.', $key, $objectKey);
- $this->assertTrue(false, $message);
- }
-
- foreach ($object as $returnKey => $returnValue) {
- if (in_array($returnKey, $ignore, true)) {
- continue;
- }
- if (array_key_exists($returnKey, $original[$objectKey])) {
- $message = sprintf(
- "Sub-array '%s' returned value %s does not match sent value %s.\n%s\n%s",
- $key, var_export($returnValue, true), var_export($original[$objectKey][$returnKey], true),
- json_encode($fullOriginal),
- json_encode($returned),
- );
- $this->assertEquals($original[$objectKey][$returnKey], $returnValue, $message);
- }
- }
- }
- }
}