<?php
require_once __DIR__ . '/helper/TestResultsManager.php';

use PHPUnit\Framework\TestCase;

class ProsesFormEmailTest extends TestCase
{
    private $testResultsManager;

    protected function setUp(): void
    {
        $this->testResultsManager = new TestResultsManager();
    }

    public function testSuccessfulSubmission()
    {
        try {
            $testCase = get_class($this) . '.' . __FUNCTION__;
            $_GET['yourname'] = 'Aliyya Putri S';
            $_GET['youremail'] = 'example@gmail.com';

            ob_start();

            include './apps/prosesFormEmail.php';

            $output = ob_get_clean();

            $dom = new DOMDocument();
            $dom->loadHTML($output);

            $this->assertStringContainsString('Your Name: Aliyya Putri S', $dom->textContent);
            $this->assertStringContainsString('Your Email: example@gmail.com', $dom->textContent);
            $this->testResultsManager->showTestResult($testCase);
        } catch (\Throwable $e) {
            $this->testResultsManager->showTestResult($testCase, $e);
            throw $e;
        }
    }
}
