<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/process/QrbProcessStatusTracker.php';

require_once __DIR__ . '/../../src/storage/QrbStorage.php';
require_once __DIR__ . '/../../src/storage/QrbStorageFactory.php';

use PHPUnit\Framework\TestCase;

final class QrbProcessStatusTrackerTest extends TestCase
{
    private QrbStorage $qrbStorage;
    private string     $expectedNewFile;
    
    protected function setUp() : void
    {
        $this->qrbStorage = new QrbFileStorage();
    }
    
    protected function tearDown() : void
    {
        $this->qrbStorage->deleteData();
    }

    public function testTrackStatus() : void
    {
        $qrbStatusTracker = new QrbProcessStatusTracker();
        
        $this->assertEquals(QrbProcessStatusTracker::NOT_FOUND, 
                            $qrbStatusTracker->trackStatus());
                            
        $qrbStatus = new QrbProcessStatus($this->qrbStorage);
        
        $this->assertEquals(QrbProcessStatusTracker::NOT_FOUND, 
                            $qrbStatusTracker->trackStatus());
                
        $qrbStatus->write("some message");
        
        $this->assertEquals(QrbProcessStatusTracker::GOOD, 
                            $qrbStatusTracker->trackStatus());
        
        $qrbStatus = NULL;  // calls desctructor, which writes EOF marker into status file

        // the first test returns GOOD, as there are still bytes to read (the EOF marker in the status file)
        $this->assertEquals(QrbProcessStatusTracker::GOOD, 
                            $qrbStatusTracker->trackStatus());
        // the second test returns EOF, as the EOF marker is now found in the tracking file
        $this->assertEquals(QrbProcessStatusTracker::EOF, 
                            $qrbStatusTracker->trackStatus());
    }
}

?>
