Browscap\Generator\GrepGenerator::run PHP Method

run() public method

Entry point for generating builds for a specified version
public run ( Browscap $browscap, string $inputFile, string $mode )
$browscap BrowscapPHP\Browscap
$inputFile string
$mode string
    public function run(Browscap $browscap, $inputFile, $mode)
    {
        $this->logger->debug('initialize Browscap');
        $this->browscap = $browscap;
        $fileContents = file_get_contents($inputFile);
        if (false !== strpos("\r\n", $fileContents)) {
            $uas = explode("\r\n", $fileContents);
        } else {
            $uas = explode("\n", $fileContents);
        }
        $foundMode = 0;
        $foundInvisible = 0;
        $foundUnexpected = 0;
        foreach (array_unique($uas) as $ua) {
            if (!$ua) {
                continue;
            }
            $check = $this->testUA($ua, $mode);
            if ($check === $mode) {
                ++$foundMode;
            } elseif ($check === GrepCommand::FOUND_INVISIBLE) {
                ++$foundInvisible;
            } else {
                ++$foundUnexpected;
            }
        }
        $this->logger->info('Found ' . $foundMode . ' ' . $mode . ' UAs and ' . $foundInvisible . ' other UAs, ' . $foundUnexpected . ' UAs had unexpected results');
    }

Usage Example

示例#1
0
    /**
     * tests running the generation of a grep command
     *
     * @group generator
     * @group sourcetest
     */
    public function testRun()
    {
        $mockLogger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false);
        self::assertSame($this->object, $this->object->setLogger($mockLogger));
        $mockBrowscap = $this->getMock('\\phpbrowscap\\Browscap', array(), array(), '', false);
        $tmpfile = tempnam(sys_get_temp_dir(), 'browscaptest');
        $in = <<<HERE
; comment

test
HERE;
        file_put_contents($tmpfile, $in);
        self::assertNull($this->object->run($mockBrowscap, $tmpfile, GrepCommand::MODE_UNMATCHED));
        unlink($tmpfile);
    }
All Usage Examples Of Browscap\Generator\GrepGenerator::run