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>
|
||||
<testsuites>
|
||||
<testsuite name="Api">
|
||||
<directory suffix="Test.php">./tests/Api/Models/PiggyBank</directory>
|
||||
<directory suffix="Test.php">./tests/Api/Models</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
|
@ -81,11 +81,6 @@ class StoreControllerTest extends TestCase
|
||||
$minimalSets = $this->minimalSets();
|
||||
$optionalSets = $this->optionalSets();
|
||||
$regenConfig = [
|
||||
'title' => function () {
|
||||
$faker = Factory::create();
|
||||
|
||||
return $faker->uuid;
|
||||
},
|
||||
'transactions' => [
|
||||
[
|
||||
'description' => function () {
|
||||
@ -118,7 +113,6 @@ class StoreControllerTest extends TestCase
|
||||
$set[] = [
|
||||
'parameters' => [],
|
||||
'fields' => [
|
||||
// not even required but OK.
|
||||
'error_if_duplicate_hash' => $faker->boolean,
|
||||
'transactions' => [
|
||||
[
|
||||
@ -144,24 +138,77 @@ class StoreControllerTest extends TestCase
|
||||
private function optionalSets(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
return [
|
||||
'title' => [
|
||||
$set = [
|
||||
'transactions_currency_id' => [
|
||||
'fields' => [
|
||||
'title' => $faker->uuid,
|
||||
'transactions' => [
|
||||
// first entry, set field:
|
||||
[
|
||||
'currency_id' => $faker->numberBetween(1, 1),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'order' => [
|
||||
'transactions_currency_code' => [
|
||||
'fields' => [
|
||||
'order' => $faker->numberBetween(1, 2),
|
||||
'transactions' => [
|
||||
// first entry, set field:
|
||||
[
|
||||
'currency_code' => $faker->randomElement(['EUR']),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'active' => [
|
||||
// category id
|
||||
'category_id' => [
|
||||
'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:
|
||||
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])) {
|
||||
$message = sprintf(
|
||||
@ -282,11 +282,12 @@ trait TestHelpers
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $fullOriginal
|
||||
* @param string $key
|
||||
* @param array $original
|
||||
* @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'];
|
||||
foreach ($returned as $objectKey => $object) {
|
||||
@ -303,8 +304,10 @@ trait TestHelpers
|
||||
}
|
||||
if (array_key_exists($returnKey, $original[$objectKey])) {
|
||||
$message = sprintf(
|
||||
'Sub: sub-array "%s" returned value %s does not match sent X value %s.',
|
||||
$key, var_export($returnValue, true), var_export($original[$objectKey][$returnKey], true)
|
||||
"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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user