|
2 | 2 |
|
3 | 3 | namespace Drupal\phpunit_example\Controller; |
4 | 4 |
|
| 5 | +use Drupal\examples\Utility\DescriptionTemplateTrait; |
| 6 | + |
5 | 7 | /** |
6 | 8 | * Controller for PHPUnit description page. |
| 9 | + * |
| 10 | + * This class uses the DescriptionTemplateTrait to display text we put in the |
| 11 | + * templates/description.html.twig file. We render out the text via its |
| 12 | + * description() method, and set up our routing to point to |
| 13 | + * PHPUnitExampleController::description(). |
7 | 14 | */ |
8 | 15 | class PHPUnitExampleController { |
| 16 | + use DescriptionTemplateTrait; |
9 | 17 |
|
10 | 18 | /** |
11 | | - * Displays a page with a descriptive page. |
12 | | - * |
13 | | - * Our router maps this method to the path 'examples/phpunit_example'. |
| 19 | + * {@inheritdoc} |
14 | 20 | */ |
15 | | - public function description() { |
16 | | - $build = array( |
17 | | - '#markup' => t('<h2>PHPUnit for Drupal: A very basic how-to.</h2> |
18 | | -<h3>How to use this example module</h3> |
19 | | -<p>You really should be reading the various docblocks in the test files.</p> |
20 | | -<h3>How To:</h3> |
21 | | -<ul> |
22 | | -<li><p>PHPUnit tests belong in their own directory, so they won't be loaded by the autoloader during normal bootstrap. This means you should have a <code>/tests/src</code> directory in the root of your module directory.</p></li> |
23 | | -<li><p>Your tests should be in the <code>Drupal\Tests\[your_module]\Unit</code> namespace. Under Drupal's PSR-4 system, this means your PHPUnit-based tests should go in a <code>[your_module]/tests/src/Unit</code> directory.</p></li> |
24 | | -<li><p>Your test case should subclass <code>Drupal\Tests\UnitTestCase</code>.</p></li> |
25 | | -<li><p>You can run PHPUnit-based tests from within Drupal 8 by enabling the Testing module and then selecting the PHPUnit group from the testing page. As of this writing, this method doesn't provide any useful output.</p></li> |
26 | | -</ul> |
27 | | -<h3>Standard PHPUnit Practices</h3> |
28 | | -<p>You can (and really, should) run PHPUnit from the command line.</p> |
29 | | -<p>On unix-based systems this means you need to <code>cd core</code> and then <code>./vendor/bin/phpunit</code>.</p> |
30 | | -<p>On Windows-based systems, assuming you have php in your path, <code>php ./vendor/phpunit/phpunit/composer/bin/phpunit --group phpunit_example</code>.</p> |
31 | | -<p>Also, you should mark your tests as belonging to a group, so they can be run independently. You do this by annotating your test classes with <code>@group group_name</code>. You should have a <code>@group</code> for your module name, and you should also have a <code>@group</code> for integrations, such as <code>views</code>.</p> |
32 | | -<p>So, for instance, to run all of the PHPUnit example tests, you would type <code>./vendor/bin/phpunit --group phpunit_example</code>.</p> |
33 | | -<p>As you can see, including a <code>@group</code> annotation is a good idea.</p>'), |
34 | | - ); |
35 | | - |
36 | | - return $build; |
| 21 | + protected function getModuleName() { |
| 22 | + return 'phpunit_example'; |
37 | 23 | } |
38 | 24 |
|
39 | 25 | } |
0 commit comments