[TASK] bamboo: Include php 7.2 in test suite
[Packages/TYPO3.CMS.git] / Build / bamboo / src / main / java / core / AbstractCoreSpec.java
1 package core;
2
3 /*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 import java.util.ArrayList;
17
18 import com.atlassian.bamboo.specs.api.builders.BambooKey;
19 import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
20 import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
21 import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;
22 import com.atlassian.bamboo.specs.api.builders.plan.Job;
23 import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
24 import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;
25 import com.atlassian.bamboo.specs.api.builders.plan.configuration.AllOtherPluginsConfiguration;
26 import com.atlassian.bamboo.specs.api.builders.plan.configuration.PluginConfiguration;
27 import com.atlassian.bamboo.specs.api.builders.requirement.Requirement;
28 import com.atlassian.bamboo.specs.api.builders.task.Task;
29 import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
30 import com.atlassian.bamboo.specs.builders.task.CommandTask;
31 import com.atlassian.bamboo.specs.builders.task.NpmTask;
32 import com.atlassian.bamboo.specs.builders.task.ScriptTask;
33 import com.atlassian.bamboo.specs.builders.task.TestParserTask;
34 import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
35 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
36 import com.atlassian.bamboo.specs.model.task.TestParserTaskProperties;
37 import com.atlassian.bamboo.specs.util.MapBuilder;
38
39 /**
40 * Abstract class with common methods of pre-merge and nightly plan
41 */
42 abstract public class AbstractCoreSpec {
43
44 protected static String bambooServerName = "https://bamboo.typo3.com:443";
45 protected static String projectName = "TYPO3 Core";
46 protected static String projectKey = "CORE";
47
48 protected String composerRootVersionEnvironment = "COMPOSER_ROOT_VERSION=8.7.0";
49
50 protected String testingFrameworkBuildPath = "vendor/typo3/testing-framework/Resources/Core/Build/";
51
52 protected String credentialsMysql =
53 "typo3DatabaseName=\"func\"" +
54 " typo3DatabaseUsername=\"funcu\"" +
55 " typo3DatabasePassword=\"funcp\"" +
56 " typo3DatabaseHost=\"localhost\"" +
57 " typo3InstallToolPassword=\"klaus\"";
58
59 protected String credentialsMssql =
60 "typo3DatabaseDriver=\"sqlsrv\"" +
61 " typo3DatabaseName=\"func\"" +
62 " typo3DatabasePassword='Test1234!'" +
63 " typo3DatabaseUsername=\"SA\"" +
64 " typo3DatabaseHost=\"localhost\"" +
65 " typo3DatabasePort=\"1433\"" +
66 " typo3DatabaseCharset=\"utf-8\"" +
67 " typo3InstallToolPassword=\"klaus\"";
68
69 protected String credentialsPgsql =
70 "typo3DatabaseDriver=\"pdo_pgsql\"" +
71 " typo3DatabaseName=\"func\"" +
72 " typo3DatabaseUsername=\"bamboo\"" +
73 " typo3DatabaseHost=\"localhost\"" +
74 " typo3InstallToolPassword=\"klaus\"";
75
76 /**
77 * Default permissions on core plans
78 *
79 * @param projectName
80 * @param planName
81 * @return
82 */
83 protected PlanPermissions getDefaultPlanPermissions(String projectKey, String planKey) {
84 return new PlanPermissions(new PlanIdentifier(projectKey, planKey))
85 .permissions(new Permissions()
86 .groupPermissions("TYPO3 GmbH", PermissionType.ADMIN, PermissionType.VIEW, PermissionType.EDIT, PermissionType.BUILD, PermissionType.CLONE)
87 .groupPermissions("TYPO3 Core Team", PermissionType.VIEW, PermissionType.BUILD)
88 .loggedInUserPermissions(PermissionType.VIEW)
89 .anonymousUserPermissionView()
90 );
91 }
92
93 /**
94 * Default plan plugin configuration
95 *
96 * @return
97 */
98 protected PluginConfiguration getDefaultPlanPluginConfiguration() {
99 return new AllOtherPluginsConfiguration()
100 .configuration(new MapBuilder()
101 .put("custom", new MapBuilder()
102 .put("artifactHandlers.useCustomArtifactHandlers", "false")
103 .put("buildExpiryConfig", new MapBuilder()
104 .put("duration", "30")
105 .put("period", "days")
106 .put("labelsToKeep", "")
107 .put("expiryTypeResult", "true")
108 .put("buildsToKeep", "")
109 .put("enabled", "true")
110 .build()
111 )
112 .build()
113 )
114 .build()
115 );
116 }
117
118 /**
119 * Default job plugin configuration
120 *
121 * @return
122 */
123 protected PluginConfiguration getDefaultJobPluginConfiguration() {
124 return new AllOtherPluginsConfiguration()
125 .configuration(new MapBuilder()
126 .put("repositoryDefiningWorkingDirectory", -1)
127 .put("custom", new MapBuilder()
128 .put("auto", new MapBuilder()
129 .put("regex", "")
130 .put("label", "")
131 .build()
132 )
133 .put("buildHangingConfig.enabled", "false")
134 .put("ncover.path", "")
135 .put("clover", new MapBuilder()
136 .put("path", "")
137 .put("license", "")
138 .put("useLocalLicenseKey", "true")
139 .build()
140 )
141 .build()
142 )
143 .build()
144 );
145 }
146
147 /**
148 * Job composer validate
149 */
150 protected Job getJobComposerValidate() {
151 return new Job("Validate composer.json", new BambooKey("VC"))
152 .description("Validate composer.json before actual tests are executed")
153 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
154 .tasks(
155 this.getTaskGitCloneRepository(),
156 this.getTaskGitCherryPick(),
157 new CommandTask()
158 .description("composer validate")
159 .executable("composer").argument("validate")
160 .environmentVariables(this.composerRootVersionEnvironment)
161 )
162 .cleanWorkingDirectory(true);
163 }
164
165 /**
166 * Job acceptance test installs system on mysql
167 *
168 * @param Requirement requirement
169 * @param String requirementIdentfier
170 */
171 protected Job getJobAcceptanceTestInstallMysql(Requirement requirement, String requirementIdentifier) {
172 return new Job("Accept inst my " + requirementIdentifier, new BambooKey("ACINSTMY" + requirementIdentifier))
173 .description("Install TYPO3 on mysql and create empty frontend page " + requirementIdentifier)
174 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
175 .tasks(
176 this.getTaskGitCloneRepository(),
177 this.getTaskGitCherryPick(),
178 this.getTaskComposerInstall(),
179 this.getTaskPrepareAcceptanceTest(),
180 new CommandTask()
181 .description("Execute codeception AcceptanceInstallMysql suite")
182 .executable("codecept")
183 .argument("run AcceptanceInstallMysql -d -c " + this.testingFrameworkBuildPath + "AcceptanceTestsInstallMysql.yml --xml reports.xml --html reports.html")
184 .environmentVariables(this.credentialsMysql)
185 )
186 .finalTasks(
187 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
188 .resultDirectories("typo3temp/var/tests/AcceptanceReportsInstallMysql/reports.xml"),
189 this.getTaskDeleteMysqlDatabases(),
190 this.getTaskTearDownAcceptanceTestSetup()
191 )
192 .requirements(
193 requirement
194 )
195 .artifacts(new Artifact()
196 .name("Test Report")
197 .copyPattern("typo3temp/var/tests/AcceptanceReportsInstallMysql/")
198 .shared(false)
199 )
200 .cleanWorkingDirectory(true);
201 }
202
203 /**
204 * Job acceptance test installs system and introduction package on pgsql
205 *
206 * @param Requirement requirement
207 * @param String requirementIdentfier
208 */
209 protected Job getJobAcceptanceTestInstallPgsql(Requirement requirement, String requirementIdentifier) {
210 return new Job("Accept inst pg " + requirementIdentifier, new BambooKey("ACINSTPG" + requirementIdentifier))
211 .description("Install TYPO3 on pgsql and load introduction package " + requirementIdentifier)
212 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
213 .tasks(
214 this.getTaskGitCloneRepository(),
215 this.getTaskGitCherryPick(),
216 this.getTaskComposerInstall(),
217 this.getTaskPrepareAcceptanceTest(),
218 new CommandTask()
219 .description("Execute codeception AcceptanceInstallPgsql suite")
220 .executable("codecept")
221 .argument("run AcceptanceInstallPgsql -d -c " + this.testingFrameworkBuildPath + "AcceptanceTestsInstallPgsql.yml --xml reports.xml --html reports.html")
222 .environmentVariables(this.credentialsPgsql)
223 )
224 .finalTasks(
225 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
226 .resultDirectories("typo3temp/var/tests/AcceptanceReportsInstallPgsql/reports.xml"),
227 this.getTaskDeletePgsqlDatabases(),
228 this.getTaskTearDownAcceptanceTestSetup()
229 )
230 .requirements(
231 requirement
232 )
233 .artifacts(new Artifact()
234 .name("Test Report")
235 .copyPattern("typo3temp/var/tests/AcceptanceReportsInstallPgsql/")
236 .shared(false)
237 )
238 .cleanWorkingDirectory(true);
239 }
240
241 /**
242 * Jobs for mysql based acceptance tests
243 *
244 * @param int numberOfChunks
245 * @param Requirement requirement
246 * @param String requirementIdentifier
247 */
248 protected ArrayList<Job> getJobsAcceptanceTestsMysql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
249 ArrayList<Job> jobs = new ArrayList<Job>();
250
251 for (int i=1; i<=numberOfChunks; i++) {
252 jobs.add(new Job("Accept my " + requirementIdentifier + " 0" + i, new BambooKey("ACMY" + requirementIdentifier + "0" + i))
253 .description("Run acceptance tests" + requirementIdentifier)
254 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
255 .tasks(
256 this.getTaskGitCloneRepository(),
257 this.getTaskGitCherryPick(),
258 this.getTaskComposerInstall(),
259 this.getTaskPrepareAcceptanceTest(),
260 new ScriptTask()
261 .description("Split acceptance tests")
262 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
263 .inlineBody(
264 this.getScriptTaskBashInlineBody() +
265 "./" + this.testingFrameworkBuildPath + "Scripts/splitAcceptanceTests.sh " + numberOfChunks + "\n"
266 ),
267 new CommandTask()
268 .description("Execute codeception acceptance suite group " + i)
269 .executable("codecept")
270 .argument("run Acceptance -d -g AcceptanceTests-Job-" + i + " -c " + this.testingFrameworkBuildPath + "AcceptanceTests.yml --xml reports.xml --html reports.html")
271 .environmentVariables(this.credentialsMysql)
272 )
273 .finalTasks(
274 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
275 .resultDirectories("typo3temp/var/tests/AcceptanceReports/reports.xml"),
276 this.getTaskDeleteMysqlDatabases(),
277 this.getTaskTearDownAcceptanceTestSetup()
278 )
279 .requirements(
280 requirement
281 )
282 .artifacts(new Artifact()
283 .name("Test Report")
284 .copyPattern("typo3temp/var/tests/AcceptanceReports/")
285 .shared(false)
286 )
287 .cleanWorkingDirectory(true)
288 );
289 }
290
291 return jobs;
292 }
293
294 /**
295 * Jobs for mysql based functional tests
296 *
297 * @param int numberOfChunks
298 * @param Requirement requirement
299 * @param String requirementIdentifier
300 */
301 protected ArrayList<Job> getJobsFunctionalTestsMysql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
302 ArrayList<Job> jobs = new ArrayList<Job>();
303
304 for (int i=0; i<numberOfChunks; i++) {
305 jobs.add(new Job("Func mysql " + requirementIdentifier + " 0" + i, new BambooKey("FMY" + requirementIdentifier + "0" + i))
306 .description("Run functional tests on mysql DB " + requirementIdentifier)
307 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
308 .tasks(
309 this.getTaskGitCloneRepository(),
310 this.getTaskGitCherryPick(),
311 this.getTaskComposerInstall(),
312 this.getTaskSplitFunctionalJobs(numberOfChunks),
313 new ScriptTask()
314 .description("Run phpunit with functional chunk 0" + i)
315 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
316 .inlineBody(
317 this.getScriptTaskBashInlineBody() +
318 "./bin/phpunit --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
319 )
320 .environmentVariables(this.credentialsMysql)
321 )
322 .finalTasks(
323 this.getTaskDeleteMysqlDatabases(),
324 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
325 .resultDirectories("test-reports/phpunit.xml")
326 )
327 .requirements(
328 requirement
329 )
330 .cleanWorkingDirectory(true)
331 );
332 }
333
334 return jobs;
335 }
336
337 /**
338 * Jobs for mssql based functional tests
339 *
340 * @param int numberOfChunks
341 * @param Requirement requirement
342 * @param String requirementIdentifier
343 */
344 protected ArrayList<Job> getJobsFunctionalTestsMssql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
345 ArrayList<Job> jobs = new ArrayList<Job>();
346
347 for (int i=0; i<numberOfChunks; i++) {
348 jobs.add(new Job("Func mssql " + requirementIdentifier + " 0" + i, new BambooKey("FMS" + requirementIdentifier + "0" + i))
349 .description("Run functional tests on mysql DB " + requirementIdentifier)
350 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
351 .tasks(
352 this.getTaskGitCloneRepository(),
353 this.getTaskGitCherryPick(),
354 this.getTaskComposerInstall(),
355 this.getTaskSplitFunctionalJobs(numberOfChunks),
356 new ScriptTask()
357 .description("Run phpunit with functional chunk 0" + i)
358 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
359 .inlineBody(
360 this.getScriptTaskBashInlineBody() +
361 "./bin/phpunit --exclude-group not-mssql --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
362 )
363 .environmentVariables(this.credentialsMssql)
364 )
365 .finalTasks(
366 this.getTaskDeleteMssqlDatabases(),
367 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
368 .resultDirectories("test-reports/phpunit.xml")
369 )
370 .requirements(
371 requirement
372 )
373 .cleanWorkingDirectory(true)
374 .enabled(false)
375 );
376 }
377
378 return jobs;
379 }
380
381 /**
382 * Jobs for pgsql based functional tests
383 *
384 * @param int numberOfChunks
385 * @param Requirement requirement
386 * @param String requirementIdentifier
387 */
388 protected ArrayList<Job> getJobsFunctionalTestsPgsql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
389 ArrayList<Job> jobs = new ArrayList<Job>();
390
391 for (int i=0; i<numberOfChunks; i++) {
392 jobs.add(new Job("Func pgsql " + requirementIdentifier + " 0" + i, new BambooKey("FPG" + requirementIdentifier + "0" + i))
393 .description("Run functional tests on pgsql DB " + requirementIdentifier)
394 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
395 .tasks(
396 this.getTaskGitCloneRepository(),
397 this.getTaskGitCherryPick(),
398 this.getTaskComposerInstall(),
399 this.getTaskSplitFunctionalJobs(numberOfChunks),
400 new ScriptTask()
401 .description("Run phpunit with functional chunk 0" + i)
402 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
403 .inlineBody(
404 this.getScriptTaskBashInlineBody() +
405 "./bin/phpunit --exclude-group not-postgres --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
406 )
407 .environmentVariables(this.credentialsPgsql)
408 )
409 .finalTasks(
410 this.getTaskDeletePgsqlDatabases(),
411 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
412 .resultDirectories("test-reports/phpunit.xml")
413 )
414 .requirements(
415 requirement
416 )
417 .cleanWorkingDirectory(true)
418 );
419 }
420
421 return jobs;
422 }
423
424 /**
425 * Job with various smaller script tests
426 */
427 protected Job getJobIntegrationVarious() {
428 // Exception code checker, xlf, permissions, rst file check
429 return new Job("Integration various", new BambooKey("CDECC"))
430 .description("Checks duplicate exceptions, git submodules, xlf files, permissions, rst")
431 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
432 .tasks(
433 this.getTaskGitCloneRepository(),
434 this.getTaskGitCherryPick(),
435 new ScriptTask()
436 .description("Run duplicate exception code check script")
437 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
438 .inlineBody(
439 this.getScriptTaskBashInlineBody() +
440 "./Build/Scripts/duplicateExceptionCodeCheck.sh\n"
441 ),
442 new ScriptTask()
443 .description("Run git submodule status and verify there are none")
444 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
445 .inlineBody(
446 this.getScriptTaskBashInlineBody() +
447 "if [[ `git submodule status 2>&1 | wc -l` -ne 0 ]]; then\n" +
448 " echo \\\"Found a submodule definition in repository\\\";\n" +
449 " exit 99;\n" +
450 "fi\n"
451 ),
452 new ScriptTask()
453 .description("Run permission check script")
454 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
455 .inlineBody(
456 this.getScriptTaskBashInlineBody() +
457 "./Build/Scripts/checkFilePermissions.sh\n"
458 ),
459 new ScriptTask()
460 .description("Run xlf check")
461 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
462 .inlineBody(
463 this.getScriptTaskBashInlineBody() +
464 "./Build/Scripts/xlfcheck.sh"
465 ),
466 new ScriptTask()
467 .description("Run rst check")
468 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
469 .inlineBody(
470 this.getScriptTaskBashInlineBody() +
471 "./Build/Scripts/validateRstFiles.sh"
472 ),
473 new ScriptTask()
474 .description("Run path length check")
475 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
476 .inlineBody(
477 this.getScriptTaskBashInlineBody() +
478 "./Build/Scripts/maxFilePathLength.sh"
479 )
480 )
481 .requirements(
482 this.getRequirementPhpVersion70Or71Or72()
483 )
484 .cleanWorkingDirectory(true);
485 }
486
487 /**
488 * Job for javascript unit tests
489 */
490 protected Job getJobUnitJavaScript() {
491 return new Job("Unit JavaScript", new BambooKey("JSUT"))
492 .description("Run JavaScript unit tests")
493 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
494 .tasks(
495 this.getTaskGitCloneRepository(),
496 this.getTaskGitCherryPick(),
497 this.getTaskComposerInstall(),
498 new NpmTask()
499 .description("npm install in Build/ dir")
500 .nodeExecutable("Node.js")
501 .workingSubdirectory("Build/")
502 .command("install"),
503 new ScriptTask()
504 .description("Run tests")
505 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
506 .inlineBody(
507 this.getScriptTaskBashInlineBody() +
508 "./Build/node_modules/karma/bin/karma start " + this.testingFrameworkBuildPath + "Configuration/JSUnit/karma.conf.js --single-run"
509 )
510 )
511 .finalTasks(
512 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
513 .resultDirectories("typo3temp/var/tests/*")
514 )
515 .requirements(
516 this.getRequirementPhpVersion70Or71Or72()
517 )
518 .artifacts(
519 new Artifact()
520 .name("Clover Report (System)")
521 .copyPattern("**/*.*")
522 .location("Build/target/site/clover")
523 .shared(false)
524 )
525 .cleanWorkingDirectory(true);
526 }
527
528 /**
529 * Job for PHP lint
530 *
531 * @param Requirement requirement
532 * @param String requirementIdentfier
533 */
534 protected Job getJobLintPhp(Requirement requirement, String requirementIdentifier) {
535 return new Job("Lint " + requirementIdentifier, new BambooKey("L" + requirementIdentifier))
536 .description("Run php -l on source files for linting " + requirementIdentifier)
537 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
538 .tasks(
539 this.getTaskGitCloneRepository(),
540 this.getTaskGitCherryPick(),
541 new ScriptTask()
542 .description("Run php lint")
543 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
544 .inlineBody(
545 this.getScriptTaskBashInlineBody() +
546 "find . -name \\*.php -print0 | xargs -0 -n1 -P2 php -l >/dev/null\n"
547 )
548 )
549 .requirements(
550 requirement
551 )
552 .cleanWorkingDirectory(true);
553 }
554
555 /**
556 * Job for lint npm scss and typescript
557 */
558 protected Job getJobLintScssTs() {
559 return new Job("Lint scss ts", new BambooKey("LSTS"))
560 .description("Run npm lint in Build/ dir")
561 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
562 .tasks(
563 this.getTaskGitCloneRepository(),
564 this.getTaskGitCherryPick(),
565 new NpmTask()
566 .description("npm install in Build/ dir")
567 .nodeExecutable("Node.js")
568 .workingSubdirectory("Build/")
569 .command("install"),
570 new NpmTask()
571 .description("Run npm lint")
572 .nodeExecutable("Node.js")
573 .workingSubdirectory("Build/")
574 .command("run lint")
575 )
576 .requirements(
577 new Requirement("system.imageVersion")
578 )
579 .cleanWorkingDirectory(true);
580 }
581
582 /**
583 * Job for unit testing PHP
584 *
585 * @param Requirement requirement
586 * @param String requirementIdentfier
587 */
588 protected Job getJobUnitPhp(Requirement requirement, String requirementIdentifier) {
589 return new Job("Unit " + requirementIdentifier, new BambooKey("UT" + requirementIdentifier))
590 .description("Run unit tests " + requirementIdentifier)
591 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
592 .tasks(
593 this.getTaskGitCloneRepository(),
594 this.getTaskGitCherryPick(),
595 this.getTaskComposerInstall(),
596 new ScriptTask()
597 .description("Run phpunit")
598 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
599 .inlineBody(
600 this.getScriptTaskBashInlineBody() +
601 this.getScriptTaskBashPhpNoXdebug() +
602 "php_no_xdebug bin/phpunit --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml"
603 )
604 )
605 .finalTasks(
606 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
607 .resultDirectories("test-reports/phpunit.xml")
608 )
609 .requirements(
610 requirement
611 )
612 .cleanWorkingDirectory(true);
613 }
614
615 /**
616 * Jobs for unit testing PHP in random test order
617 *
618 * @param int numberOfRuns
619 * @param Requirement requirement
620 * @param String requirementIdentfier
621 */
622 protected ArrayList<Job> getJobUnitPhpRandom(int numberOfRuns, Requirement requirement, String requirementIdentifier) {
623 ArrayList<Job> jobs = new ArrayList<Job>();
624
625 for (int i=0; i<numberOfRuns; i++) {
626 jobs.add(new Job("Unit " + requirementIdentifier + " random 0" + i, new BambooKey("UTR" + requirementIdentifier + "0" + i))
627 .description("Run unit tests on " + requirementIdentifier + " in random order 0" + i)
628 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
629 .tasks(
630 this.getTaskGitCloneRepository(),
631 this.getTaskGitCherryPick(),
632 this.getTaskComposerInstall(),
633 new ScriptTask()
634 .description("Run phpunit-randomizer")
635 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
636 .inlineBody(
637 this.getScriptTaskBashInlineBody() +
638 this.getScriptTaskBashPhpNoXdebug() +
639 "php_no_xdebug bin/phpunit-randomizer --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml --order rand"
640 )
641 )
642 .finalTasks(
643 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
644 .resultDirectories("test-reports/phpunit.xml")
645 )
646 .requirements(
647 requirement
648 )
649 .cleanWorkingDirectory(true)
650 );
651 }
652
653 return jobs;
654 }
655
656 /**
657 * Task definition for basic core clone of linked default repository
658 */
659 protected Task getTaskGitCloneRepository() {
660 return new VcsCheckoutTask()
661 .description("Checkout git core")
662 .checkoutItems(new CheckoutItem().defaultRepository())
663 .cleanCheckout(true);
664 }
665
666 /**
667 * Task definition to cherry pick a patch set from gerrit on top of cloned core
668 */
669 protected Task getTaskGitCherryPick() {
670 return new ScriptTask()
671 .description("Gerrit cherry pick")
672 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
673 .inlineBody(
674 this.getScriptTaskBashInlineBody() +
675 "CHANGEURL=${bamboo.changeUrl}\n" +
676 "CHANGEURLID=${CHANGEURL#https://review.typo3.org/}\n" +
677 "PATCHSET=${bamboo.patchset}\n" +
678 "\n" +
679 "if [[ $CHANGEURL ]]; then\n" +
680 " gerrit-cherry-pick https://review.typo3.org/Packages/TYPO3.CMS $CHANGEURLID/$PATCHSET || exit 1\n" +
681 "fi\n"
682 );
683 }
684
685 /**
686 * Task definition to execute composer install
687 */
688 protected Task getTaskComposerInstall() {
689 return new CommandTask()
690 .description("composer install")
691 .executable("composer")
692 .argument("install -n")
693 .environmentVariables(this.composerRootVersionEnvironment);
694 }
695
696 /**
697 * Task to prepare an acceptance test starting selenium and others
698 */
699 protected Task getTaskPrepareAcceptanceTest() {
700 return new ScriptTask()
701 .description("Start php web server, chromedriver, prepare environment")
702 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
703 .inlineBody(
704 this.getScriptTaskBashInlineBody() +
705 "php -S localhost:8000 >/dev/null 2>&1 &\n" +
706 "echo $! > phpserver.pid\n" +
707 "\n" +
708 "./bin/chromedriver --url-base=/wd/hub >/dev/null 2>&1 &\n" +
709 "echo $! > chromedriver.pid\n" +
710 "\n" +
711 "mkdir -p typo3temp/var/tests/\n"
712 );
713 }
714
715 /**
716 * Task to delete any created mysql test databases, used as final task
717 */
718 protected Task getTaskDeleteMysqlDatabases() {
719 return new ScriptTask()
720 .description("Delete mysql test dbs")
721 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
722 .inlineBody(
723 this.getScriptTaskBashInlineBody() +
724 "DB_STARTS_WITH=\"func_\"\n" +
725 "MUSER=\"funcu\"\n" +
726 "MPWD=\"funcp\"\n" +
727 "MYSQL=\"mysql\"\n" +
728 "DBS=\"$($MYSQL -u $MUSER -p\"$MPWD\" -Bse 'show databases')\"\n" +
729 "\n" +
730 "for db in $DBS; do\n" +
731 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
732 " echo \"Deleting $db\"\n" +
733 " $MYSQL -u $MUSER -p\"$MPWD\" -Bse \"drop database $db\"\n" +
734 " fi\n" +
735 "done\n"
736 );
737 }
738
739 /**
740 * Task to delete any created mssql test databases, used as final task
741 */
742 protected Task getTaskDeleteMssqlDatabases() {
743 return new ScriptTask()
744 .description("Delete mssql test dbs")
745 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
746 .inlineBody(
747 this.getScriptTaskBashInlineBody() +
748 "DBS=`/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q 'select name from sys.databases' | grep '^func_'`\n" +
749 "\n" +
750 "for db in $DBS; do\n" +
751 " echo \"Deleteing $db\"\n" +
752 " /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q \"drop database $db\"\n" +
753 "done\n"
754 );
755 }
756
757 /**
758 * Task to delete any created pgsql test databases, used as final task
759 */
760 protected Task getTaskDeletePgsqlDatabases() {
761 return new ScriptTask()
762 .description("Delete pgsql test dbs")
763 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
764 .inlineBody(
765 this.getScriptTaskBashInlineBody() +
766 "DB_STARTS_WITH=\"func_\"\n" +
767 "PGUSER=\"bamboo\"\n" +
768 "DBS=\"$(/usr/bin/psql -qtA -c 'SELECT datname FROM pg_database WHERE datistemplate = false;' postgres)\"\n" +
769 "\n" +
770 "for db in $DBS; do\n" +
771 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
772 " echo \"Deleting $db\"\n" +
773 " /usr/bin/psql -qtA -c \"DROP DATABASE $db\" postgres\n" +
774 " fi\n" +
775 "done\n"
776 );
777 }
778
779 /**
780 * Task to stop selenium and friends, opposite of getTaskPrepareAcceptanceTest, used as final task
781 */
782 protected Task getTaskTearDownAcceptanceTestSetup() {
783 return new ScriptTask()
784 .description("Stop acceptance test services like chromedriver and friends")
785 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
786 .inlineBody(
787 this.getScriptTaskBashInlineBody() +
788 "kill `cat phpserver.pid`\n" +
789 "kill `cat chromedriver.pid`\n"
790 );
791 }
792
793 /**
794 * Task to split functional jobs into chunks
795 */
796 protected Task getTaskSplitFunctionalJobs(int numberOfJobs) {
797 return new ScriptTask()
798 .description("Create list of test files to execute per job")
799 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
800 .inlineBody(
801 this.getScriptTaskBashInlineBody() +
802 "./" + this.testingFrameworkBuildPath + "Scripts/splitFunctionalTests.sh " + numberOfJobs
803 );
804 }
805
806 /**
807 * Requirement for php 7.0
808 */
809 protected Requirement getRequirementPhpVersion70() {
810 return new Requirement("system.phpVersion")
811 .matchValue("7.0")
812 .matchType(Requirement.MatchType.EQUALS);
813 }
814
815 /**
816 * Requirement for php 7.1
817 */
818 protected Requirement getRequirementPhpVersion71() {
819 return new Requirement("system.phpVersion")
820 .matchValue("7.1")
821 .matchType(Requirement.MatchType.EQUALS);
822 }
823
824 /**
825 * Requirement for php 7.2
826 */
827 protected Requirement getRequirementPhpVersion72() {
828 return new Requirement("system.phpVersion")
829 .matchValue("7.2")
830 .matchType(Requirement.MatchType.EQUALS);
831 }
832
833 /**
834 * Requirement for php 7.0 or 7.1
835 */
836 protected Requirement getRequirementPhpVersion70Or71() {
837 return new Requirement("system.phpVersion")
838 .matchValue("7\\.0|7\\.1")
839 .matchType(Requirement.MatchType.MATCHES);
840 }
841
842 /**
843 * Requirement for php 7.0 or 7.1 or 7.2
844 */
845 protected Requirement getRequirementPhpVersion70Or71Or72() {
846 return new Requirement("system.phpVersion")
847 .matchValue("7\\.0|7\\.1|7\\.2")
848 .matchType(Requirement.MatchType.MATCHES);
849 }
850
851 /**
852 * A bash header for script tasks forking a bash if needed
853 */
854 protected String getScriptTaskBashInlineBody() {
855 return
856 "#!/bin/bash\n" +
857 "\n" +
858 "if [ \"$(ps -p \"$$\" -o comm=)\" != \"bash\" ]; then\n" +
859 " bash \"$0\" \"$@\"\n" +
860 " exit \"$?\"\n" +
861 "fi\n" +
862 "\n";
863 }
864
865 /**
866 * A bash function providing a php bin without xdebug
867 */
868 protected String getScriptTaskBashPhpNoXdebug() {
869 return
870 "php_no_xdebug () {\n" +
871 " temporaryPath=\"$(mktemp -t php.XXXX).ini\"\n" +
872 " php -i | grep \"\\.ini\" | grep -o -e '\\(/[A-Za-z0-9._-]\\+\\)\\+\\.ini' | grep -v xdebug | xargs awk 'FNR==1{print \"\"}1' > \"${temporaryPath}\"\n" +
873 " php -n -c \"${temporaryPath}\" \"$@\"\n" +
874 " RETURN=$?\n" +
875 " rm -f \"${temporaryPath}\"\n" +
876 " exit $RETURN\n" +
877 "}\n" +
878 "\n";
879 }
880 }