Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117746666
D4163.1775173720.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D4163.1775173720.diff
View Options
diff --git a/src/app/Console/Commands/Wallet/TransactionsCommand.php b/src/app/Console/Commands/Wallet/TransactionsCommand.php
--- a/src/app/Console/Commands/Wallet/TransactionsCommand.php
+++ b/src/app/Console/Commands/Wallet/TransactionsCommand.php
@@ -11,7 +11,7 @@
*
* @var string
*/
- protected $signature = 'wallet:transactions {--detail} {wallet}';
+ protected $signature = 'wallet:transactions {--detail} {--balance} {wallet}';
/**
* The console command description.
@@ -34,7 +34,15 @@
return 1;
}
- $wallet->transactions()->orderBy('created_at')->each(function ($transaction) {
+ $withDetail = $this->option('detail');
+ $balanceMode = $this->option('balance');
+ $balance = 0;
+
+ $transactions = $wallet->transactions()->orderBy('created_at')->cursor();
+
+ foreach ($transactions as $transaction) {
+ $balance += $transaction->amount;
+
$this->info(
sprintf(
"%s: %s %s",
@@ -42,9 +50,10 @@
$transaction->created_at,
$transaction->toString()
)
+ . ($balanceMode ? sprintf(' (balance: %s)', $wallet->money($balance)) : '')
);
- if ($this->option('detail')) {
+ if ($withDetail) {
$elements = \App\Transaction::where('transaction_id', $transaction->id)
->orderBy('created_at')->get();
@@ -58,6 +67,6 @@
);
}
}
- });
+ }
}
}
diff --git a/src/tests/Feature/Console/Wallet/TransactionsTest.php b/src/tests/Feature/Console/Wallet/TransactionsTest.php
--- a/src/tests/Feature/Console/Wallet/TransactionsTest.php
+++ b/src/tests/Feature/Console/Wallet/TransactionsTest.php
@@ -6,8 +6,61 @@
class TransactionsTest extends TestCase
{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('test-user1@kolabnow.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('test-user1@kolabnow.com');
+
+ parent::tearDown();
+ }
+
public function testHandle(): void
{
- $this->markTestIncomplete();
+ $user = $this->getTestUser('test-user1@kolabnow.com');
+ $wallet = $user->wallets()->first();
+
+ // Non-existing wallet
+ $code = \Artisan::call("wallet:transactions 123");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("Wallet not found.", $output);
+
+ // Empty wallet
+ $code = \Artisan::call("wallet:transactions {$wallet->id}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+
+ // Non-Empty wallet
+ $this->createTestTransactions($wallet);
+ $code = \Artisan::call("wallet:transactions {$wallet->id}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertCount(12, explode("\n", $output));
+
+ // With --detail and --balance
+ $code = \Artisan::call("wallet:transactions --detail --balance {$wallet->id}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertCount(12, explode("\n", $output));
+ $this->assertStringContainsString('(balance: 20,00 CHF)', $output);
+
+ // TODO: Add and test some detail sub-transactions
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 2, 11:48 PM (11 h, 45 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821564
Default Alt Text
D4163.1775173720.diff (3 KB)
Attached To
Mode
D4163: Fix wallet:transactions and add --balance option
Attached
Detach File
Event Timeline