-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransactionLoggerTest.php
More file actions
71 lines (57 loc) · 2.05 KB
/
Copy pathTransactionLoggerTest.php
File metadata and controls
71 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Bow\Payment\Tests;
use PHPUnit\Framework\TestCase;
use Bow\Payment\Support\TransactionLogger;
class TransactionLoggerTest extends TestCase
{
private $logPath;
private $logger;
protected function setUp(): void
{
$this->logPath = sys_get_temp_dir() . '/test_payment_logs_' . uniqid();
$this->logger = new TransactionLogger($this->logPath, true);
}
protected function tearDown(): void
{
// Clean up log files
if (file_exists($this->logPath)) {
$files = glob($this->logPath . '/*');
foreach ($files as $file) {
unlink($file);
}
rmdir($this->logPath);
}
}
public function testLoggerCreatesDirectory()
{
$this->assertDirectoryExists($this->logPath);
}
public function testLogInfo()
{
$this->logger->info('Test info message', ['key' => 'value']);
$logFile = $this->logPath . '/payment_' . date('Y-m-d') . '.log';
$this->assertFileExists($logFile);
$content = file_get_contents($logFile);
$this->assertStringContainsString('Test info message', $content);
$this->assertStringContainsString('info', $content);
}
public function testLogPaymentRequest()
{
$this->logger->logPaymentRequest('orange', [
'amount' => 1000,
'reference' => 'TEST-123',
]);
$logFile = $this->logPath . '/payment_' . date('Y-m-d') . '.log';
$content = file_get_contents($logFile);
$this->assertStringContainsString('Payment request initiated', $content);
$this->assertStringContainsString('orange', $content);
$this->assertStringContainsString('1000', $content);
}
public function testDisabledLogger()
{
$logger = new TransactionLogger($this->logPath, false);
$logger->info('This should not be logged');
$logFile = $this->logPath . '/payment_' . date('Y-m-d') . '.log';
$this->assertFileDoesNotExist($logFile);
}
}