mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Most model tests now working.
This commit is contained in:
parent
beece4dcbb
commit
5eb1f93851
@ -36,7 +36,7 @@
|
|||||||
</coverage>
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Api">
|
<testsuite name="Api">
|
||||||
<directory suffix="Test.php">./tests/Api/Models/PiggyBank</directory>
|
<directory suffix="Test.php">./tests/Api/Models</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<php>
|
<php>
|
||||||
|
@ -81,11 +81,6 @@ class StoreControllerTest extends TestCase
|
|||||||
$minimalSets = $this->minimalSets();
|
$minimalSets = $this->minimalSets();
|
||||||
$optionalSets = $this->optionalSets();
|
$optionalSets = $this->optionalSets();
|
||||||
$regenConfig = [
|
$regenConfig = [
|
||||||
'title' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return $faker->uuid;
|
|
||||||
},
|
|
||||||
'transactions' => [
|
'transactions' => [
|
||||||
[
|
[
|
||||||
'description' => function () {
|
'description' => function () {
|
||||||
@ -118,7 +113,6 @@ class StoreControllerTest extends TestCase
|
|||||||
$set[] = [
|
$set[] = [
|
||||||
'parameters' => [],
|
'parameters' => [],
|
||||||
'fields' => [
|
'fields' => [
|
||||||
// not even required but OK.
|
|
||||||
'error_if_duplicate_hash' => $faker->boolean,
|
'error_if_duplicate_hash' => $faker->boolean,
|
||||||
'transactions' => [
|
'transactions' => [
|
||||||
[
|
[
|
||||||
@ -144,24 +138,77 @@ class StoreControllerTest extends TestCase
|
|||||||
private function optionalSets(): array
|
private function optionalSets(): array
|
||||||
{
|
{
|
||||||
$faker = Factory::create();
|
$faker = Factory::create();
|
||||||
|
$set = [
|
||||||
return [
|
'transactions_currency_id' => [
|
||||||
'title' => [
|
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'title' => $faker->uuid,
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
'currency_id' => $faker->numberBetween(1, 1),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'order' => [
|
],
|
||||||
|
],
|
||||||
|
'transactions_currency_code' => [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'order' => $faker->numberBetween(1, 2),
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
'currency_code' => $faker->randomElement(['EUR']),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'active' => [
|
],
|
||||||
|
],
|
||||||
|
// category id
|
||||||
|
'category_id' => [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'active' => $faker->boolean,
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
'category_id' => '1',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// reconciled
|
||||||
|
'reconciled' => [
|
||||||
|
'fields' => [
|
||||||
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
'reconciled' => $faker->boolean,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// tags
|
||||||
|
'tags' => [
|
||||||
|
'fields' => [
|
||||||
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
'tags' => ['a', 'b', 'c'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$extra = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
|
||||||
|
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
|
||||||
|
foreach ($extra as $key) {
|
||||||
|
$set[$key] = [
|
||||||
|
'fields' => [
|
||||||
|
'transactions' => [
|
||||||
|
// first entry, set field:
|
||||||
|
[
|
||||||
|
$key => $faker->uuid,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -267,7 +267,7 @@ trait TestHelpers
|
|||||||
}
|
}
|
||||||
// check if is array, if so we need something smart:
|
// check if is array, if so we need something smart:
|
||||||
if (is_array($returnValue) && is_array($submission[$returnName])) {
|
if (is_array($returnValue) && is_array($submission[$returnName])) {
|
||||||
$this->compareArray($returnName, $submission[$returnName], $returnValue);
|
$this->compareArray($submission, $returnName, $submission[$returnName], $returnValue);
|
||||||
}
|
}
|
||||||
if (!is_array($returnValue) && !is_array($submission[$returnName])) {
|
if (!is_array($returnValue) && !is_array($submission[$returnName])) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
@ -282,11 +282,12 @@ trait TestHelpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array $fullOriginal
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param array $original
|
* @param array $original
|
||||||
* @param array $returned
|
* @param array $returned
|
||||||
*/
|
*/
|
||||||
protected function compareArray(string $key, array $original, array $returned)
|
protected function compareArray(array $fullOriginal, string $key, array $original, array $returned)
|
||||||
{
|
{
|
||||||
$ignore = ['id', 'created_at', 'updated_at'];
|
$ignore = ['id', 'created_at', 'updated_at'];
|
||||||
foreach ($returned as $objectKey => $object) {
|
foreach ($returned as $objectKey => $object) {
|
||||||
@ -303,8 +304,10 @@ trait TestHelpers
|
|||||||
}
|
}
|
||||||
if (array_key_exists($returnKey, $original[$objectKey])) {
|
if (array_key_exists($returnKey, $original[$objectKey])) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'Sub: sub-array "%s" returned value %s does not match sent X value %s.',
|
"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)
|
$key, var_export($returnValue, true), var_export($original[$objectKey][$returnKey], true),
|
||||||
|
json_encode($fullOriginal),
|
||||||
|
json_encode($returned),
|
||||||
);
|
);
|
||||||
$this->assertEquals($original[$objectKey][$returnKey], $returnValue, $message);
|
$this->assertEquals($original[$objectKey][$returnKey], $returnValue, $message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user