Skip to content

Firefly III: a personal finances manager

Merge branch 'develop' into feature/ci

James Cole8a91618f8dad
diff --cc composer.json
index b18c54df23,464c83f5f2..2bc916b00a
--- a/composer.json
+++ b/composer.json
@@@ -108,13 -107,9 +108,13 @@@
"fzaninotto/faker": "1.*",
"johnkary/phpunit-speedtrap": "^3.1",
"mockery/mockery": "1.*",
+ "nunomaduro/larastan": "^0.6.1",
+ "phpstan/phpstan": "^0.12.33",
+ "phpstan/phpstan-deprecation-rules": "^0.12.5",
- "phpunit/phpunit": "^8.5",
+ "phpunit/phpunit": "^9.2",
"psalm/plugin-laravel": "^1.1",
"roave/security-advisories": "dev-master",
+ "thecodingmachine/phpstan-strict-rules": "^0.12.0",
"vimeo/psalm": "^3.10"
},
"suggest": {
diff --cc composer.lock
index 0ec1200d9b,78d7d15c8c..ee42bb0115
--- a/composer.lock
+++ b/composer.lock
@@@ -4,7 -4,7 +4,8 @@@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d2251a23c0f09e4125a1c87d23e25104",
++
+ "content-hash": "4b5202505732cec5b0a2f9d2fa43e939",
"packages": [
{
"name": "adldap2/adldap2",
@@@ -8488,116 -8388,9 +8628,116 @@@
],
"time": "2020-07-08T12:44:21+00:00"
},
+ {
+ "name": "phpstan/phpstan",
+ "version": "0.12.33",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan.git",
+ "reference": "46e698a0452526a05c4a351d7c47c4b8c37a548d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e698a0452526a05c4a351d7c47c4b8c37a548d",
+ "reference": "46e698a0452526a05c4a351d7c47c4b8c37a548d",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1|^8.0"
+ },
+ "conflict": {
+ "phpstan/phpstan-shim": "*"
+ },
+ "bin": [
+ "phpstan",
+ "phpstan.phar"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.12-dev"
+ }
+ },
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan - PHP Static Analysis Tool",
+ "funding": [
+ {
+ "url": "https://github.com/ondrejmirtes",
+ "type": "github"
+ },
+ {
+ "url": "https://www.patreon.com/phpstan",
+ "type": "patreon"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2020-07-19T22:10:11+00:00"
+ },
+ {
+ "name": "phpstan/phpstan-deprecation-rules",
+ "version": "0.12.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
+ "reference": "bfabc6a1b4617fbcbff43f03a4c04eae9bafae21"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/bfabc6a1b4617fbcbff43f03a4c04eae9bafae21",
+ "reference": "bfabc6a1b4617fbcbff43f03a4c04eae9bafae21",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1 || ^8.0",
+ "phpstan/phpstan": "^0.12.26"
+ },
+ "require-dev": {
+ "consistence/coding-standard": "^3.0.1",
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
+ "ergebnis/composer-normalize": "^2.0.2",
+ "jakub-onderka/php-parallel-lint": "^1.0",
+ "phing/phing": "^2.16.0",
+ "phpstan/phpstan-phpunit": "^0.12",
+ "phpunit/phpunit": "^7.0",
+ "slevomat/coding-standard": "^4.5.2"
+ },
+ "type": "phpstan-extension",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.12-dev"
+ },
+ "phpstan": {
+ "includes": [
+ "rules.neon"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "PHPStan\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
+ "time": "2020-07-21T14:52:30+00:00"
+ },
{
"name": "phpunit/php-code-coverage",
- "version": "7.0.10",
+ "version": "8.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
diff --cc tests/TestCase.php
index 10997245ab,c07f2814bb..ceb7e0842b
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@@ -511,309 -51,4 +51,5 @@@ abstract class TestCase extends BaseTes
'custom range' => ['custom'],
];
}
+
- /**
- * @return User
- */
- public function demoUser(): User
- {
- return User::where('email', 'demo@firefly')->first();
- }
-
- /**
- * @return User
- */
- public function emptyUser(): User
- {
- return User::find(2);
- }
-
- use CreatesApplication;
-
- /**
- * @param int|null $except
- *
- * @return Account
- */
- public function getRandomAsset(?int $except = null): Account
- {
- return $this->getRandomAccount(AccountType::ASSET, $except);
- }
-
- /**
- * @return TransactionJournal
- */
- public function getRandomDeposit(): TransactionJournal
- {
- return $this->getRandomJournal(TransactionType::DEPOSIT, null);
- }
-
- /**
- * @return Account
- */
- public function getRandomExpense(): Account
- {
- return $this->getRandomAccount(AccountType::EXPENSE, null);
- }
-
- /**
- * @return Account
- */
- public function getRandomInitialBalance(): Account
- {
- return $this->getRandomAccount(AccountType::INITIAL_BALANCE, null);
- }
-
- public function getRandomReconciliation(): Account
- {
- return $this->getRandomAccount(AccountType::RECONCILIATION, null);
- }
-
- /**
- * @return Account
- */
- public function getRandomLoan(): Account
- {
- return $this->getRandomAccount(AccountType::LOAN, null);
- }
-
- /**
- * @return Account
- */
- public function getRandomRevenue(): Account
- {
- return $this->getRandomAccount(AccountType::REVENUE, null);
- }
-
- /**
- * @return TransactionJournal
- */
- public function getRandomSplitWithdrawal(): TransactionJournal
- {
- return $this->getRandomSplitJournal(TransactionType::WITHDRAWAL);
- }
-
- /**
- * @return TransactionJournal
- */
- public function getRandomTransfer(): TransactionJournal
- {
- return $this->getRandomJournal(TransactionType::TRANSFER);
- }
-
- /**
- * @return TransactionJournal
- */
- public function getRandomWithdrawal(): TransactionJournal
- {
- return $this->getRandomJournal(TransactionType::WITHDRAWAL);
- }
-
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- }
-
- /**
- * @return User
- */
- public function user(): User
- {
- if (getenv('CI') === 'true') {
- self::markTestIncomplete("Database is not been populated for tests. This may fail in CI.");
- }
- return User::find(1);
- }
-
- /**
- * @return Budget
- */
- protected function getBudget(): Budget
- {
- return $this->user()->budgets()->inRandomOrder()->first();
- }
-
- /**
- * @return TransactionCurrency
- */
- protected function getEuro(): TransactionCurrency
- {
- return TransactionCurrency::where('code', 'EUR')->first();
- }
-
- /**
- * @return TransactionCurrency
- */
- protected function getDollar(): TransactionCurrency
- {
- return TransactionCurrency::where('code', 'USD')->first();
- }
-
- /**
- * @return TransactionGroup
- */
- protected function getRandomWithdrawalGroup(): TransactionGroup
- {
- return $this->getRandomGroup(TransactionType::WITHDRAWAL);
- }
-
- /**
- * @return TransactionGroup
- */
- protected function getRandomTransferGroup(): TransactionGroup
- {
- return $this->getRandomGroup(TransactionType::TRANSFER);
- }
-
- /**
- * @return TransactionGroup
- */
- protected function getRandomDepositGroup(): TransactionGroup
- {
- return $this->getRandomGroup(TransactionType::DEPOSIT);
- }
-
- /**
- * @param string $class
- *
- * @param Closure|null $closure
- *
- * @return \Mockery\MockInterface
- */
- protected function mock($class, Closure $closure = null): \Mockery\MockInterface
- {
- $deprecated = [
- TransactionTransformer::class,
- TransactionCollectorInterface::class,
- ];
- if (in_array($class, $deprecated, true)) {
- throw new RuntimeException(strtoupper('Must not be mocking the transaction collector or transformer.'));
- }
- //Log::debug(sprintf('Will now mock %s', $class));
- $object = Mockery::mock($class);
- $this->app->instance($class, $object);
-
- return $object;
- }
-
- /**
- * @param string $class
- *
- * @return Mockery\MockInterface
- */
- protected function overload(string $class): \Mockery\MockInterface
- {
- //$this->app->instance($class, $externalMock);
- return Mockery::mock('overload:' . $class);
- }
-
- /**
- * @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);
- }
- $result = $query->first(['accounts.*']);
-
- return $result;
- }
-
- /**
- * @param string $type
- *
- * @return TransactionGroup
- */
- private function getRandomGroup(string $type): TransactionGroup
- {
- $transactionType = TransactionType::where('type', $type)->first();
-
- // make sure it's a single count group
- do {
- $journal = $this->user()->transactionJournals()
- ->where('transaction_type_id', $transactionType->id)->inRandomOrder()->first();
- /** @var TransactionGroup $group */
- $group = $journal->transactionGroup;
- $count = 0;
- if (null !== $group) {
- $count = $group->transactionJournals()->count();
- }
- } while (1 !== $count);
-
- return $journal->transactionGroup;
- }
-
- /**
- * @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_journalstransaction_type_id',
- DB::raw('COUNT(transaction_journal_id) as ct'),
- ]
- )->first();
- if (null === $result) {
- throw new FireflyException(sprintf('Cannot find suitable %s to use.', $type));
- }
-
- return TransactionJournal::find((int)$result->transaction_journal_id);
- }
-
- /**
- * @param string $type
- *
- * @return TransactionJournal
- */
- private function getRandomSplitJournal(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_journalstransaction_type_id',
- DB::raw('COUNT(transaction_journal_id) as ct'),
- ]
- )->first();
-
- return TransactionJournal::find((int)$result->transaction_journal_id);
- }
}