<?php

use Tests\Support\DatabaseTestCase;

class ReportTest extends DatabaseTestCase
{
    protected $migrate     = false;
    protected $refresh     = false;
    protected $db;

    protected function setUp(): void
    {
        parent::setUp();
        $this->db = \Config\Database::connect();
    }

    public function testReportHelperInitialization()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        $this->assertInstanceOf(\App\Libraries\ReportHelper::class, $helper);
    }

    public function testCutDataFunction()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        
        $shortText = "This is short";
        $result = $this->invokeMethod($helper, 'cutData', [$shortText]);
        $this->assertEquals($shortText, $result);
        
        $longText = "This is a very long text that should be cut into two parts because it exceeds ninety five characters in total length";
        $result = $this->invokeMethod($helper, 'cutData', [$longText]);
        $this->assertStringContainsString("\r\n", $result);
    }

    public function testGetHost()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        $result = $this->invokeMethod($helper, 'getHost', ['INVALID123']);
        $this->assertIsString($result);
    }

    public function testGetNotes()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        $result = $this->invokeMethod($helper, 'getNotes', ['INVALID123']);
        $this->assertIsString($result);
    }

    public function testGetStatus()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        $result = $this->invokeMethod($helper, 'getStatus', ['INVALID123']);
        $this->assertIsString($result);
    }

    public function testGetValBy()
    {
        $helper = new \App\Libraries\ReportHelper($this->db);
        $result = $this->invokeMethod($helper, 'getValBy', ['INVALID123']);
        $this->assertIsString($result);
    }

    protected function invokeMethod(&$object, $methodName, array $parameters = [])
    {
        $reflection = new \ReflectionClass(get_class($object));
        $method = $reflection->getMethod($methodName);
        $method->setAccessible(true);
        return $method->invokeArgs($object, $parameters);
    }
}
