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

use PHPUnit\Framework\TestCase;

class IndexTest extends TestCase
{
    private $testResultsManager;

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

    public function testFirstPHPCode()
    {
        try {
            $testCase = get_class($this) . '.' . __FUNCTION__;

            ob_start();
            include_once './apps/index.php';
            $output = ob_get_clean();
            $dom = new DOMDocument();
            $dom->loadHTML($output);
            $content = $dom->textContent;
            $expectedMessage = "Hello World!";
            $this->assertEquals($expectedMessage, $content, 'No text found "Hello World!"');
            $this->testResultsManager->showTestResult($testCase);
        } catch (\Throwable $e) {
            $this->testResultsManager->showTestResult($testCase, $e);
            throw $e;
        }
    }
}
