Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit testing with TYPO3

Oliver Klee
October 25, 2015

Unit testing with TYPO3

Oliver Klee

October 25, 2015
Tweet

More Decks by Oliver Klee

Other Decks in Technology

Transcript

  1. The phpunit extension has it all phpunit (TYPO3 extension) PHPUnit

    (Composer package) Testrunner (back-end- module) Testrunner
 (CLI module) Testing framework for FE & DB
  2. Test suite Test case Test Two tests meet in a

    bar ... Assertion Test Test Test case
  3. The life cycle of a unit test new FooTest(); setUp();

    /** @test */ lifeIsGood(); tearDown();
  4. 4 test phases Setup Exercise Verify Teardown setUp() in the

    test method call assert… tearDown() https://robots.thoughtbot.com/four-phase-test
  5. Use meaningful unit test names classCanBeInstantiated setTitleSetsTitle setSizeWithZeroThrowsException hasTitleForEmptyTitleReturnsFalse Name

    the behavior. Name the preconditions. Mention the method. Dont‘t use "works" or "correctly". measureFrubbleWorksCorrectly
  6. The testing framework is created quickly /** * @var Tx_Phpunit_Framework

    */ protected $testingFramework = NULL; protected function setUp() { $this->testingFramework = new Tx_Phpunit_Framework('tx_news2'); } protected function tearDown() { $this->testingFramework->cleanUp(); } CREATE TABLE tx_news2_domain_model_news ( … is_dummy_record tinyint(1) unsigned DEFAULT '0' NOT NULL, … discard the FE,
 delete DB records,
 delete files
  7. $recordUid = $tf->createRecord($tableName, array $recordData = array()); The testing framework

    can fake almost everything $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0); $tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign); $numberOfRecords = $tf->countRecords($tableName, $whereClause = ''); $success = $tf->existsRecord($tableName, $whereClause = ''); $success = $tf->existsRecordWithUid($tableName, $uid); $success = $tf->existsExactlyOneRecord($tableName, $whereClause = '');
  8. $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups =

    '', array $recordData = array()); $userUid = $tf->createAndLoginFrontEndUser($groups = '', array $recordData = array()); $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $tf->loginFrontEndUser($userId); $tf->logoutFrontEndUser(); $isLoggedIn = $tf->isLoggedIn(); The testing framework can fake almost everything
  9. $path = $tf->createDummyFile($fileName = 'test.txt', $content = ''); $path =

    $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array()); $tf->deleteDummyFile($fileName); $tf->deleteDummyFolder($folderName); $path = $tf->createDummyFolder($folderName); The testing framework can fake almost everything