Skip to content

Commit 709bd03

Browse files
Mile23torenware
Mile23
authored andcommitted
Issue #2747309 by Mile23: Add CONTRIBUTING.md, STANDARDS.md, TESTING.md for contributors
1 parent 907cba2 commit 709bd03

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

CONTRIBUTING.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Drupal Examples For Developers: Contributor's Guide
2+
===================================================
3+
4+
Examples for Developers is a community project.
5+
6+
If you'd like to participate in Examples development, thank you!
7+
8+
If you are new to Drupal or open source in general, have no fear. Examples is
9+
an easy-going project where you can learn some things about how to work on a
10+
collaborative project in a friendly environment.
11+
12+
13+
Policies
14+
--------
15+
16+
Examples follows the Drupal core process as much as possible.
17+
18+
Contributions thus need to be similar in quality to Drupal core patches.
19+
Contributions will need to meet the following minimum standards:
20+
21+
### Normal Drupal issue process
22+
23+
Drupal projects use patches related to issues. You should know how to make a
24+
patch and an interdiff using git. It's fine to develop on github or
25+
what-have-you, but eventually it has to be a patch that can be reviewed in the
26+
normal Drupal issue process. See the list of resources for some information on
27+
how to do do this.
28+
29+
Your patch will also need to be reviewed by someone other than yourself. Learn
30+
about the review process in the resources section.
31+
32+
### DrupalCI
33+
34+
Examples uses the Drupal automated testing system to verify the applicability of
35+
patches. See `TESTING.md` for details.
36+
37+
### Drupal coding standards
38+
39+
All code in Examples should adhere to the Drupal core coding standards. Examples
40+
uses the Drupal Coder project and PHP_CodeSniffer to enforce coding standards.
41+
Think of this as another test your code must pass. See `STANDARDS.md` for
42+
details.
43+
44+
45+
Resources
46+
---------
47+
48+
### Novice
49+
50+
Drupal novice contribution guide: https://www.drupal.org/novice
51+
52+
Drupal contribution guide: https://www.drupal.org/contribute
53+
54+
What's a patch? https://www.drupal.org/patch
55+
56+
How to make a patch with git: https://www.drupal.org/node/707484
57+
58+
### Everyone
59+
60+
How to review a patch: https://www.drupal.org/patch/review
61+
62+
See `STANDARDS.md` and `TESTING.md` for information on how to run a coding
63+
standards test, and also how to run the tests themselves.

STANDARDS.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
HOWTO: Drupal Examples For Developers Coding Standards
2+
=======================================================
3+
4+
Examples uses the same coding standards as Drupal core.
5+
6+
Examples has a `phpcs.xml.dist` file at the root of the project. This file
7+
specifies the current coding standards 'sniffs' which code in the project must
8+
pass.
9+
10+
The `phpcs.xml.dist` file is used by a tool called PHP_CodeSniffer (`phpcs`).
11+
12+
Contributors should install `phpcs` in their local Drupal installation, and then
13+
use that to run `phpcs` against Examples as part of their development and review
14+
process.
15+
16+
Contributors can also patch the `phpcs.xml.dist` file itself, in order to fix
17+
the codebase to pass a given rule or sniff. Patches which do this should be
18+
limited to a single rule or sniff, in order make the patch easier to review.
19+
20+
Installing phpcs
21+
----------------
22+
23+
Generally: Use Composer to add Drupal's Coder project to your root
24+
Drupal project. Coder contains the PHP_CodeSniffer rules we need, and
25+
also requires `phpcs`.
26+
27+
Then tell `phpcs' where our Drupal-specific rules are.
28+
29+
Like this:
30+
31+
$ cd my/drupal/root/
32+
$ composer require drupal/coder
33+
// Composer installs Coder, which requires PHP_CodeSniffer as well.
34+
// Configure phpcs to use the Drupal standard rules...
35+
$ ./vendor/bin/phpcs --config-set installed_paths /path/to/drupal/vendor/drupal/coder/coder_sniffer/
36+
// phpcs now knows how to find the Drupal standard. You can test it:
37+
$ cd core
38+
$ ../vendor/bin/phpcs -e --standard=Drupal
39+
// Shows you a bunch of Drupal-related sniffs.
40+
41+
Running phpcs
42+
-------------
43+
44+
Now you can run phpcs:
45+
46+
$ cd modules/examples
47+
$ ../../vendor/bin/phpcs -p -s
48+
// phpcs uses Exampes' phpcs.xml.dist to verify coding standards.
49+
// -p shows you progress dots.
50+
// -s shows you sniff errors in the report.
51+
52+
If there are errors, they can sometimes be fixed with `phpcbf`, which is
53+
part of the `phpcs` package.
54+
55+
$ ../../vendor/bin/phpcbf
56+
// phpcbf now performs automated fixes.
57+
58+
Always look at the changes to see what `phpcbf` did.
59+
60+
And always re-run `phpcs` in order to discover whether `phpcbf` handled all the
61+
errors.

TESTING.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Testing Drupal Examples for Developers
2+
======================================
3+
4+
The Drupal Examples for Developers project uses DrupalCI testing on drupal.org.
5+
6+
That means: It runs the testbot on every patch that is marked as 'Needs Review.'
7+
8+
Your patch might not get reviewed, and certainly won't get committed unless it
9+
passes the testbot.
10+
11+
The testbot runs a script that's in your Drupal installation called
12+
`core/scripts/run-tests.sh`. You can run `run-tests.sh` manually and approximate
13+
the testbot's behavior.
14+
15+
You can find information on how to run `run-tests.sh` locally here:
16+
https://www.drupal.org/node/645286
17+
18+
You should at least run `run-tests.sh` locally against all the changes in your
19+
patch before uploading it.
20+
21+
Keep in mind that unless you know you're changing behavior that is being tested
22+
for, the tests are not at fault. :-)
23+
24+
Note also that, currently, using the `phpunit` tool under Drupal 8 will not find
25+
PHPUnit-based tests in submodules, such as phpunit_example. There is no
26+
suggested workaround for this, since there is no best practice to demonstrate as
27+
an example. There is, however, this issue in core:
28+
https://www.drupal.org/node/2499239
29+
30+
31+
What Tests Should An Example Project Have?
32+
------------------------------------------
33+
34+
Examples has a checklist for each module:
35+
https://www.drupal.org/node/2209627
36+
37+
The reason we care about these tests is that we want the documentation
38+
of these APIs to be correct. If Core changes APIs, we want our tests to
39+
fail so that we know our documentation is incorrect.
40+
41+
Our list of required tests includes:
42+
* Functional tests which verifies a 200 result for each route/path defined by
43+
the module.
44+
* Functional tests of permission-based restrictions.
45+
* Functional tests which submit forms and verify that they behave as
46+
expected.
47+
* Unit tests of unit-testable code.
48+
* Other. More. Better.

0 commit comments

Comments
 (0)