mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some test scripts.
This commit is contained in:
parent
690edb8fcc
commit
df86c89acc
@ -25,6 +25,9 @@ namespace Tests\Api\Models\Account;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
|
use Tests\Objects\TestMandatoryField;
|
||||||
|
use Tests\Objects\TestMandatoryFieldSet;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
use Tests\Traits\RandomValues;
|
use Tests\Traits\RandomValues;
|
||||||
@ -55,6 +58,8 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
|
$this->someTestData();
|
||||||
|
exit;
|
||||||
if ([] === $submission) {
|
if ([] === $submission) {
|
||||||
$this->markTestSkipped('Empty data provider');
|
$this->markTestSkipped('Empty data provider');
|
||||||
}
|
}
|
||||||
@ -235,7 +240,67 @@ class StoreControllerTest extends TestCase
|
|||||||
|
|
||||||
public function someTestData(): void
|
public function someTestData(): void
|
||||||
{
|
{
|
||||||
$set = [
|
// a basic test config set contains
|
||||||
|
// mandatory fields and X optional fields
|
||||||
|
// the optional fields will be rotated automatically.
|
||||||
|
$config = new TestConfiguration;
|
||||||
|
|
||||||
|
// add a set of mandatory fields:
|
||||||
|
$mandatoryFieldSet = new TestMandatoryFieldSet();
|
||||||
|
$mandatoryFieldSet->title = 'default_asset_account';
|
||||||
|
|
||||||
|
// name
|
||||||
|
$mandatoryField = new TestMandatoryField;
|
||||||
|
$mandatoryField->title = 'name';
|
||||||
|
$mandatoryField->fieldTitle = 'name';
|
||||||
|
$mandatoryField->fieldPosition = ''; // root
|
||||||
|
$mandatoryField->fieldType = 'uuid'; // refers to a generator or something?
|
||||||
|
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
|
||||||
|
$mandatoryField->expectedReturn = null; // or the callback
|
||||||
|
$mandatoryField->ignorableFields = [];
|
||||||
|
$mandatoryFieldSet->addMandatoryField($mandatoryField);
|
||||||
|
|
||||||
|
// type
|
||||||
|
$mandatoryField = new TestMandatoryField;
|
||||||
|
$mandatoryField->title = 'type';
|
||||||
|
$mandatoryField->fieldTitle = 'type';
|
||||||
|
$mandatoryField->fieldPosition = ''; // root
|
||||||
|
$mandatoryField->fieldType = 'static-asset'; // refers to a generator or something?
|
||||||
|
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
|
||||||
|
$mandatoryField->expectedReturn = null; // or the callback
|
||||||
|
$mandatoryField->ignorableFields = []; // something like transactions/0/currency_code
|
||||||
|
$mandatoryFieldSet->addMandatoryField($mandatoryField);
|
||||||
|
|
||||||
|
// role
|
||||||
|
$mandatoryField = new TestMandatoryField;
|
||||||
|
$mandatoryField->title = 'role';
|
||||||
|
$mandatoryField->fieldTitle = 'account_role';
|
||||||
|
$mandatoryField->fieldPosition = ''; // root
|
||||||
|
$mandatoryField->fieldType = 'random-asset-accountRole'; // refers to a generator or something?
|
||||||
|
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
|
||||||
|
$mandatoryField->expectedReturn = null; // or the callback
|
||||||
|
$mandatoryField->ignorableFields = []; // something like transactions/0/currency_code
|
||||||
|
$mandatoryFieldSet->addMandatoryField($mandatoryField);
|
||||||
|
|
||||||
|
// $mandatoryField = new TestMandatoryField;
|
||||||
|
// $mandatoryField->title = 'transaction_type';
|
||||||
|
// $mandatoryField->fieldTitle = 'type';
|
||||||
|
// $mandatoryField->fieldPosition = 'transactions/0'; // not root!
|
||||||
|
// $mandatoryField->fieldType = 'random-transactionType'; // refers to a generator or something?
|
||||||
|
// $mandatoryField->expectedReturnType = 'equal'; // or 'callback'
|
||||||
|
// $mandatoryField->expectedReturn = null; // or the callback
|
||||||
|
// $mandatoryField->ignorableFields = [];
|
||||||
|
// $mandatoryFieldSet->addMandatoryField($mandatoryField);
|
||||||
|
|
||||||
|
$config->mandatoryFieldSet = $mandatoryFieldSet;
|
||||||
|
|
||||||
|
// generate submissions
|
||||||
|
$arr = $config->generateSubmission();
|
||||||
|
var_dump($arr);
|
||||||
|
exit;
|
||||||
|
// generate expected returns.
|
||||||
|
|
||||||
|
$set = [
|
||||||
// set for withdrawal, copy this for
|
// set for withdrawal, copy this for
|
||||||
// other transaction types etc.
|
// other transaction types etc.
|
||||||
// make a CLASS!!
|
// make a CLASS!!
|
||||||
|
12
tests/Objects/IgnorableField.php
Normal file
12
tests/Objects/IgnorableField.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tests\Objects;
|
||||||
|
|
||||||
|
|
||||||
|
class IgnorableField
|
||||||
|
{
|
||||||
|
public string $fieldTitle;
|
||||||
|
public string $fieldPosition;
|
||||||
|
|
||||||
|
}
|
74
tests/Objects/TestConfiguration.php
Normal file
74
tests/Objects/TestConfiguration.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tests\Objects;
|
||||||
|
|
||||||
|
use Faker\Factory;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TestConfiguration
|
||||||
|
*/
|
||||||
|
class TestConfiguration
|
||||||
|
{
|
||||||
|
public TestMandatoryFieldSet $mandatoryFieldSet;
|
||||||
|
private array $submission;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestConfiguration constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->submission = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateSubmission(): array
|
||||||
|
{
|
||||||
|
$this->submission = [];
|
||||||
|
/** @var TestMandatoryField $field */
|
||||||
|
foreach ($this->mandatoryFieldSet->mandatoryFields as $field) {
|
||||||
|
$this->parseField($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->submission;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseField(TestMandatoryField $field)
|
||||||
|
{
|
||||||
|
if ('' === $field->fieldPosition) {
|
||||||
|
$this->submission[$field->fieldTitle] = $this->generateFieldValue($field->fieldType);
|
||||||
|
}
|
||||||
|
if ('' !== $field->fieldPosition) {
|
||||||
|
$positions = explode('/', $field->fieldPosition);
|
||||||
|
// since the "positions" array is almost 2 indexes deep at best, we can do some manual fiddling.
|
||||||
|
$root = $positions[0];
|
||||||
|
$count = (int)$positions[1];
|
||||||
|
$this->submission[$root] = array_key_exists($root, $this->submission) ? $this->submission[$root] : [];
|
||||||
|
$this->submission[$root][$count] = array_key_exists($count, $this->submission[$root]) ? $this->submission[$root][$count] : [];
|
||||||
|
$this->submission[$root][$count][$field->fieldTitle] = $this->generateFieldValue($field->fieldType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
private function generateFieldValue(string $type)
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
switch ($type) {
|
||||||
|
default:
|
||||||
|
throw new RuntimeException(sprintf('Cannot handle field "%s"', $type));
|
||||||
|
case 'uuid':
|
||||||
|
return $faker->uuid;
|
||||||
|
case 'static-asset':
|
||||||
|
return 'asset';
|
||||||
|
case 'random-asset-accountRole':
|
||||||
|
return $faker->randomElement(['defaultAsset', 'savingsAsset']);
|
||||||
|
case 'random-transactionType':
|
||||||
|
return $faker->randomElement(['withdrawal', 'deposit', 'transfer']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
tests/Objects/TestMandatoryField.php
Normal file
20
tests/Objects/TestMandatoryField.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tests\Objects;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TestMandatoryField
|
||||||
|
*/
|
||||||
|
class TestMandatoryField
|
||||||
|
{
|
||||||
|
public string $title;
|
||||||
|
public string $fieldTitle;
|
||||||
|
public string $fieldPosition;
|
||||||
|
public string $fieldType;
|
||||||
|
public string $expectedReturnType;
|
||||||
|
public ?Closure $expectedReturn;
|
||||||
|
public ?array $ignorableFields;
|
||||||
|
|
||||||
|
}
|
28
tests/Objects/TestMandatoryFieldSet.php
Normal file
28
tests/Objects/TestMandatoryFieldSet.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tests\Objects;
|
||||||
|
|
||||||
|
|
||||||
|
class TestMandatoryFieldSet
|
||||||
|
{
|
||||||
|
public string $title;
|
||||||
|
public ?array $mandatoryFields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestMandatoryFieldSet constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->mandatoryFields = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TestMandatoryField $field
|
||||||
|
*/
|
||||||
|
public function addMandatoryField(TestMandatoryField $field)
|
||||||
|
{
|
||||||
|
$this->mandatoryFields[] = $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
tests/Objects/TestObject.php
Normal file
16
tests/Objects/TestObject.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tests\Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TestObject
|
||||||
|
*/
|
||||||
|
class TestObject
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user