Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Start testing your extension NOW

89 views

Published on

"I really would like to do this testing stuff with TYPO3. But I have no clue where to start." After this presentation, you will.

Published in: Technology
  • Be the first to comment

Start testing your extension NOW

  1. 1. Real Values. Start testing your extension NOW TYPO3camp Berlin 2019 O MORE EXCUSES
  2. 2. Real Values. Well ... I really would like to do this testing stuff. But I have no clue where to start. Most common excuse
  3. 3. Real Values. About ▪ Senior TYPO3 Developer @ sitegeist ▪ TYPO3 CMS Certified Developer ▪ Working with TYPO3 since version 3.8 ▪ TYPO3 developer since 2004 ▪ TYPO3 core contributor since 11/2014 ▪ Cartographer, Food Blogger and Square Dancer ▪ Twitter: @buccaneer23 Jan Helke
  4. 4. Real Values. What to test? I refuse to answer that Audiences often understand "What ONLY to test?" The obvious answer must be "Everything" Ask yourself "Does this piece of code something meaningful?"
  5. 5. Real Values. What (probably) not to test? Classes/Domain/Model • Should do only trivial stuff (e.g. getTitle(), setTitle()) • Business logic should be moved to Services or Utilities (e.g. getValidityDate()) Classes/Domain/Repository • You can rely on the core to test that database stuff Classes/Controller • Should only be in control • Gather data • Call business logic • Assign data to view
  6. 6. Real Values. Testing methods Unit testing • Single units (e.g. single functions) • Closed scope - only own code • No 3rd party requirements (e.g. Database, TYPO3 Core functions) Integration testing (a.k.a. functional testing) • Composed functionality (e.g. "validate form and save values to database") • Useful for public APIs (e.g. REST services) • 3rd party requirements (User) acceptance testing • Frontend functionality
  7. 7. Real Values. All units on deck ./composer.json "require-dev": { "typo3/testing-framework": "^4.12" }, "scripts": { "test:php-unit": "./bin/phpunit --color -d memory_limit=-1 ↵ -c ./Build/Testing/UnitTests.xml", }
  8. 8. Real Values. <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="true" backupStaticAttributes="false" bootstrap="../../vendor/typo3/testing-framework/Resources/Core/Build/ UnitTestsBootstrap.php" convertErrorsToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" verbose="false"> <testsuites> <testsuite name="testing_example"> <directory>../../Extension/testing_example/Tests/Unit</directory> </testsuite> </testsuites> <filter> <!-- add folders explicitly as some TER extensions throw errors --> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">../Extension/testing_example/Classes/</directory> </whitelist> </filter> </phpunit>
  9. 9. Real Values. And the functions as well ./composer.json "require-dev": { "typo3/testing-framework": "^4.12" }, "scripts": { "test:php-function": "rm -rf typo3temp/var/tests/functional-*; ↵ typo3DatabaseName="typo3_functional" typo3DatabaseHost="db" ↵ typo3DatabaseUsername="root" typo3DatabasePassword="root" ↵ ./bin/phpunit -d memory_limit=-1 --colors ↵ -c ./Build/Testing/FunctionalTests.xml" ↵ }
  10. 10. Real Values. <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="true" backupStaticAttributes="false" bootstrap="../../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" convertErrorsToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" verbose="false"> <testsuites> <testsuite name="testing_example"> <directory>../../Extension/testing_example/Tests/Functional</directory> </testsuite> </testsuites> <filter> <!-- add folders explicitly as some TER extensions throw errors --> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">../Extension/testing_example/Classes/</directory> </whitelist> </filter> </phpunit>
  11. 11. Real Values. Bonus: Static code analysis ./composer.json "require-dev": { "phpstan/phpstan": "^0.10.6", "saschaegerer/phpstan-typo3": "^0.10.0" }, "scripts": { "test:php-static": "./bin/phpstan --configuration=./Build/Testing/ ↵ phpstan.neon analyse --no-progress Extension/ --level=5", } ./Build/Testing/phpstan.neon includes: - ../../vendor/saschaegerer/phpstan-typo3/extension.neon parameters: bootstrap: %rootDir%/../../saschaegerer/phpstan-typo3/src/ ↵ PhpstanTypo3Bootstrap.php
  12. 12. Real Values. Finally: pretty pretty code Use the opportunity - run some code style checking all the time ./composer.json "scripts": { "lint:editorconfig": "./bin/editorconfig-checker ./Extension/*", "lint:php": "./bin/php-cs-fixer fix --dry-run --diff ↵ --config ./Build/Testing/.php_cs.php", "test" : [ "@lint:editorconfig", "@lint:php", "@test:php-static", "@test:php-unit", "@test:php-function" ], }
  13. 13. Real Values. Thank you. Questions?
  14. 14. Real Values. Sources • https://github.com/sitegeist/typo3-testing-example • https://www.slideshare.net/JanHelke • https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/Testing/Index.html

×