1- .. include :: /Includes.rst.txt
2- .. index :: pair: Testing; Extensions
3- .. _testing-extensions :
1+ .. include :: /Includes.rst.txt
2+ .. index :: pair: Testing; Extensions
3+ .. _testing-extensions :
44
55=================
66Extension testing
@@ -21,10 +21,33 @@ The following test strategies should be applied to improve your code quality.
2121
2222.. contents :: Table of contents
2323
24- .. seealso :: See also the :ref:`Testing enetcache <testing-tutorial-enetcache>`
25- that used to be displayed on this page.
24+ .. tip ::
25+ Using the extension kickstarter (:composer: `friendsoftypo3/kickstarter `) you
26+ can create a testing environment for your extension using the command
27+ `vendor/bin/typo3 make:testenv `.
2628
27- .. _testing-extensions-linting :
29+ .. _testing-extensions-composer :
30+
31+ Composer install / update before running extensions tests
32+ =========================================================
33+
34+ If you used :composer: `friendsoftypo3/kickstarter ` to create your testing
35+ environment all packages are listed in the :file: `composer.json ` section
36+ `require-dev `. You must therefore run `composer update ` with dev dependencies
37+ using the correct PHP version. The :file: `runTests.sh ` script created by the
38+ kickstarter contains a script to do that:
39+
40+ .. code-block :: bash
41+
42+ Build/Scripts/runTests.sh -s composerUpdate
43+
44+ If you want to test on a version different to the default PHP version:
45+
46+ .. code-block :: bash
47+
48+ Build/Scripts/runTests.sh -s composerUpdate -p 8.4
49+
50+ .. _testing-extensions-linting :
2851
2952Linting
3053=======
@@ -42,9 +65,14 @@ Depending on your extension, any other file format can be linted
4265too, if there is tooling for that (for example validating XML files
4366against a XSD schema).
4467
45- .. todo: Add links to examples from blog extension and maybe others here
68+ If you used the :composer: `friendsoftypo3/kickstarter ` to create your testing
69+ environment you can run the linting with:
4670
47- .. _testing-extensions-cgl :
71+ .. code-block :: bash
72+
73+ Build/Scripts/runTests.sh -s lint
74+
75+ .. _testing-extensions-cgl :
4876
4977Coding guidelines (CGL)
5078=======================
@@ -60,12 +88,17 @@ Common tools to help with applying coding guidelines are
6088You can find more information in the :ref: `Coding guidelines <t3coreapi:cgl >`
6189section.
6290
63- .. todo: Add links to examples from blog extension and maybe others here
91+ If you used the :composer: `friendsoftypo3/kickstarter ` to create your testing
92+ environment you can run the CGL tests with:
6493
65- .. _ testing-extensions-static :
94+ .. code-block :: bash
6695
67- Static code analysis
68- ====================
96+ Build/Scripts/runTests.sh -s cgl
97+
98+ .. _testing-extensions-static :
99+
100+ Static code analysis (PHPStan / Psalm)
101+ ======================================
69102
70103Static code analysis tools are highly recommended to be used with PHP. The most
71104common tools used are `PHPStan <https://phpstan.org >`__ and `Psalm
@@ -74,12 +107,17 @@ rules and levels you apply: You should use one.
74107
75108There are also static code analysis tools for TypeScript and JavaScript.
76109
77- .. todo: Link to a detailed chapter on static code analysis and to examples
110+ If you used the :composer: `friendsoftypo3/kickstarter ` to create your testing
111+ environment you can run static code analysis tests, using `phpstan `:
112+
113+ .. code-block :: bash
78114
79- .. _ testing-extensions-unit :
115+ Build/Scripts/runTests.sh -s phpstan
80116
81- Unit tests
82- ==========
117+ .. _testing-extensions-unit :
118+
119+ Unit tests (PHPUnit!)
120+ ====================
83121
84122Unit tests are executing the code to be tested and define input and their
85123expected outcome. They are run on an isolated classes or methods.
@@ -95,9 +133,20 @@ configurations and settings and everything done during
95133
96134See also :ref: `Writing unit tests <testing-writing-unit >`
97135
98- .. todo: Add examples
136+ If you used the :composer: `friendsoftypo3/kickstarter ` to create your testing
137+ environment you can run unit tests like this:
138+
139+ .. code-block :: bash
140+
141+ Build/Scripts/runTests.sh -s unit
142+
143+ To run a specific test isolated use:
99144
100- .. _testing-extensions-functional :
145+ .. code-block :: bash
146+
147+ Build/Scripts/runTests.sh -s unit -- Tests/Unit/Service/MyServiceTest.php
148+
149+ .. _testing-extensions-functional :
101150
102151Functional tests
103152================
@@ -122,9 +171,30 @@ TYPO3 environment being present.
122171
123172See also :ref: `Writing functional tests <testing-writing-functional >`
124173
125- .. todo: Add examples
174+ If you used the :composer: `friendsoftypo3/kickstarter ` to create your testing
175+ environment you can run unit tests like this:
176+
177+ .. code-block :: bash
178+
179+ Build/Scripts/runTests.sh -s functional
180+
181+ To run a specific test isolated use:
182+
183+ .. code-block :: bash
184+
185+ Build/Scripts/runTests.sh -s functional -- Tests/Functional/Service/MyServiceTest.php
186+
187+ It is possible to run the tests using different database systems and or PHP
188+ versions. Before you run the tests with a different PHP version, do a
189+ `composerUpdate ` with the same version to ensure that composer has been run
190+ with the correct PHP version.
191+
192+ .. code-block :: bash
193+
194+ Build/Scripts/runTests.sh -s composerUpdate -p 8.4
195+ Build/Scripts/runTests.sh -s functional -p 8.4 -d postgres
126196
127- .. _testing-extensions-acceptance :
197+ .. _testing-extensions-acceptance :
128198
129199Acceptance tests
130200================
@@ -135,7 +205,7 @@ scenarios in the TYPO3 backend.
135205
136206See also :ref: `Writing acceptance tests <testing-writing-acceptance >`
137207
138- .. _testing-extensions-organization :
208+ .. _testing-extensions-organization :
139209
140210Organizing and storing the commands
141211===================================
0 commit comments