Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Console/PageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ class PageCommand extends GeneratorCommand
*/
protected $type = 'Page';

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$result = parent::buildClass($name);

$pageName = $this->argument('name');

$baseClass = 'Tests\Browser\Pages\Page';

if (! Str::contains($pageName, '/') && class_exists($baseClass)) {
return $result;
} elseif (! class_exists($baseClass)) {
$baseClass = 'Laravel\Dusk\Page';
}

$lineEndingCount = [
"\r\n" => substr_count($result, "\r\n"),
"\r" => substr_count($result, "\r"),
"\n" => substr_count($result, "\n"),
];

$eol = array_keys($lineEndingCount, max($lineEndingCount))[0];

return str_replace(
'use Laravel\Dusk\Browser;'.$eol,
'use Laravel\Dusk\Browser;'.$eol."use {$baseClass};".$eol,
$result
);
}

/**
* Get the stub file for the generator.
*
Expand Down