joachim-n / ddev-drupal-core-dev

ddev addon for core development
Apache License 2.0
0 stars 1 forks source link

Find a better way to handle phpunit.xml file #3

Open joachim-n opened 3 weeks ago

joachim-n commented 3 weeks ago

I'm not sure what's going on with the phpunit.xml file.

I thought that it was getting copied when the addon gets installed, with some token replacements, in install.yaml:

  - cp core-dev/phpunit-chrome.xml ../phpunit.xml
  - perl -pi -e "s|DRUPAL_CORE_DDEV_URL|$DDEV_PRIMARY_URL|g" ../phpunit.xml
  - perl -pi -e "'$DDEV_DOCROOT' and s|DDEV_DOCROOT|$DDEV_DOCROOT/|g" ../phpunit.xml

but in config.core-dev.yaml, this also happens whenever ddev is started:

hooks:
  post-start:
  - exec: |
      dburl='sqlite://localhost/sites/default/files/db.sqlite'
      cp .ddev/core-dev/phpunit-chrome.xml core/phpunit.xml
      cp .ddev/core-dev/.env core/.env
      if ping -c 1 db >/dev/null 2>&1; then
        case ${DDEV_DATABASE_FAMILY:-} in
          mysql)
            # the backslash here is to prevent perl from eating the @
            dburl='mysql://db:db\@db/db'
            ;;
          postgres)
            dburl='pgsql://db:db\@db/db'
            ;;
        esac
      fi
      perl -pi -e "s|SIMPLETEST_DB_VALUE|${dburl}|g" core/phpunit.xml
      perl -pi -e "s|DRUPAL_TEST_DB_URL_VALUE|${dburl}|g" core/.env
      perl -pi -e "s|DRUPAL_CORE_DDEV_URL|${DDEV_PRIMARY_URL}|g" core/phpunit.xml

I don't understand this. We're redoing the setting of DRUPAL_CORE_DDEV_URL. Then there's SIMPLETEST_DB_VALUE that we set now, but didn't on install -- is that because we only know the database once DDEV is running, rather than when the addon is installed?

Then there's the core-dev/src/Command/TestBrowserCommand.php command which copies the file again, but this time to allow you switch between the phpunit-chrome.xml and phpunit-firefox.xml flavours that come with this addon.

See also: https://github.com/rfay/ddev-drupal-core-dev/commit/90eeb91e7bc4b31096fca8bac4fb46cafad9ed02#r148645439

joachim-n commented 2 weeks ago

@rfay are SIMPLETEST_DB_VALUE and DRUPAL_TEST_DB_URL_VALUE and DRUPAL_CORE_DDEV_URL not known at add-on install time, only when ddev is being started?

rfay commented 2 weeks ago

DDEV doesn't know anything about "install time". It only knows about whether it's started. The way to sort things like this out is to use simple statements like

hooks:
  post-start:
  - exec: "echo $SOMEVAR"
joachim-n commented 2 weeks ago

Sorry, I should have been more specific -- I mean when the addon is being installed, when post_install_actions are run (and not when Drupal is being installed)

rfay commented 2 weeks ago

Lot of times during add-on installation, DDEV isn't even started, so you won't get those unless you get them from somewhere.

That said, none of those vars are set by DDEV itself. You must be thinking they'll get set somewhere, you'll have to figure out where. But add-on installation does not require that a project be started already. In fact, since a restart is almost always required, it's better to think about them as being done on stopped project.

joachim-n commented 13 hours ago

Lot of times during add-on installation, DDEV isn't even started, so you won't get those unless you get them from somewhere.

I just tried doing ddev addon get on an unstarted project, and it started ddev. Is that normal, or is there something in this particular addon's code which caused a startup?

rfay commented 12 hours ago

Your add-on may be starting it, or you may be running a custom command that starts it.

If you try ddev add-on get ddev/ddev-redis for example, it won't start the project.