예제 #1
0
    /**
     * @param  array $browser
     * @return PHPUnit_Extensions_SeleniumTestCase_Driver
     */
    protected function getDriver(array $browser)
    {
        if (isset($browser['name'])) {
            if (!is_string($browser['name'])) {
                throw new InvalidArgumentException(
                  'Array element "name" is no string.'
                );
            }
        } else {
            $browser['name'] = '';
        }

        if (isset($browser['browser'])) {
            if (!is_string($browser['browser'])) {
                throw new InvalidArgumentException(
                  'Array element "browser" is no string.'
                );
            }
        } else {
            $browser['browser'] = '';
        }

        if (isset($browser['host'])) {
            if (!is_string($browser['host'])) {
                throw new InvalidArgumentException(
                  'Array element "host" is no string.'
                );
            }
        } else {
            $browser['host'] = 'localhost';
        }

        if (isset($browser['port'])) {
            if (!is_int($browser['port'])) {
                throw new InvalidArgumentException(
                  'Array element "port" is no integer.'
                );
            }
        } else {
            $browser['port'] = 4444;
        }

        if (isset($browser['timeout'])) {
            if (!is_int($browser['timeout'])) {
                throw new InvalidArgumentException(
                  'Array element "timeout" is no integer.'
                );
            }
        } else {
            $browser['timeout'] = 30;
        }

        if (isset($browser['httpTimeout'])) {
            if (!is_int($browser['httpTimeout'])) {
                throw new InvalidArgumentException(
                  'Array element "httpTimeout" is no integer.'
                );
            }
        } else {
            $browser['httpTimeout'] = 45;
        }
        
    	if (isset($browser['captureScreenshotOnFailure'])) {
            if (!is_bool($browser['captureScreenshotOnFailure'])) {
                throw new InvalidArgumentException(
                  'Array element "captureScreenshotOnFailure" is no boolean.'
                );
            }
        } else {
            $browser['captureScreenshotOnFailure'] = false;
        }
        
        if (isset($browser['screenshotPath'])) {
            if (!is_string($browser['screenshotPath'])) {
                throw new InvalidArgumentException(
                  'Array element "screenshotPath" is no string.'
                );
            }
        } else {
            $browser['screenshotPath'] = '';
        }
        
    	if (isset($browser['screenshotUrl'])) {
            if (!is_string($browser['screenshotUrl'])) {
                throw new InvalidArgumentException(
                  'Array element "screenshotUrl" is no string.'
                );
            }
        } else {
            $browser['screenshotUrl'] = '';
        }
        
    	if (isset($browser['captureMethod'])) {
            if (!is_string($browser['captureMethod'])) {
                throw new InvalidArgumentException(
                  'Array element "captureMethod" is no string.'
                );
            }
        } else {
            $browser['captureMethod'] = 'captureScreenshot';
        }

        if (@fsockopen($browser['host'], $browser['port'], $errno, $errstr)) {
            $this->serverRunning = TRUE;
        } else {
            $this->serverRunning = FALSE;
        }

        $driver = new PHPUnit_Extensions_SeleniumTestCase_Driver;
        $driver->setName($browser['name']);
        $driver->setBrowser($browser['browser']);
        $driver->setHost($browser['host']);
        $driver->setPort($browser['port']);
        $driver->setTimeout($browser['timeout']);
        $driver->setHttpTimeout($browser['httpTimeout']);
        $driver->setCaptureScreenshotOnFailure($browser['captureScreenshotOnFailure']);
        $driver->setScreenshotPath($browser['screenshotPath']);
        $driver->setScreenshotUrl($browser['screenshotUrl']);
        $driver->setCaptureMethod($browser['captureMethod']);
        $driver->setTestCase($this);
        $driver->setTestId($this->testId);

        $this->drivers[] = $driver;

        return $driver;
    }