File: //var/www/payments-gateway/tests/PaymentControllerTest.php
<?php
namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PaymentControllerTest extends WebTestCase
{
public function testInitiatePayment(): void
{
$client = static::createClient();
$payload = [
'order_reference' => 'TEST123456',
'student_id' => 'STU123',
'amount' => 1000,
'redirect_url' => 'https://example.com/return',
'cancel_url' => 'https://example.com/cancel',
'student_email' => 'student@example.com'
];
$client->request('POST', '/api/payment/initiate', [], [], [
'CONTENT_TYPE' => 'application/json'
], json_encode($payload));
$this->assertResponseIsSuccessful();
$this->assertJson($client->getResponse()->getContent());
$data = json_decode($client->getResponse()->getContent(), true);
dump($data['payment_link']);
$this->assertArrayHasKey('payment_link', $data);
$this->assertStringStartsWith('http', $data['payment_link']);
}
}