tests/FileStreamerTest.php
/**
     * Test if the correct data is being served according to the requested ranges.
     *
     * @return void
     */
Test if the correct data is being served according to the requested ranges.
@return void
Test if the correct data is being served according to the requested ranges . @return void
public function testStartMultiRange(): void
    {
        $_SERVER['HTTP_RANGE'] = 'bytes=2-3,5-6,-1';
        $expectedHeaders       = [
            'HTTP/1.1 206 Partial Content',
            'Content-Length: 330',
            'Content-Type: multipart/byteranges; boundary=cafd507eba83d389029d38c0cbe92dc5',
        ];
        $expectedHeaders       = array_merge(self::defaultHeaders, $expectedHeaders);
        $expectedOutput        = <<<'TXT'
--cafd507eba83d389029d38c0cbe92dc5
Content-Type: text/plain
Content-range: bytes 2-3/10
23
--cafd507eba83d389029d38c0cbe92dc5
Content-Type: text/plain
Content-range: bytes 5-6/10
56
--cafd507eba83d389029d38c0cbe92dc5
Content-Type: text/plain
Content-range: bytes 9-9/10
9
--cafd507eba83d389029d38c0cbe92dc5--
TXT;
        $expectedOutput = preg_replace('~\R~u', "\r\n", $expectedOutput);
        $mock = $this->mockFileStreamer();
        try {
            @$mock->start();
            $this->fail();
        } catch (Exception $e) {
            $this->assertSame($expectedOutput, Output::getBody());
            $this->assertSame($expectedHeaders, Output::$headers);
        }
    }
public function testStartMultiRange ( ) : void { $ _SERVER [ 'HTTP_RANGE' ] = 'bytes=2-3,5-6,-1' ; $ expectedHeaders = [ 'HTTP/1.1 206 Partial Content' , 'Content-Length: 330' , 'Content-Type: multipart/byteranges; boundary=cafd507eba83d389029d38c0cbe92dc5' , ] ; $ expectedHeaders = array_merge ( self :: defaultHeaders , $ expectedHeaders ) ; $ expectedOutput = <<< ' TXT ' --cafd507eba83d389029d38c0cbe92dc5 
Content-Type: text/plain 
Content-range: bytes 2-3/10 

23 
--cafd507eba83d389029d38c0cbe92dc5 
Content-Type: text/plain 
Content-range: bytes 5-6/10 

56 
--cafd507eba83d389029d38c0cbe92dc5 
Content-Type: text/plain 
Content-range: bytes 9-9/10 

9 
--cafd507eba83d389029d38c0cbe92dc5-- TXT ; $ expectedOutput = preg_replace ( '~\R~u' , " \r \n " , $ expectedOutput ) ; $ mock = $ this -> mockFileStreamer ( ) ; try { @ $ mock -> start ( ) ; $ this -> fail ( ) ; } catch ( Exception $ e ) { $ this -> assertSame ( $ expectedOutput , Output :: getBody ( ) ) ; $ this -> assertSame ( $ expectedHeaders , Output :: $ headers ) ; } }
Test if the correct data is being served according to the requested ranges.
Test if the correct data is being served according to the requested ranges .
// Ensure the line separators match \r\n. // Get a mocked instance of the class with overridden terminate method. /** @var FileStreamer $mock */ // Suppress warning or method will be aborted.