webksde / ddev-vscode-devcontainer-drupal-template

Drupal DDEV based development container with attached Visual Studio Code
23 stars 3 forks source link

Run CERTAIN commands on the current path, others on the project path (e. g. phpunit on the current module) #107

Closed JPustkuchen closed 2 years ago

JPustkuchen commented 2 years ago

Currently things like ddev phpunit web/modules/custom/mymodule have to be executed from the ddev project directory. Otherwise, they won't work work correctly or show errors.

Examples: ~/ddev/drupal9/web/modules/custom/fences_block$ ddev phpunit tests the whole project (core, ...)

~/ddev/drupal9/web/modules/custom/fences_block$ ddev phpunit . returns

PHP Fatal error: Uncaught Error: Class 'Behat\Mink\Tests\Driver\TestCase' not found in /var/www/html/vendor/behat/mink-selenium2-driver/tests/Custom/DesiredCapabilitiesTest.php:8 Stack trace:

0 /var/www/html/vendor/phpunit/phpunit/src/Util/FileLoader.php(65): include_once()

1 /var/www/html/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/var/www/html/v...')

2 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(394): PHPUnit\Util\FileLoader::checkAndLoad('/var/www/html/v...')

3 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(522): PHPUnit\Framework\TestSuite->addTestFile('/var/www/html/v...')

4 /var/www/html/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(98): PHPUnit\Framework\TestSuite->addTestFiles(Array)

5 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php(120): PHPUnit\Runner\BaseTestRunner->getTest('/var/www/html', Array)

6 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php(96): PHPUnit\TextUI\Command->run(Array, true)

7 phpvf in /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php on line 9

Anyway, you're often working inside a module directory to execute your git commands etc. So as a workaround you have to open a 2nd shell or change directories everytime, which isn't perfect.

So best would be for such commands which are useful on subdirectories to be able to execute them just like ddev phpunit or ddev phpunit . would also be fine! :)

Commands for which this would be useful (but I didn't test their behavior yet):

Other commands should ALWAYS be executed at the top level, like

They should NOT be affected by this change and runnable from any subdirectory without having to change to root.

joshsedl commented 2 years ago

Fixed commands:

You can now run: ddev fixedcommand -> to run the command on the current directory or ddev fixedcommand path/to/something -> to run the command on the given directory (just like before)

JPustkuchen commented 2 years ago

Genius! :)

JPustkuchen commented 2 years ago

Note: Didn't work with ddev 1.19.1!

With ddev 1.21.1 it works!! :)

I think the reason is that ## HostWorkingDir: true didn't exist in 1.19.