Laravel 5.6 updates
Travis config update Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
189
vendor/laravel/dusk/src/TestCase.php
vendored
189
vendor/laravel/dusk/src/TestCase.php
vendored
@@ -2,32 +2,16 @@
|
||||
|
||||
namespace Laravel\Dusk;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use ReflectionFunction;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Dusk\Chrome\SupportsChrome;
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||
use Illuminate\Foundation\Testing\TestCase as FoundationTestCase;
|
||||
|
||||
abstract class TestCase extends FoundationTestCase
|
||||
{
|
||||
use SupportsChrome;
|
||||
|
||||
/**
|
||||
* All of the active browser instances.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $browsers = [];
|
||||
|
||||
/**
|
||||
* The callbacks that should be run on class tear down.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $afterClassCallbacks = [];
|
||||
use Concerns\ProvidesBrowser,
|
||||
SupportsChrome;
|
||||
|
||||
/**
|
||||
* Register the base URL with Dusk.
|
||||
@@ -49,167 +33,6 @@ abstract class TestCase extends FoundationTestCase
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the Dusk test case class.
|
||||
*
|
||||
* @afterClass
|
||||
* @return void
|
||||
*/
|
||||
public static function tearDownDuskClass()
|
||||
{
|
||||
static::closeAll();
|
||||
|
||||
foreach (static::$afterClassCallbacks as $callback) {
|
||||
$callback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an "after class" tear down callback.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function afterClass(Closure $callback)
|
||||
{
|
||||
static::$afterClassCallbacks[] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new browser instance.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return \Laravel\Dusk\Browser|void
|
||||
* @throws \Exception
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function browse(Closure $callback)
|
||||
{
|
||||
$browsers = $this->createBrowsersFor($callback);
|
||||
|
||||
try {
|
||||
$callback(...$browsers->all());
|
||||
} catch (Exception $e) {
|
||||
$this->captureFailuresFor($browsers);
|
||||
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
$this->captureFailuresFor($browsers);
|
||||
|
||||
throw $e;
|
||||
} finally {
|
||||
$this->storeConsoleLogsFor($browsers);
|
||||
|
||||
static::$browsers = $this->closeAllButPrimary($browsers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the browser instances needed for the given callback.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return array
|
||||
*/
|
||||
protected function createBrowsersFor(Closure $callback)
|
||||
{
|
||||
if (count(static::$browsers) === 0) {
|
||||
static::$browsers = collect([$this->newBrowser($this->createWebDriver())]);
|
||||
}
|
||||
|
||||
$additional = $this->browsersNeededFor($callback) - 1;
|
||||
|
||||
for ($i = 0; $i < $additional; $i++) {
|
||||
static::$browsers->push($this->newBrowser($this->createWebDriver()));
|
||||
}
|
||||
|
||||
return static::$browsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Browser instance.
|
||||
*
|
||||
* @param \Facebook\WebDriver\Remote\RemoteWebDriver $driver
|
||||
* @return \Laravel\Dusk\Browser
|
||||
*/
|
||||
protected function newBrowser($driver)
|
||||
{
|
||||
return new Browser($driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of browsers needed for a given callback.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return int
|
||||
*/
|
||||
protected function browsersNeededFor(Closure $callback)
|
||||
{
|
||||
return (new ReflectionFunction($callback))->getNumberOfParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture failure screenshots for each browser.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $browsers
|
||||
* @return void
|
||||
*/
|
||||
protected function captureFailuresFor($browsers)
|
||||
{
|
||||
$browsers->each(function ($browser, $key) {
|
||||
$browser->screenshot('failure-'.$this->getName().'-'.$key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the console output for the given browsers.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $browsers
|
||||
* @return void
|
||||
*/
|
||||
protected function storeConsoleLogsFor($browsers)
|
||||
{
|
||||
$browsers->each(function ($browser, $key) {
|
||||
$browser->storeConsoleLog($this->getName().'-'.$key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all of the browsers except the primary (first) one.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $browsers
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function closeAllButPrimary($browsers)
|
||||
{
|
||||
$browsers->slice(1)->each->quit();
|
||||
|
||||
return $browsers->take(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all of the active browsers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function closeAll()
|
||||
{
|
||||
Collection::make(static::$browsers)->each->quit();
|
||||
|
||||
static::$browsers = collect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the remote web driver instance.
|
||||
*
|
||||
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
|
||||
*/
|
||||
protected function createWebDriver()
|
||||
{
|
||||
return retry(5, function () {
|
||||
return $this->driver();
|
||||
}, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the RemoteWebDriver instance.
|
||||
*
|
||||
@@ -225,7 +48,7 @@ abstract class TestCase extends FoundationTestCase
|
||||
/**
|
||||
* Determine the application's base URL.
|
||||
*
|
||||
* @var string
|
||||
* @return string
|
||||
*/
|
||||
protected function baseUrl()
|
||||
{
|
||||
@@ -233,9 +56,9 @@ abstract class TestCase extends FoundationTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a callback that returns the default user to authenticate.
|
||||
* Return the default user to authenticate.
|
||||
*
|
||||
* @return \Closure
|
||||
* @return \App\User|int|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function user()
|
||||
|
||||
Reference in New Issue
Block a user