Skip to content

Commit

Permalink
abstract initial stub copy so the plugin can call it directly
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Sep 30, 2024
1 parent 9cc1466 commit e3706d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
26 changes: 26 additions & 0 deletions src/actions/CopyInitialStubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace markhuot\craftpest\actions;

use craft\helpers\FileHelper;

class CopyInitialStubs
{
public function __invoke()
{
if (! is_dir(CRAFT_BASE_PATH.'/tests')) {
mkdir(CRAFT_BASE_PATH.'/tests');
}
if (! file_exists(CRAFT_BASE_PATH.'/tests/Pest.php')) {
copy(__DIR__.'/../../stubs/init/ExampleTest.php', CRAFT_BASE_PATH.'/tests/ExampleTest.php');
copy(__DIR__.'/../../stubs/init/Pest.php', CRAFT_BASE_PATH.'/tests/Pest.php');
}
if (! file_exists(CRAFT_BASE_PATH.'/phpunit.xml')) {
copy(__DIR__.'/../../stubs/init/phpunit.xml', CRAFT_BASE_PATH.'/phpunit.xml');
}
if (! is_dir(CRAFT_BASE_PATH.'/modules')) {
FileHelper::createDirectory(CRAFT_BASE_PATH.'/modules/pest/seeders');
copy(__DIR__.'/../../stubs/seeders/DatabaseSeeder.php', CRAFT_BASE_PATH.'/modules/pest/seeders/DatabaseSeeder.php');
}
}
}
17 changes: 3 additions & 14 deletions src/console/PestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Craft;
use craft\console\Controller;
use craft\helpers\FileHelper;
use markhuot\craftpest\actions\CopyInitialStubs;
use markhuot\craftpest\interfaces\RenderCompiledClassesInterface;
use markhuot\craftpest\Pest;
use Symfony\Component\Process\Process;
use yii\console\ExitCode;

use function markhuot\craftpest\helpers\base\service;
use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to;

/**
Expand Down Expand Up @@ -71,20 +73,7 @@ public function actionInit()

protected function runInit()
{
if (! is_dir(CRAFT_BASE_PATH.'/tests')) {
mkdir(CRAFT_BASE_PATH.'/tests');
}
if (! file_exists(CRAFT_BASE_PATH.'/tests/Pest.php')) {
copy(__DIR__.'/../../stubs/init/ExampleTest.php', CRAFT_BASE_PATH.'/tests/ExampleTest.php');
copy(__DIR__.'/../../stubs/init/Pest.php', CRAFT_BASE_PATH.'/tests/Pest.php');
}
if (! file_exists(CRAFT_BASE_PATH.'/phpunit.xml')) {
copy(__DIR__.'/../../stubs/init/phpunit.xml', CRAFT_BASE_PATH.'/phpunit.xml');
}
if (! is_dir(CRAFT_BASE_PATH.'/modules')) {
FileHelper::createDirectory(CRAFT_BASE_PATH.'/modules/pest/seeders');
copy(__DIR__.'/../../stubs/seeders/DatabaseSeeder.php', CRAFT_BASE_PATH.'/modules/pest/seeders/DatabaseSeeder.php');
}
service(CopyInitialStubs::class)();
}

protected function runTests(): int
Expand Down

0 comments on commit e3706d5

Please sign in to comment.