SlideShare une entreprise Scribd logo
1  sur  112
Test-Driven Development
for TYPO3




Oliver Klee, 2011-12-13 and 2011-12-14
typo3-coding@oliverklee.de
Unit
tests?
Manual testing is cumbersome
Automated
testing is
fast
Unit tests for the
 Realty Manager
   extension
more than
1600 tests
in less than 60
    seconds
Verify that your code
does what you expect
Make sure that your
changes won‘t break
           anything
Keep
        other coders
from breaking your code
Don‘t break anything
even in complex projects
Create asafety net
   for refactoring
Green feels good!
Green feels good!
Know
   your
  tools
The phpunit extension
             has it all
The phpunit extension
               has it all
phpunit (TYPO3 extension)
The phpunit extension
               has it all
phpunit (TYPO3 extension)
 PHPUnit (PEAR package)
The phpunit extension
               has it all
phpunit (TYPO3 extension)
 PHPUnit (PEAR package)

 Testrunner
 (back-end-
  module)
The phpunit extension
               has it all
phpunit (TYPO3 extension)
 PHPUnit (PEAR package)

 Testrunner    Testrunner
 (back-end-
  module)     (CLI module)
The phpunit extension
               has it all
phpunit (TYPO3 extension)
 PHPUnit (PEAR package)
  Testing framework for FE & DB
 Testrunner         Testrunner
 (back-end-
  module)          (CLI module)
Let‘s get
some terms
  straight
Two tests
meet in a
  bar ...
Two tests
Test   meet in a
         bar ...
Two tests
  Test      meet in a
Assertion     bar ...
Two tests
  Test      meet in a
Assertion     bar ...
  Test
  Test
Two tests
  Test      meet in a
Assertion     bar ...
  Test
  Test
Test case
Two tests
  Test      meet in a
Assertion     bar ...
  Test
  Test
Test case
Test case
Two tests
  Test       meet in a
Assertion      bar ...
  Test
  Test
Test case
Test case
Test suite
Code   test-first
Code   test-first
Code   test-first

write
test
Code   test-first

write
test
Code    test-first

write          write
test           code
Code    test-first

write          write
test           code
Code    test-first

write          write
test           code
Code    test-first

write          write
test           code



                       refactor
Code    test-first

write          write
test           code



                       refactor
The   life cycle unit test
               of a
The   life cycle unit test
               of a
The   life cycle unit test
               of a
                      new FooTest();
The   life cycle unit test
               of a
                      new FooTest();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();

                      /** @test */
                      lifeIsGood();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();

                      /** @test */
                      lifeIsGood();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();

                      /** @test */
                      lifeIsGood();

                        tearDown();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();

                      /** @test */
                      lifeIsGood();

                        tearDown();
The   life cycle unit test
               of a
                      new FooTest();

                           setUp();

                      /** @test */
                      lifeIsGood();

                        tearDown();
Use   meaningful
           unit test   names
Use   meaningful
                          unit test   names
Name the
behavior.            classCanBeInstantiated
Use   meaningful
                            unit test   names
 Name the
 behavior.             classCanBeInstantiated


Mention the
 method.                   setTitleSetsTitle
Use   meaningful
                                 unit test   names
  Name the
  behavior.                 classCanBeInstantiated


Mention the
 method.                         setTitleSetsTitle


  Name the          setSizeWithZeroThrowsException
preconditions.   hasTitleForEmptyTitleReturnsFalse
Use   meaningful
                                 unit test   names
  Name the
  behavior.                 classCanBeInstantiated


Mention the
 method.                         setTitleSetsTitle


  Name the          setSizeWithZeroThrowsException
preconditions.   hasTitleForEmptyTitleReturnsFalse


  Dont‘t use
 "works" or
 "correctly".
Use   meaningful
                                   unit test   names
  Name the
  behavior.                   classCanBeInstantiated


Mention the
 method.                           setTitleSetsTitle


  Name the          setSizeWithZeroThrowsException
preconditions.   hasTitleForEmptyTitleReturnsFalse


  Dont‘t use
 "works" or             measureFrubbleWorksCorrectly
 "correctly".
Use   meaningful
                                   unit test   names
  Name the
  behavior.                   classCanBeInstantiated


Mention the
 method.                           setTitleSetsTitle


  Name the          setSizeWithZeroThrowsException
preconditions.   hasTitleForEmptyTitleReturnsFalse


  Dont‘t use
 "works" or             measureFrubbleWorksCorrectly
 "correctly".
Continuous
Integration
Continuous
Integration
    =
Continuous
Integration
    =
checking in
more often
The continuous integration server
                 monitors the code
     Checkin

                             Repository (SVN)
The continuous integration server
                 monitors the code
     Checkin



                hook
                             Repository (SVN)

               SVN
The continuous integration server
                     monitors the code
      Checkin



                   hook
                             Repository (SVN)

                  SVN



  continuous integration
         server
The continuous integration server
                     monitors the code
      Checkin



                    hook
                             Repository (SVN)

                   SVN
          Hey, a
         change!

  continuous integration
         server
The continuous integration server
                     monitors the code
      Checkin



                    hook
                                  Repository (SVN)

                   SVN
          Hey, a
         change!

  continuous integration   run the unit
         server             tests etc.
The continuous integration server
                     monitors the code
      Checkin



                    hook
                                  Repository (SVN)

                   SVN
          Hey, a
         change!

  continuous integration   run the unit   Report
         server             tests etc.
There are
 small and huge
              tests
Unit tests are
        small and fast
Integration tests test
  the complete thing
Automated click tests
    test the interface
Automated click tests
    test the interface



              Selenium
Blackbox tests
       test
        the   public interface
Whitebox tests   test the
       inner workings
The   testing framework
                 is created quickly
	   /**
	    * @var Tx_Phpunit_Framework
	    */
	   protected $testingFramework = NULL;

	   public function setUp() {
	   	 $this->testingFramework = new Tx_Phpunit_Framework('tx_news2');
	   }

	   public function tearDown() {
	   	 $this->testingFramework->cleanUp();
	   	 unset($this->testingFramework);
	   }
The   testing framework
                 is created quickly
	   /**
	    * @var Tx_Phpunit_Framework
	    */
	   protected $testingFramework = NULL;

	   public function setUp() {
	   	 $this->testingFramework = new Tx_Phpunit_Framework('tx_news2');
	   }
                                                       discard the FE,
	   public function tearDown() {
                                                     delete DB records,
	   	 $this->testingFramework->cleanUp();
	   	 unset($this->testingFramework);
                                                         delete files
	   }
The   testing framework
                 is created quickly
	   /**
	    * @var Tx_Phpunit_Framework
	    */
	   protected $testingFramework = NULL;

	   public function setUp() {
	   	 $this->testingFramework = new Tx_Phpunit_Framework('tx_news2');
	   }
                                                       discard the FE,
	   public function tearDown() {
                                                     delete DB records,
	   	 $this->testingFramework->cleanUp();
	   	 unset($this->testingFramework);
                                                         delete files
	   }




CREATE TABLE tx_news2_domain_model_news (
	 …
	 is_dummy_record tinyint(1) unsigned DEFAULT '0' NOT NULL,
	 …
The   testing framework
              can fake almost everything
The   testing framework
              can fake almost everything
         $recordUid = $tf->createRecord($tableName, array $recordData = array());
The   testing framework
              can fake almost everything
         $recordUid = $tf->createRecord($tableName, array $recordData = array());

                          $tf->changeRecord($tableName, $uid, array $recordData);
The   testing framework
              can fake almost everything
         $recordUid = $tf->createRecord($tableName, array $recordData = array());

                          $tf->changeRecord($tableName, $uid, array $recordData);


                                             $tf->deleteRecord($tableName, $uid);
The   testing framework
              can fake almost everything
         $recordUid = $tf->createRecord($tableName, array $recordData = array());

                          $tf->changeRecord($tableName, $uid, array $recordData);


                                             $tf->deleteRecord($tableName, $uid);


           $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $tf->changeRecord($tableName, $uid, array $recordData);


                                                 $tf->deleteRecord($tableName, $uid);


               $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);


$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName);
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $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);
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $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 = '');
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $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 = '');
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $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->existsExactlyOneRecord($tableName, $whereClause = '');
The   testing framework
              can fake almost everything
             $recordUid = $tf->createRecord($tableName, array $recordData = array());

                              $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->existsExactlyOneRecord($tableName, $whereClause = '');


                              $success = $tf->existsRecordWithUid($tableName, $uid);
The   testing framework
              can fake almost everything
The   testing framework
              can fake almost everything
      $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array());
The   testing framework
              can fake almost everything
      $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array());


      $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array());
The   testing framework
              can fake almost everything
      $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array());


      $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array());


 $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array());
The   testing framework
              can fake almost everything
      $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());
The   testing framework
              can fake almost everything
      $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);
The   testing framework
              can fake almost everything
      $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();
The   testing framework
              can fake almost everything
      $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();


              $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());
The   testing framework
              can fake almost everything
      $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();


              $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());


      $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());
The   testing framework
              can fake almost everything
      $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();


              $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());


      $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());


                                                    $tf->loginFrontEndUser($userId);
The   testing framework
              can fake almost everything
      $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();


              $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());


      $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());


              $tf->logoutFrontEndUser();            $tf->loginFrontEndUser($userId);
The   testing framework
              can fake almost everything
       $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();


                $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());


        $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());


               $tf->logoutFrontEndUser();             $tf->loginFrontEndUser($userId);


$userUid = $tf->createAndLoginFrontEndUser($groups = '', array $recordData = array());
The   testing framework
              can fake almost everything
       $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();


                $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());


        $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());


               $tf->logoutFrontEndUser();             $tf->loginFrontEndUser($userId);


$userUid = $tf->createAndLoginFrontEndUser($groups = '', array $recordData = array());


                                                      $isLoggedIn = $tf->isLoggedIn();
The   testing framework
              can fake almost everything
The   testing framework
              can fake almost everything
            $recordUid = $tf->createBackEndUser(array $recordData = array());
The   testing framework
              can fake almost everything
              $recordUid = $tf->createBackEndUser(array $recordData = array());

         $recordUid = $tf->createBackEndUserGroup(array $recordData = array());
The   testing framework
              can fake almost everything
The   testing framework
              can fake almost everything
          $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');
The   testing framework
                can fake almost everything
                    $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');


$path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array());
The   testing framework
                can fake almost everything
                    $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');


$path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array());

                                                        $tf->deleteDummyFile($fileName);
The   testing framework
                can fake almost everything
                    $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');


$path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array());

                                                        $tf->deleteDummyFile($fileName);


                                            $path = $tf->createDummyFolder($folderName);
The   testing framework
                can fake almost everything
                    $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');


$path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array());

                                                        $tf->deleteDummyFile($fileName);


                                            $path = $tf->createDummyFolder($folderName);

                                                    $tf->deleteDummyFolder($folderName);
How to        your  test
      extbase                             controllers
class Tx_Coffee_Controller_CoffeeControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
	    /** @var Tx_Coffee_Controller_CoffeeController */
	    protected $fixture;
	    /** @var Tx_Fluid_View_TemplateView */
	    protected $view = NULL;
	    /** @var Tx_Coffee_Domain_Repository_CoffeeRepository */
	    protected $coffeeRepository = NULL;

	   public function setUp() {
	   	    $this->fixture = new Tx_Coffee_Controller_CoffeeController();

	   	    $this->view = $this->getMock('Tx_Fluid_View_TemplateView', array(), array(), '', FALSE);
	   	    $this->fixture->setView($this->view);

	   	    $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
	   	    $this->fixture->injectObjectManager($this->objectManager);

	   	    $this->coffeeRepository = $this->getMock(
	   	    	    'Tx_Coffee_Domain_Repository_CoffeeRepository',
	   	    	    array('findAll', 'findByBrand'), array($this->objectManager)
	   	    );
	   	    $this->fixture->injectCoffeeRepository($this->coffeeRepository);
    }
How to        your  test
      extbase                             controllers
class Tx_Coffee_Controller_CoffeeControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
	    /** @var Tx_Coffee_Controller_CoffeeController */
	    protected $fixture;
	    /** @var Tx_Fluid_View_TemplateView */
	    protected $view = NULL;
	    /** @var Tx_Coffee_Domain_Repository_CoffeeRepository */
	    protected $coffeeRepository = NULL;

	   public function setUp() {
	   	    $this->fixture = new Tx_Coffee_Controller_CoffeeController();

	   	    $this->view = $this->getMock('Tx_Fluid_View_TemplateView', array(), array(), '', FALSE);
	   	    $this->fixture->setView($this->view);

	   	    $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
	   	    $this->fixture->injectObjectManager($this->objectManager);

	   	    $this->coffeeRepository = $this->getMock(
	   	    	    'Tx_Coffee_Domain_Repository_CoffeeRepository',
	   	    	    array('findAll', 'findByBrand'), array($this->objectManager)
	   	    );
	   	    $this->fixture->injectCoffeeRepository($this->coffeeRepository);
    }
                         class Tx_Coffee_Controller_CoffeeController extends Tx_Extbase_MVC_Controller_ActionController {
                         	    /**
                         	      * Sets the view.
                         	      *
                         	      * This function is intended to be used for unit testing purposes only.
                         	      *
                         	      * @param Tx_Fluid_View_TemplateView $view the new view
                         	      *
                         	      * @return void
                         	      */
                         	    public function setView(Tx_Fluid_View_TemplateView $view) {
                         	    	     $this->view = $view;
                         	    }
How to test   your
      extbase controllers
How to        your test
                 extbase                         controllers
/**
  * @test
  */
public function indexActionAssignsAllCoffeesToView() {
	    $models = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
	    $this->coffeeRepository->expects($this->once())->method('findAll')
	    	    ->will($this->returnValue($models));

	   $this->view->expects($this->at(0))->method('assign')->with('coffees', $models);

	   $this->fixture->indexAction();
}
How to        your test
                 extbase                         controllers
/**
  * @test
  */
public function indexActionAssignsAllCoffeesToView() {
	    $models = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
	    $this->coffeeRepository->expects($this->once())->method('findAll')
	    	    ->will($this->returnValue($models));

	   $this->view->expects($this->at(0))->method('assign')->with('coffees', $models);

	   $this->fixture->indexAction();
}




/**
  * @test
  */
public function showActionAssignsModelToView() {
	    $model = clone new Tx_Coffee_Domain_Model_Coffee();
	    $this->view->expects($this->at(0))->method('assign')->with('coffee', $model);

	   $this->fixture->showAction($model);
}

Contenu connexe

Tendances

J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
ksain
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
nicobn
 

Tendances (20)

Java custom annotations example
Java custom annotations exampleJava custom annotations example
Java custom annotations example
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit Tests
 
J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
3 j unit
3 j unit3 j unit
3 j unit
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
 
Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Tdd
TddTdd
Tdd
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Junit
JunitJunit
Junit
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 

En vedette (6)

Objektorientierte Programmierung mit extbase und fluid
Objektorientierte Programmierung mit extbase und fluidObjektorientierte Programmierung mit extbase und fluid
Objektorientierte Programmierung mit extbase und fluid
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
Stand das im Handbuch?
Stand das im Handbuch?Stand das im Handbuch?
Stand das im Handbuch?
 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHP
 
Semantic TYPO3
Semantic TYPO3Semantic TYPO3
Semantic TYPO3
 
Test-Driven Development with FLOW3
Test-Driven Development with FLOW3Test-Driven Development with FLOW3
Test-Driven Development with FLOW3
 

Similaire à Test-Driven Development for TYPO3

Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
Gabriele Lana
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
Yi-Huan Chan
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
PyCon Italia
 

Similaire à Test-Driven Development for TYPO3 (20)

Python unittest
Python unittestPython unittest
Python unittest
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
Rc2010 tdd
Rc2010 tddRc2010 tdd
Rc2010 tdd
 
jUnit
jUnitjUnit
jUnit
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 

Plus de Oliver Klee (9)

Stand das im Handbuch?
Stand das im Handbuch?Stand das im Handbuch?
Stand das im Handbuch?
 
Test-Driven Development ... und mehr
Test-Driven Development ... und mehrTest-Driven Development ... und mehr
Test-Driven Development ... und mehr
 
Test-driven Development mit TYPO3
Test-driven Development mit TYPO3Test-driven Development mit TYPO3
Test-driven Development mit TYPO3
 
Test-driven development with TYPO3 (T3CON10)
Test-driven development with TYPO3 (T3CON10)Test-driven development with TYPO3 (T3CON10)
Test-driven development with TYPO3 (T3CON10)
 
Persönliches Zeitmanagement mit Getting Things Done (GTD)
Persönliches Zeitmanagement mit Getting Things Done (GTD)Persönliches Zeitmanagement mit Getting Things Done (GTD)
Persönliches Zeitmanagement mit Getting Things Done (GTD)
 
Everything you need to know about the TYPO3 Security Team (T3DD10)
Everything you need to know about the TYPO3 Security Team (T3DD10)Everything you need to know about the TYPO3 Security Team (T3DD10)
Everything you need to know about the TYPO3 Security Team (T3DD10)
 
TDD & Best Practices mit TYPO3
TDD & Best Practices mit TYPO3TDD & Best Practices mit TYPO3
TDD & Best Practices mit TYPO3
 
GPG Workshop
GPG WorkshopGPG Workshop
GPG Workshop
 
Unit testing for the TYPO3 4.x core
Unit testing for the TYPO3 4.x coreUnit testing for the TYPO3 4.x core
Unit testing for the TYPO3 4.x core
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Test-Driven Development for TYPO3

  • 1. Test-Driven Development for TYPO3 Oliver Klee, 2011-12-13 and 2011-12-14 typo3-coding@oliverklee.de
  • 3. Manual testing is cumbersome
  • 5. Unit tests for the Realty Manager extension
  • 7. in less than 60 seconds
  • 8. Verify that your code does what you expect
  • 9. Make sure that your changes won‘t break anything
  • 10. Keep other coders from breaking your code
  • 11. Don‘t break anything even in complex projects
  • 12. Create asafety net for refactoring
  • 15. Know your tools
  • 16. The phpunit extension has it all
  • 17. The phpunit extension has it all phpunit (TYPO3 extension)
  • 18. The phpunit extension has it all phpunit (TYPO3 extension) PHPUnit (PEAR package)
  • 19. The phpunit extension has it all phpunit (TYPO3 extension) PHPUnit (PEAR package) Testrunner (back-end- module)
  • 20. The phpunit extension has it all phpunit (TYPO3 extension) PHPUnit (PEAR package) Testrunner Testrunner (back-end- module) (CLI module)
  • 21. The phpunit extension has it all phpunit (TYPO3 extension) PHPUnit (PEAR package) Testing framework for FE & DB Testrunner Testrunner (back-end- module) (CLI module)
  • 23. Two tests meet in a bar ...
  • 24. Two tests Test meet in a bar ...
  • 25. Two tests Test meet in a Assertion bar ...
  • 26. Two tests Test meet in a Assertion bar ... Test Test
  • 27. Two tests Test meet in a Assertion bar ... Test Test Test case
  • 28. Two tests Test meet in a Assertion bar ... Test Test Test case Test case
  • 29. Two tests Test meet in a Assertion bar ... Test Test Test case Test case Test suite
  • 30. Code test-first
  • 31. Code test-first
  • 32. Code test-first write test
  • 33. Code test-first write test
  • 34. Code test-first write write test code
  • 35. Code test-first write write test code
  • 36. Code test-first write write test code
  • 37. Code test-first write write test code refactor
  • 38. Code test-first write write test code refactor
  • 39. The life cycle unit test of a
  • 40. The life cycle unit test of a
  • 41. The life cycle unit test of a new FooTest();
  • 42. The life cycle unit test of a new FooTest();
  • 43. The life cycle unit test of a new FooTest(); setUp();
  • 44. The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood();
  • 45. The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood();
  • 46. The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • 47. The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • 48. The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • 49. Use meaningful unit test names
  • 50. Use meaningful unit test names Name the behavior. classCanBeInstantiated
  • 51. Use meaningful unit test names Name the behavior. classCanBeInstantiated Mention the method. setTitleSetsTitle
  • 52. Use meaningful unit test names Name the behavior. classCanBeInstantiated Mention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsException preconditions. hasTitleForEmptyTitleReturnsFalse
  • 53. Use meaningful unit test names Name the behavior. classCanBeInstantiated Mention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsException preconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or "correctly".
  • 54. Use meaningful unit test names Name the behavior. classCanBeInstantiated Mention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsException preconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or measureFrubbleWorksCorrectly "correctly".
  • 55. Use meaningful unit test names Name the behavior. classCanBeInstantiated Mention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsException preconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or measureFrubbleWorksCorrectly "correctly".
  • 58. Continuous Integration = checking in more often
  • 59. The continuous integration server monitors the code Checkin Repository (SVN)
  • 60. The continuous integration server monitors the code Checkin hook Repository (SVN) SVN
  • 61. The continuous integration server monitors the code Checkin hook Repository (SVN) SVN continuous integration server
  • 62. The continuous integration server monitors the code Checkin hook Repository (SVN) SVN Hey, a change! continuous integration server
  • 63. The continuous integration server monitors the code Checkin hook Repository (SVN) SVN Hey, a change! continuous integration run the unit server tests etc.
  • 64. The continuous integration server monitors the code Checkin hook Repository (SVN) SVN Hey, a change! continuous integration run the unit Report server tests etc.
  • 65. There are small and huge tests
  • 66. Unit tests are small and fast
  • 67. Integration tests test the complete thing
  • 68. Automated click tests test the interface
  • 69. Automated click tests test the interface Selenium
  • 70. Blackbox tests test the public interface
  • 71. Whitebox tests test the inner workings
  • 72. The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework('tx_news2'); } public function tearDown() { $this->testingFramework->cleanUp(); unset($this->testingFramework); }
  • 73. The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework('tx_news2'); } discard the FE, public function tearDown() { delete DB records, $this->testingFramework->cleanUp(); unset($this->testingFramework); delete files }
  • 74. The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework('tx_news2'); } discard the FE, public function tearDown() { delete DB records, $this->testingFramework->cleanUp(); unset($this->testingFramework); delete files } CREATE TABLE tx_news2_domain_model_news ( … is_dummy_record tinyint(1) unsigned DEFAULT '0' NOT NULL, …
  • 75. The testing framework can fake almost everything
  • 76. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array());
  • 77. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData);
  • 78. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid);
  • 79. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);
  • 80. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0); $tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName);
  • 81. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $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);
  • 82. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $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 = '');
  • 83. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $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 = '');
  • 84. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $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->existsExactlyOneRecord($tableName, $whereClause = '');
  • 85. The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $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->existsExactlyOneRecord($tableName, $whereClause = ''); $success = $tf->existsRecordWithUid($tableName, $uid);
  • 86. The testing framework can fake almost everything
  • 87. The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array());
  • 88. The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array());
  • 89. The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array());
  • 90. The testing framework can fake almost everything $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());
  • 91. The testing framework can fake almost everything $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);
  • 92. The testing framework can fake almost everything $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();
  • 93. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());
  • 94. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array());
  • 95. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array()); $tf->loginFrontEndUser($userId);
  • 96. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId);
  • 97. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId); $userUid = $tf->createAndLoginFrontEndUser($groups = '', array $recordData = array());
  • 98. The testing framework can fake almost everything $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(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = '', array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId); $userUid = $tf->createAndLoginFrontEndUser($groups = '', array $recordData = array()); $isLoggedIn = $tf->isLoggedIn();
  • 99. The testing framework can fake almost everything
  • 100. The testing framework can fake almost everything $recordUid = $tf->createBackEndUser(array $recordData = array());
  • 101. The testing framework can fake almost everything $recordUid = $tf->createBackEndUser(array $recordData = array()); $recordUid = $tf->createBackEndUserGroup(array $recordData = array());
  • 102. The testing framework can fake almost everything
  • 103. The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = 'test.txt', $content = '');
  • 104. The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = 'test.txt', $content = ''); $path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array());
  • 105. The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = 'test.txt', $content = ''); $path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array()); $tf->deleteDummyFile($fileName);
  • 106. The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = 'test.txt', $content = ''); $path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array()); $tf->deleteDummyFile($fileName); $path = $tf->createDummyFolder($folderName);
  • 107. The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = 'test.txt', $content = ''); $path = $tf->createDummyZipArchive($fileName = 'test.zip', array $filesToAdd = array()); $tf->deleteDummyFile($fileName); $path = $tf->createDummyFolder($folderName); $tf->deleteDummyFolder($folderName);
  • 108. How to your test extbase controllers class Tx_Coffee_Controller_CoffeeControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase { /** @var Tx_Coffee_Controller_CoffeeController */ protected $fixture; /** @var Tx_Fluid_View_TemplateView */ protected $view = NULL; /** @var Tx_Coffee_Domain_Repository_CoffeeRepository */ protected $coffeeRepository = NULL; public function setUp() { $this->fixture = new Tx_Coffee_Controller_CoffeeController(); $this->view = $this->getMock('Tx_Fluid_View_TemplateView', array(), array(), '', FALSE); $this->fixture->setView($this->view); $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); $this->fixture->injectObjectManager($this->objectManager); $this->coffeeRepository = $this->getMock( 'Tx_Coffee_Domain_Repository_CoffeeRepository', array('findAll', 'findByBrand'), array($this->objectManager) ); $this->fixture->injectCoffeeRepository($this->coffeeRepository); }
  • 109. How to your test extbase controllers class Tx_Coffee_Controller_CoffeeControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase { /** @var Tx_Coffee_Controller_CoffeeController */ protected $fixture; /** @var Tx_Fluid_View_TemplateView */ protected $view = NULL; /** @var Tx_Coffee_Domain_Repository_CoffeeRepository */ protected $coffeeRepository = NULL; public function setUp() { $this->fixture = new Tx_Coffee_Controller_CoffeeController(); $this->view = $this->getMock('Tx_Fluid_View_TemplateView', array(), array(), '', FALSE); $this->fixture->setView($this->view); $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); $this->fixture->injectObjectManager($this->objectManager); $this->coffeeRepository = $this->getMock( 'Tx_Coffee_Domain_Repository_CoffeeRepository', array('findAll', 'findByBrand'), array($this->objectManager) ); $this->fixture->injectCoffeeRepository($this->coffeeRepository); } class Tx_Coffee_Controller_CoffeeController extends Tx_Extbase_MVC_Controller_ActionController { /** * Sets the view. * * This function is intended to be used for unit testing purposes only. * * @param Tx_Fluid_View_TemplateView $view the new view * * @return void */ public function setView(Tx_Fluid_View_TemplateView $view) { $this->view = $view; }
  • 110. How to test your extbase controllers
  • 111. How to your test extbase controllers /** * @test */ public function indexActionAssignsAllCoffeesToView() { $models = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface'); $this->coffeeRepository->expects($this->once())->method('findAll') ->will($this->returnValue($models)); $this->view->expects($this->at(0))->method('assign')->with('coffees', $models); $this->fixture->indexAction(); }
  • 112. How to your test extbase controllers /** * @test */ public function indexActionAssignsAllCoffeesToView() { $models = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface'); $this->coffeeRepository->expects($this->once())->method('findAll') ->will($this->returnValue($models)); $this->view->expects($this->at(0))->method('assign')->with('coffees', $models); $this->fixture->indexAction(); } /** * @test */ public function showActionAssignsModelToView() { $model = clone new Tx_Coffee_Domain_Model_Coffee(); $this->view->expects($this->at(0))->method('assign')->with('coffee', $model); $this->fixture->showAction($model); }

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n