Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F237007
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/app/Console/Commands/Wallet/TransactionsCommand.php b/src/app/Console/Commands/Wallet/TransactionsCommand.php
index 70ad541b..81ab6ee8 100644
--- a/src/app/Console/Commands/Wallet/TransactionsCommand.php
+++ b/src/app/Console/Commands/Wallet/TransactionsCommand.php
@@ -1,63 +1,72 @@
<?php
namespace App\Console\Commands\Wallet;
use App\Console\Command;
class TransactionsCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = 'wallet:transactions {--detail} {wallet}';
+ protected $signature = 'wallet:transactions {--detail} {--balance} {wallet}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List the transactions against a wallet.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
$this->error("Wallet not found.");
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",
$transaction->id,
$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();
foreach ($elements as $element) {
$this->info(
sprintf(
" + %s: %s",
$element->id,
$element->toString()
)
);
}
}
- });
+ }
}
}
diff --git a/src/tests/Feature/Console/Wallet/TransactionsTest.php b/src/tests/Feature/Console/Wallet/TransactionsTest.php
index a837ed9d..12777008 100644
--- a/src/tests/Feature/Console/Wallet/TransactionsTest.php
+++ b/src/tests/Feature/Console/Wallet/TransactionsTest.php
@@ -1,13 +1,66 @@
<?php
namespace Tests\Feature\Console\Wallet;
use Tests\TestCase;
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/x-diff
Expires
Sat, May 17, 2:24 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
178377
Default Alt Text
(4 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment