mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
First run of all tests
This commit is contained in:
parent
eb90dac89d
commit
657726e667
@ -53,6 +53,8 @@ class UpdateController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*
|
||||
* TODO generates query exception when link exists.
|
||||
*/
|
||||
public function update(UpdateRequest $request, TransactionJournalLink $journalLink): JsonResponse
|
||||
{
|
||||
|
65
phpunit.xml
65
phpunit.xml
@ -29,36 +29,39 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Api">
|
||||
<!--
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Api">
|
||||
<!--
|
||||
-->
|
||||
|
||||
<directory suffix="Test.php">./tests/Api/Models/Account</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/AvailableBudget</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Bill</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Budget</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/BudgetLimit</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Category</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/ObjectGroup</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/PiggyBank</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Recurrence</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Rule</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/RuleGroup</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Tag</directory>
|
||||
-->
|
||||
<directory suffix="Test.php">./tests/Api/Models/Transaction</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<env name="QUEUE_DRIVER" value="sync"/>
|
||||
</php>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Account</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/AvailableBudget</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Bill</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Budget</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/BudgetLimit</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Category</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/ObjectGroup</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/PiggyBank</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Recurrence</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Rule</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/RuleGroup</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Tag</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/Transaction</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/TransactionCurrency</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/TransactionLink</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models/TransactionLinkType</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<env name="QUEUE_DRIVER" value="sync"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
@ -25,6 +25,9 @@ namespace Tests\Api\Models\TransactionCurrency;
|
||||
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;
|
||||
|
||||
@ -61,72 +64,41 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'code' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return substr($faker->uuid, 0, 3);
|
||||
},
|
||||
'name' => function () {
|
||||
$faker = Factory::create();
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_object';
|
||||
$defaultSet->addField(Field::createBasic('code', 'random-new-currency-code'));
|
||||
$defaultSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('symbol', 'random-new-currency-symbol'));
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
'symbol' => function () {
|
||||
$faker = Factory::create();
|
||||
// 'code' => substr($faker->uuid, 0, 3),
|
||||
// 'name' => $faker->uuid,
|
||||
// 'symbol' => $faker->randomAscii . $faker->randomAscii,
|
||||
|
||||
return $faker->randomAscii . $faker->randomAscii;
|
||||
},
|
||||
];
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
}
|
||||
// optionals
|
||||
$fieldSet = new FieldSet;
|
||||
$field = Field::createBasic('enabled', 'boolean');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('enabled', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$fieldSet = new FieldSet;
|
||||
$field = Field::createBasic('default', 'boolean');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('default', $fieldSet);
|
||||
|
||||
return [
|
||||
'default_currency' => [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'code' => substr($faker->uuid, 0, 3),
|
||||
'name' => $faker->uuid,
|
||||
'symbol' => $faker->randomAscii . $faker->randomAscii,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
$fieldSet = new FieldSet;
|
||||
$field = Field::createBasic('decimal_places', 'currency-dp');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('decimal_places', $fieldSet);
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'enabled' => [
|
||||
'fields' => [
|
||||
'enabled' => $faker->boolean,
|
||||
],
|
||||
],
|
||||
'default' => [
|
||||
'fields' => [
|
||||
'default' => $faker->boolean,
|
||||
],
|
||||
],
|
||||
'decimal_places' => [
|
||||
'fields' => [
|
||||
'decimal_places' => $faker->numberBetween(1, 6),
|
||||
],
|
||||
],
|
||||
];
|
||||
return $configuration->generateAll();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,10 +111,15 @@ class StoreControllerTest extends TestCase
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.currencies.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
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.currencies.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,9 @@ namespace Tests\Api\Models\TransactionCurrency;
|
||||
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;
|
||||
|
||||
@ -53,13 +56,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.currencies.update', [$submission['id']]);
|
||||
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']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.currencies.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@ -68,13 +75,43 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$fieldSet->addField(Field::createBasic('symbol', 'random-new-currency-symbol'));
|
||||
$configuration->addOptionalFieldSet('symbol', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$field = Field::createBasic('enabled', 'boolean');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('enabled', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$field = Field::createBasic('default', 'boolean-true');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('default', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$field = Field::createBasic('decimal_places', 'currency-dp');
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('decimal_places', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = ['RMB'];
|
||||
$fieldSet->addField(Field::createBasic('symbol', 'random-new-currency-code'));
|
||||
$configuration->addOptionalFieldSet('code', $fieldSet);
|
||||
|
||||
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,9 @@ namespace Tests\Api\Models\TransactionLink;
|
||||
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;
|
||||
|
||||
@ -61,66 +64,33 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'inward_id' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return (string)$faker->numberBetween(1, 10);
|
||||
},
|
||||
'outward_id' => function () {
|
||||
$faker = Factory::create();
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_object';
|
||||
$defaultSet->addField(Field::createBasic('link_type_id', 'random-link-type-id'));
|
||||
$defaultSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
|
||||
$defaultSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return (string)$faker->numberBetween(11, 20);
|
||||
},
|
||||
];
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_object_name';
|
||||
$defaultSet->addField(Field::createBasic('link_type_name', 'random-link-type-name'));
|
||||
$defaultSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
|
||||
$defaultSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
// optionals
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'default_link_id' => [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'link_type_id' => (string)$faker->numberBetween(1, 4),
|
||||
'inward_id' => (string)$faker->numberBetween(1, 10),
|
||||
'outward_id' => (string)$faker->numberBetween(11, 20),
|
||||
],
|
||||
],
|
||||
'default_link_name' => [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'link_type_name' => 'Related',
|
||||
'inward_id' => (string)$faker->numberBetween(1, 10),
|
||||
'outward_id' => (string)$faker->numberBetween(11, 20),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'notes' => [
|
||||
'fields' => [
|
||||
'notes' => join(' ', $faker->words(5)),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submission
|
||||
@ -132,10 +102,17 @@ class StoreControllerTest extends TestCase
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.transaction_links.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
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.transaction_links.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -22,12 +22,13 @@
|
||||
namespace Tests\Api\Models\TransactionLink;
|
||||
|
||||
|
||||
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\TestHelpers;
|
||||
|
||||
/**
|
||||
@ -53,13 +54,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.transaction_links.update', [$submission['id']]);
|
||||
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']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.transaction_links.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@ -68,61 +73,44 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $submissions;
|
||||
}
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
|
||||
$field = Field::createBasic('link_type_id', 'random-link-type-id');
|
||||
$field->ignorableFields = ['link_type_name'];
|
||||
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('link_type_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
|
||||
$field = Field::createBasic('link_type_name', 'random-link-type-name');
|
||||
$field->ignorableFields = ['link_type_id'];
|
||||
|
||||
$fieldSet->addField($field);
|
||||
$configuration->addOptionalFieldSet('link_type_name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
|
||||
$configuration->addOptionalFieldSet('inward_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
|
||||
$configuration->addOptionalFieldSet('outward_id', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$set = [
|
||||
'link_type_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'link_type_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
|
||||
],
|
||||
'extra_ignore' => ['link_type_name'],
|
||||
],
|
||||
'link_type_name' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'link_type_name' => ['test_value' => 'Refund'],
|
||||
],
|
||||
'extra_ignore' => ['link_type_id'],
|
||||
],
|
||||
'inward_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'inward_id' => ['test_value' => (string)$faker->numberBetween(11, 20)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'outward_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'outward_id' => ['test_value' => (string)$faker->numberBetween(11, 30)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'notes' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
];
|
||||
return $configuration->generateAll();
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,9 @@ namespace Tests\Api\Models\TransactionLinkType;
|
||||
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;
|
||||
|
||||
@ -61,57 +64,19 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'name' => function () {
|
||||
$faker = Factory::create();
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
'inward' => function () {
|
||||
$faker = Factory::create();
|
||||
// default test set:
|
||||
$defaultSet = new FieldSet();
|
||||
$defaultSet->title = 'default_object';
|
||||
$defaultSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('inward', 'uuid'));
|
||||
$defaultSet->addField(Field::createBasic('outward', 'uuid'));
|
||||
$configuration->addMandatoryFieldSet($defaultSet);
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
'outward' => function () {
|
||||
$faker = Factory::create();
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
];
|
||||
|
||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function minimalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'default_link_type' => [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
'name' => $faker->uuid,
|
||||
'inward' => $faker->uuid,
|
||||
'outward' => $faker->uuid,
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
private function optionalSets(): array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
return $configuration->generateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,11 +88,17 @@ class StoreControllerTest extends TestCase
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty data provider');
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
$route = 'api.v1.link_types.store';
|
||||
$this->storeAndCompare($route, $submission);
|
||||
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.link_types.store');
|
||||
$this->assertPOST($address, $submission);
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,9 @@ namespace Tests\Api\Models\TransactionLinkType;
|
||||
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;
|
||||
|
||||
@ -53,13 +56,17 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
$route = route('api.v1.link_types.update', [$submission['id']]);
|
||||
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']);
|
||||
|
||||
$this->updateAndCompare($route, $submission, $ignore);
|
||||
$route = route('api.v1.link_types.update', $submission['parameters']);
|
||||
$this->assertPUT($route, $submission);
|
||||
}
|
||||
|
||||
|
||||
@ -68,48 +75,24 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
}
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [5];
|
||||
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [5];
|
||||
$fieldSet->addField(Field::createBasic('inward', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('inward', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [5];
|
||||
$fieldSet->addField(Field::createBasic('outward', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('outward', $fieldSet);
|
||||
|
||||
return $configuration->generateAll();
|
||||
|
||||
return $submissions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$set = [
|
||||
'name' => [
|
||||
'id' => 5,
|
||||
'fields' => [
|
||||
'name' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'inward' => [
|
||||
'id' => 5,
|
||||
'fields' => [
|
||||
'inward' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'outward' => [
|
||||
'id' => 5,
|
||||
'fields' => [
|
||||
'outward' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -67,7 +67,7 @@ class TestConfiguration
|
||||
$positions = explode('/', $value);
|
||||
$count = count($positions);
|
||||
if (1 === $count) {
|
||||
$updated[$key] = $updated[$key] ? $updated[$key] : $value;
|
||||
$updated[$key] = array_key_exists($key, $updated) ? $updated[$key] : $value;
|
||||
continue;
|
||||
}
|
||||
if (3 === $count) {
|
||||
@ -286,6 +286,7 @@ class TestConfiguration
|
||||
if (is_array($value) && !array_key_exists($key, $left)) {
|
||||
$this->debugMsg(sprintf('Key %s exists in right only, keep it as it is.', $key));
|
||||
$result[$key] = $right[$key];
|
||||
continue;
|
||||
}
|
||||
// value is not an array, can be appended to result (ignore the key):
|
||||
$this->debugMsg(sprintf('Key %s is a string (%s), just append it and return it later.', $key, $value));
|
||||
@ -401,6 +402,14 @@ class TestConfiguration
|
||||
return $faker->randomElement(['loan', 'debt', 'mortgage']);
|
||||
case 'random-journal-id':
|
||||
return $faker->numberBetween(1, 25);
|
||||
case 'random-low-journal-id':
|
||||
return $faker->numberBetween(1, 9);
|
||||
case 'random-high-journal-id':
|
||||
return $faker->numberBetween(10, 20);
|
||||
case 'random-link-type-id':
|
||||
return $faker->numberBetween(1, 4);
|
||||
case 'random-link-type-name':
|
||||
return $faker->randomElement(['Related', 'Refund', 'Paid', 'Reimbursement']);
|
||||
case 'random-amount':
|
||||
return number_format($faker->randomFloat(2, 10, 100), 2);
|
||||
case 'random-percentage':
|
||||
@ -423,6 +432,8 @@ class TestConfiguration
|
||||
return $faker->randomElement(['withdrawal', 'deposit', 'transfer']);
|
||||
case 'boolean':
|
||||
return $faker->boolean;
|
||||
case 'boolean-true':
|
||||
return true;
|
||||
case 'iban':
|
||||
case 'account_number':
|
||||
return $faker->iban();
|
||||
@ -505,6 +516,12 @@ class TestConfiguration
|
||||
return $faker->randomElement(['set_category', 'add_tag', 'set_description']);
|
||||
case 'random-rule-group-title':
|
||||
return $faker->randomElement(['Rule group 1', 'Rule group 2']);
|
||||
case 'random-new-currency-code':
|
||||
return $faker->randomLetter . $faker->randomLetter . $faker->randomLetter;
|
||||
case 'random-new-currency-symbol':
|
||||
return $faker->randomAscii . $faker->randomAscii;
|
||||
case 'currency-dp':
|
||||
return $faker->numberBetween(0, 11);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user