Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Engineering Guidelines Documentation #6798

Closed
2 tasks
maitreyie-chavan opened this issue Dec 17, 2021 · 4 comments · Fixed by #6802
Closed
2 tasks

Update the Engineering Guidelines Documentation #6798

maitreyie-chavan opened this issue Dec 17, 2021 · 4 comments · Fixed by #6802
Labels
Changelogged Whether the issue/PR has been added to release notes. Documentation Documentation related tasks P1 Medium priority
Milestone

Comments

@maitreyie-chavan
Copy link
Collaborator

Problem Statement

The current Engineering Guidelines are mostly outdated and need to be updated to ensure users are able to contribute to the plugin easily

https://github.com/ampproject/amp-wp/wiki/Engineering-Guidelines

To-Do

Along with updating the contents under the existing sections, let's also include a setup guideline for the below development environments

  • Local (formerly known as Local by Flywheel)
  • Valet -- (to be written by @dhaval-parekh)

Initial updated draft to be created by @delawski, followed by a review and Valet related updates by @dhaval-parekh

Please feel free to add any new sections to improve the knowledge base further.

@delawski
Copy link
Collaborator

As part of this issue, I’m working on making sure that the docker-based local environment bundled with the repo works as expected and allows for a really quick set up for new contributors. It is because I realized that that my setup based on Local is pretty custom and not reliable, especially when it comes to PHP unit testing.

@delawski
Copy link
Collaborator

I've faced some issues with having 2 instances of both wordpress and mysql running at the same time so that one can be used for development and the other can be used for tests.

It's interesting that @wordpress/env uses such a setup and everything works okay.

I've even tried replacing the custom docker-compose setup we have in the plugin with wp-env. With almost no changes I've been able to make it work (both dev and tests along with xdebug).

Where issues popped up is phpunit. After adding some tweaks to the bootstrap.php file and custom mappings to .wp-env.json (so that tests/includes, tests/data, and phpunit-wp-config.php are found), I was able to run the unit tests inside the tests container like:

wp-env run tests-cli './wp-content/plugins/amp/vendor/bin/phpunit -c wp-content/plugins/amp/phpunit.xml.dist'

There are limitations to that since, when used as an npm script, there's no way to pass additional arguments to phpunit from the CLI.

The wp-env's built in phpunit service seems to be lacking the context (e.g. WP_CLI used in the bootstrap.php file is not defined).

Phpunit, in general, has been a pain for me when using Local, too. It'd be great to find a way to make it easy to run the tests for anyone joining the project (ideally, the tests would work out-of-the-box).

@ediamin
Copy link
Collaborator

ediamin commented Dec 24, 2021

There are limitations to that since, when used as an npm script, there's no way to pass additional arguments to phpunit from the CLI.

You can use $npm_config_xyz in your npm script and use that to pass additional args to phpunit using --xyz flag. For example in the package.json

  "scripts": {
      ...
      "phpunit": "wp-env run tests-cli './wp-content/plugins/amp/vendor/bin/phpunit -c wp-content/plugins/amp/phpunit.xml.dist $npm_config_args'"
      ...
  },

Then in console we can use,

npm run phpunit --args=/var/www/html/wp-content/plugins/amp/tests/php/test-amp.php
// or
npm run phpunit --args='/var/www/html/wp-content/plugins/amp/tests/php/test-amp.php --filter=test_amp_is_canonical'

Here is my wp-env setup for amp-wp development.

@delawski
Copy link
Collaborator

delawski commented Jan 3, 2022

@ediamin Thanks for the advice and for sharing a link to your setup. I think it'll be very helpful.

@maitreyie-chavan maitreyie-chavan added this to the v2.2.1 milestone Jan 13, 2022
@maitreyie-chavan maitreyie-chavan added the P1 Medium priority label Jan 13, 2022
@maitreyie-chavan maitreyie-chavan modified the milestones: v2.2.1, v2.3 Jan 31, 2022
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. Documentation Documentation related tasks P1 Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants