Compare.php

<?php

namespace Taeluf\Tester\Test;

class Compare extends \Taeluf\Tester {


    public function testComparePHPFileToString(){
        $file = __DIR__.'/src/Compare.php';
        ob_start();
        require($file);
        $target = ob_get_clean();
        if (substr($target,0,4)!='I am'){
            throw new \Exception("The source file for the test does not match /^I am.*/");
        }

        return $this->compare($target,'file://'.$file)
            &&$this->compare('file://'.$file,$target);
    }
    public function testCompareFileToStringStrict(){
        $file = __DIR__.'/src/Compare.txt';
        $target = file_get_contents($file);
        if (substr($target,0,4)!='abcd'){
            throw new \Exception("The source file for the test does not match /^abcd.*/");
        }

        return !$this->compare($target, "file://{$file}",true)
            &&!$this->compare("file://{$file}",$target,true);
    }

    public function testCompareFileToStringLoose(){
        $file = __DIR__.'/src/Compare.txt';
        $target = file_get_contents($file);
        if (substr($target,0,4)!='abcd'){
            throw new \Exception("The source file for the test does not match /^abcd.*/");
        }

        return $this->compare($target, "file://{$file}")
            &&$this->compare("file://{$file}",$target);
    }
    public function testComparestringsWithDiffPad(){
        $actual = "I am a string.";
        $target = "   ".$actual;
        return
            !$this->compare($target,$actual,true)
            && $this->compare($target,$actual);
    }

    public function testCompareStringsThatMatch(){
        $actual = "Be good to others.";
        $target = $actual;

        return $this->compare($target,$actual,true);
    }
}

Compare::runAll();