-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
86 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class InstallTestsCommand extends Command | ||
{ | ||
protected $signature = 'rapidez:install:tests'; | ||
|
||
protected $description = 'Install Rapidez Tests'; | ||
|
||
public function handle() | ||
{ | ||
File::copyDirectory(base_path('vendor/rapidez/core/tests/Browser'), base_path('tests/Browser')); | ||
File::copyDirectory(base_path('vendor/rapidez/core/tests/Feature'), base_path('tests/Feature')); | ||
File::copy(base_path('vendor/rapidez/core/phpunit.dusk.xml'), base_path('phpunit.dusk.xml')); | ||
|
||
foreach (File::files(base_path('tests/Feature')) as $file) { | ||
file_put_contents($file->getPathname(), str_replace( | ||
'use Rapidez\Core\Tests\TestCase;', | ||
'use Tests\TestCase;', | ||
$file->getContents() | ||
)); | ||
} | ||
|
||
shell_exec('cd '.base_path().' && composer require --dev laravel/dusk && php artisan dusk:install && php artisan dusk:chrome-driver --detect'); | ||
|
||
$duskTestCaseFile = base_path('tests/DuskTestCase.php'); | ||
file_put_contents($duskTestCaseFile, str(file_get_contents($duskTestCaseFile)) | ||
->replace('use CreatesApplication;', 'use CreatesApplication, DuskTestCaseSetup;') | ||
->replace('use Laravel\Dusk\TestCase as BaseTestCase;\n', 'use Laravel\Dusk\TestCase as BaseTestCase;\nuse Rapidez\Core\Tests\DuskTestCaseSetup;\n')); | ||
|
||
foreach (File::files(base_path('tests/Browser')) as $file) { | ||
file_put_contents($file->getPathname(), str_replace( | ||
'use Rapidez\Core\Tests\DuskTestCase;', | ||
'use Tests\DuskTestCase;', | ||
$file->getContents() | ||
)); | ||
} | ||
|
||
$this->info('Done 🚀'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Tests; | ||
|
||
use Laravel\Dusk\Browser; | ||
use Rapidez\Core\Models\Product; | ||
|
||
trait DuskTestCaseSetup | ||
{ | ||
public string $flat; | ||
|
||
public Product $testProduct; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Browser::macro('waitUntilAllAjaxCallsAreFinished', function ($pause = false) { | ||
$this->waitUntil('!window.app.$data.loading', 10); | ||
|
||
if ($pause) { | ||
$this->pause($pause); | ||
} | ||
|
||
return $this; | ||
}); | ||
|
||
$this->flat = (new Product())->getTable(); | ||
|
||
$this->testProduct = Product::selectAttributes([ | ||
'name', | ||
'price', | ||
'url_key', | ||
])->firstWhere($this->flat.'.sku', env('TEST_PRODUCT', '24-WB02')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters