justafish / ddev-drupal-core-dev

ddev addon for core development
Apache License 2.0
24 stars 10 forks source link

DDEV 1.23, sqlite, yarn. #30

Closed simesy closed 5 months ago

simesy commented 6 months ago

Updates the plugin for ddev 1.23.

The original issue was here, however the base branch changed so i need to create a new PR.

Test by cloning the forked repo and using slightly different commands.

pcambra commented 6 months ago

Feels to me that there are some missing instruction somewhere, with the changes in this PR, running a Functional test:

ddev phpunit core/modules/shortc
ut/tests/src/Functional/GenericTest.php 
Clearing old webdriver sessions
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.6
Configuration: /var/www/html/core/phpunit.xml

Testing Drupal\Tests\shortcut\Functional\GenericTest
E                                                                   1 / 1 (100%)R

Time: 00:00.465, Memory: 4.00 MB

There was 1 error:

1) Drupal\Tests\shortcut\Functional\GenericTest::testModuleGenericIssues
Drupal\Core\Installer\Exception\InstallerException: Resolve all issues below to continue the installation. For help configuring your database server, see the <a href="https://www.drupal.org/docs/installing-drupal">installation handbook</a>, or contact your hosting provider.<ul><li>Failed to connect to your database server. The server reports the following message: <em class="placeholder">SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db failed: Name or service not known [Tip: This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.] </em>.<ul><li>Is the database server running?</li><li>Does the database exist or does the database user have sufficient privileges to create the database?</li><li>Have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname and port number?</li></ul></li></ul>

If I add - SIMPLETEST_DB=sqlite://localhost/sites/default/files/db.sqlite to my env variables for the web container:

ddev phpunit core/modules/shortcut/tests/src/Functional/GenericTest.php 
Clearing old webdriver sessions
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.6
Configuration: /var/www/html/core/phpunit.xml

Testing Drupal\Tests\shortcut\Functional\GenericTest
.                                                                   1 / 1 (100%)

Time: 00:03.586, Memory: 4.00 MB

OK (1 test, 9 assertions)
rfay commented 6 months ago

@simesy there are massive differences between this PR and the one you previously proposed (#23)

git diff simesy/main simesy/upstream shows

Difference between the two PRs ``` diff --git a/README.md b/README.md index c6dff2d..2721e7e 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,73 @@ -# Drupal Core Dev (DDEV plugin) +# ddev-core-dev -## Context of the fork +This is a DDEV addon for doing Drupal core development. -I maintain this fork of [justafish/ddev-drupal-core-dev](https://github.com/justafish/ddev-drupal-core-dev) -for my own tinkering. I have diverged parts of it from the upstream, so please be aware -that my requirements may differ from yours. +We're in #ddev-for-core-dev on [Drupal Slack](https://www.drupal.org/community/contributor-guide/reference-information/talk/tools/slack) (but please try and keep work and feature requests in Issues where it's visible to all 🙏) -I keep the [upstream branch](https://github.com/simesy/ddev-drupal-core-dev/tree/upstream) aligned with -the upstream along with anything I may be looking to get merged upstream. - -Ping @sime in #ddev-for-core-dev on [Drupal Slack](https://www.drupal.org/community/contributor-guide/reference-information/talk/tools/slack). +``` +git clone https://git.drupalcode.org/project/drupal.git drupal +cd drupal +ddev config --omit-containers=db --disable-settings-management +ddev start +ddev get justafish/ddev-drupal-core-dev +ddev restart +ddev composer install -## Philosophy +# See included commands +ddev drupal list -1. I'm working on Drupal core: Drupal repo first, tooling is secondary. -2. My tooling never makes "git status" dirty. -3. My tooling doesn't alter the Drupal application. +# Install drupal +ddev drupal install -## Setting up +# Run PHPUnit tests +ddev phpunit core/modules/sdc +# Run Nightwatch tests (currently only runs on Chrome) +ddev nightwatch --tag core ``` -# Clone the Drupal core codebase into the current directory. -git clone https://git.drupalcode.org/project/drupal.git drupal -cd drupal -# Configure and start a minimal DDEV project. -# This creates a .ddev folder and DDEV manages its own .gitingore -# Using SQLite, so skip mysql container with --omit-containers=db -ddev config --omit-containers=db --disable-settings-management -ddev start +## Nightwatch Examples -# Use DDEV to install Drupal's composer dependencies. The host machine does not need PHP. -ddev composer install +You can watch Nightwatch running in real time at https://drupal.ddev.site:7900 +for Chrome and https://drupal.ddev.site:7901 for Firefox. The password is +"secret". YMMV using Firefox as core tests don't currently run on it. -# Get the latest release of this plugin. This adds files to the .ddev folder. -ddev get simesy/ddev-drupal-core-dev -ddev restart +Only core tests +``` +ddev nightwatch --tag core ``` -## Installing and Testing +Skip running core tests +``` +ddev nightwatch --skiptags core +``` +Run a single test +``` +ddev nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js +``` + +a11y tests for both the admin and default themes +``` +ddev nightwatch --tag a11y ``` -# This plugin provides a "drupal" command, see what it offers. -ddev drupal list -# Install (or re-install) Drupal. -ddev drupal install minimal +a11y tests for the admin theme only +``` +ddev nightwatch --tag a11y:admin +``` -# Run a small sample of PHPUnit tests. -ddev phpunit core/modules/text/tests/src/Functional/GenericTest.php +a11y tests for the default theme only +``` +ddev nightwatch --tag a11y:default +``` -# Run Nightwatch tests. -ddev nightwatch --tag core +a11y test for a custom theme used as the default theme +``` +ddev nightwatch --tag a11y:default --defaultTheme bartik +``` -# Todo, I have temporarily removed a lot of examples here. +a11y test for a custom admin theme +``` +ddev nightwatch --tag a11y:admin --adminTheme seven ``` diff --git a/commands/web/drupal b/commands/web/drupal index 569315b..2e82267 100755 --- a/commands/web/drupal +++ b/commands/web/drupal @@ -14,12 +14,13 @@ */ use Drupal\Core\Command\GenerateTheme; +use Drupal\Core\Command\InstallCommand; use Symfony\Component\Console\Application; -use DrupalCoreDev\Command\AdminLoginCommand; use DrupalCoreDev\Command\CacheCommand; -use DrupalCoreDev\Command\InstallCommand; +use DrupalCoreDev\Command\AdminLoginCommand; use DrupalCoreDev\Command\TestCommand; use DrupalCoreDev\Command\TestBrowserCommand; +use DrupalCoreDev\Command\UninstallCommand; if (PHP_SAPI !== 'cli') { return; @@ -37,5 +38,6 @@ $application->add(new CacheCommand($loader)); $application->add(new AdminLoginCommand($loader)); $application->add(new TestCommand()); $application->add(new TestBrowserCommand()); +$application->add(new UninstallCommand()); $application->run(); diff --git a/core-dev/.env b/core-dev/.env index 5c4ed10..9a54fb3 100644 --- a/core-dev/.env +++ b/core-dev/.env @@ -1,12 +1,82 @@ #ddev-generated +# This is a dotenv file used by JavaScript tasks. +# Copy this to '.env' to override. -# This is based on Drupal core env.example, see for documentation: -# @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/.env.example?ref_type=heads - +############################# +# General Test Environment # +############################# +# This is the URL that Drupal can be accessed by. You don't need an installed +# site here, just make sure you can at least access the installer screen. If you +# don't already have one running, e.g. Apache, you can use PHP's built-in web +# server by running the following command in your Drupal root folder: +# php -S localhost:8888 .ht.router.php +# DRUPAL_TEST_BASE_URL=http://localhost:8888 DRUPAL_TEST_BASE_URL=http://web + +# Tests need to be executed with a user in the same group as the web server +# user. +#DRUPAL_TEST_WEBSERVER_USER=www-data + +# By default we use sqlite as database. Use +# mysql://username:password@localhost/databasename#table_prefix for mysql. DRUPAL_TEST_DB_URL=sqlite://localhost/sites/default/files/db.sqlite + +############# +# Webdriver # +############# + +# If Chromedriver is running as a service elsewhere, set it here. +# When using DRUPAL_TEST_CHROMEDRIVER_AUTOSTART leave this at the default settings. DRUPAL_TEST_WEBDRIVER_HOSTNAME=chrome DRUPAL_TEST_WEBDRIVER_PORT=4444 + +# If using Selenium, override the path prefix here. +# See http://nightwatchjs.org/gettingstarted#browser-drivers-setup +#DRUPAL_TEST_WEBDRIVER_PATH_PREFIX=/wd/hub + +################ +# Chromedriver # +################ + +# Automatically start chromedriver for local development. Set to false when you +# use your own webdriver or chromedriver setup. +# Also set it to false when you use a different browser for testing. DRUPAL_TEST_CHROMEDRIVER_AUTOSTART=false + +# A list of arguments to pass to Chrome, separated by spaces +# e.g. `--disable-gpu --headless --no-sandbox`. +#DRUPAL_TEST_WEBDRIVER_CHROME_ARGS= + +# A list of arguments to pass to Webdriver, separated by spaces +# e.g. `--allowed-ips --disable-dev-shm-usage`. +#DRUPAL_TEST_WEBDRIVER_CLI_ARGS= + +############## +# Nightwatch # +############## + +# Nightwatch generates output files. Use this to specify the location where these +# files need to be stored. The default location is ignored by git, if you modify +# the location you will probably want to add this location to your .gitignore. DRUPAL_NIGHTWATCH_OUTPUT=test_output/nightwatch + +# The path that Nightwatch searches for assumes the same directory structure as +# when you download Drupal core. If you have Drupal installed into a docroot +# folder, you can use the following folder structure to add integration tests +# for your project, outside of tests specifically for custom modules/themes/profiles. +# +# . +# ├── docroot +# │ ├── core +# ├── tests +# │ ├── Nightwatch +# │ │ ├── Tests +# │ │ │ ├── myTest.js +# +# and then set DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY=../ +# +#DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY= + +# Filter directories to look for tests. This uses minimatch syntax. +# Separate folders with a comma. DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES=node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest diff --git a/core-dev/phpunit-chrome.xml b/core-dev/phpunit-chrome.xml index 1a98287..a4888bd 100644 --- a/core-dev/phpunit-chrome.xml +++ b/core-dev/phpunit-chrome.xml @@ -1,9 +1,12 @@ + + + + + + + + + + + + + + + diff --git a/core-dev/phpunit-firefox.xml b/core-dev/phpunit-firefox.xml new file mode 100644 index 0000000..564f83c --- /dev/null +++ b/core-dev/phpunit-firefox.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./tests/TestSuites/UnitTestSuite.php + + + ./tests/TestSuites/KernelTestSuite.php + + + ./tests/TestSuites/FunctionalTestSuite.php + + + ./tests/TestSuites/FunctionalJavascriptTestSuite.php + + + ./tests/TestSuites/BuildTestSuite.php + + + + + + + + + + ./includes + ./lib + ./modules + ../modules + ../sites + + + ./modules/*/src/Tests + ./modules/*/tests + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + ./lib/** + ./modules/** + ../modules/** + + + diff --git a/core-dev/src/Command/InstallCommand.php b/core-dev/src/Command/UninstallCommand.php similarity index 51% rename from core-dev/src/Command/InstallCommand.php rename to core-dev/src/Command/UninstallCommand.php index d5b84bb..e847b45 100644 --- a/core-dev/src/Command/InstallCommand.php +++ b/core-dev/src/Command/UninstallCommand.php @@ -3,22 +3,25 @@ namespace DrupalCoreDev\Command; -use Drupal\Core\Command\InstallCommand as CoreInstallCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; -/** - * Extends Drupal install site command. - */ -class InstallCommand extends CoreInstallCommand { +class UninstallCommand extends Command { + /** + * {@inheritdoc} + */ + protected function configure() { + $this->setName('uninstall') + ->setDescription('Uninstall Drupal by deleting settings.'); + } - /** - * {@inheritdoc} - */ - function execute(InputInterface $input, OutputInterface $output): int { - $filesystem = new Filesystem(); - try { + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output): int { + $filesystem = new Filesystem(); $settings = __DIR__ . '/../../../../sites/default/settings.php'; $files = __DIR__ . '/../../../../sites/default/files'; $filesystem->chmod($files . '/../', 0755); @@ -26,11 +29,6 @@ class InstallCommand extends CoreInstallCommand { $filesystem->remove($settings); $filesystem->chmod($files, 0777, 0000, true); $filesystem->remove($files); - $output->writeln('Removed a previous installation.'); - } - catch (\Exception $e) { - // This would fail if there was no previous installation, naively proceed to install Drupal. + return 0; } - return parent::execute($input, $output); - } } diff --git a/install.yaml b/install.yaml index cefcf19..1e206a4 100644 --- a/install.yaml +++ b/install.yaml @@ -6,6 +6,7 @@ project_files: - config.ddev-drupal-core-dev.yaml - web-build/Dockerfile.ddev-drupal-core-dev - docker-compose.core-dev-selenium.yaml + - core-dev/phpunit-firefox.xml - core-dev/phpunit-chrome.xml - commands/web/drupal - commands/web/phpunit @@ -17,7 +18,7 @@ project_files: - core-dev/src/Command/CacheCommand.php - core-dev/src/Command/TestCommand.php - core-dev/src/Command/TestBrowserCommand.php - - core-dev/src/Command/InstallCommand.php + - core-dev/src/Command/UninstallCommand.php post_install_actions: - cp core-dev/phpunit-chrome.xml ../core/phpunit.xml ```

By closing the other one, you invalidated all the reviews there. And then opening this one with major changes leaves us all confused.

Would you mind reopening the other one and closing this one? If you need help figuring out what was going wrong, I'm happy to help.

If you'd rather, I can open a replacement PR for #23 I guess and give you credit in the commit.

rfay commented 5 months ago

Per conversation with @simesy this can be closed in favor of