Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
crazyfactory/jobs / tests / JobResultTest.php
Size: Mime:
<?php

namespace CrazyFactory\JobsTests;


use CrazyFactory\Jobs\JobResult;

class JobResultTest extends \PHPUnit_Framework_TestCase
{
    public function testGetCode() {
        $jobResult = new JobResult(15);
        $this->assertEquals(15, $jobResult->getCode());
    }

    public function testFatal() {
        $jobResult = JobResult::fatal("test");
        $this->assertStringStartsWith("FATAL", $jobResult->getOutput()[0]);
    }

    public function testGetLastParagraph() {
        $jobResult = new JobResult(0, 0,0, ["first", "", "lastA", "inbetween", "lastB", ""]);
        $p = $jobResult->getLastParagraph();
        $this->assertStringStartsWith("lastA", reset($p));
        $this->assertStringEndsWith("lastB", end($p));
    }

    public function testHasOutput() {
        $this->assertTrue((new JobResult(0,0, 0, ["foo"]))->hasOutput());
        $this->assertFalse((new JobResult(0,0, 0, []))->hasOutput());
    }

    public function testGetOutput() {
        $op = ["a", "", "c"];
        $this->assertEquals($op, (new JobResult(0,0,0, $op))->getOutput());
        $this->assertEquals([], (new JobResult(0,0,0))->getOutput());
    }

    public function testGetLastLine() {
        $jobResult = new JobResult(0, 0,0, ["first", "", "lastA", "inbetween", "lastB"]);
        $this->assertEquals("lastB", $jobResult->getLastLine());
    }

    public function testGetStart() {
        $this->assertEquals(42, (new JobResult(0, 42))->getStart());
    }

    public function testGetEnd() {
        $this->assertEquals(98, (new JobResult(0, 0, 98))->getEnd());
    }

    public function testGetDuration() {
        $this->assertEquals(10, (new JobResult(0, 30, 40))->getDuration());
    }

    public function provideTestGetDurationFormatted() {
        return [
            [50, "50s"],
            [70, "01m 10s"],
            [3696, "01h 01m 36s"],
            [7200, "02h 00m 00s"]
        ];
    }

    /**
     * @dataProvider provideTestGetDurationFormatted
     */
    public function testGetDurationFormatted($duration, $expected) {
        $jobResult = new JobResult(0, 0, $duration);
        $this->assertEquals($expected, $jobResult->getDurationFormatted());
    }
}