[TASK] Update to phpunit 4.1 84/29584/6
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 20 Apr 2014 12:46:13 +0000 (14:46 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 12 May 2014 15:04:35 +0000 (17:04 +0200)
Do not forget to "composer update" test instances!

Updating from phpunit 3.7 to 4.1 is smooth, except two details:

* The mock framework dropped staticExpects, two test cases must
  be refactored to circumvent this.

* The mocker now tries to resolve method argument type hints, so
  those classes must exist and autoloaded, some FLOW dependencies
  are affected here.

Change-Id: Ie74bdad000182dde808d3771fa6eec4764a133da
Resolves: #58676
Releases: 6.2
Reviewed-on: https://review.typo3.org/29584
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
composer.json
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Core/ClassLoader.php [new file with mode: 0644]
typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/LoggerInterface.php [new file with mode: 0644]
typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/SystemLoggerInterface.php [new file with mode: 0644]
typo3/sysext/core/ext_autoload.php
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php

index 2379aa5..1334866 100644 (file)
                "irc": "irc://irc.freenode.net/#typo3-cms",
                "news": "nntp://lists.typo3.org"
        },
-    "config": {
-        "vendor-dir": "Packages/Libraries",
-        "bin-dir": "bin"
-    },
+       "config": {
+               "vendor-dir": "Packages/Libraries",
+               "bin-dir": "bin"
+       },
        "require": {
                "php": ">=5.3.7",
                "ext-fileinfo": "*",
@@ -37,7 +37,7 @@
        },
        "require-dev": {
                "mikey179/vfsStream": "1.3.*@dev",
-               "phpunit/phpunit": "3.7.*"
+               "phpunit/phpunit": "4.1.*"
        },
        "suggest": {
                "ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
index bbf90d2..97affd5 100644 (file)
@@ -130,7 +130,6 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @see http://forge.typo3.org/issues/20994
         */
        public function getProcessedValueForZeroStringIsZero() {
-               $subject = new BackendUtility();
                $GLOBALS['TCA'] = array(
                        'tt_content' => array(
                                'columns' => array(
@@ -142,7 +141,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ),
                        ),
                );
-               $this->assertEquals('0', $subject->getProcessedValue('tt_content', 'header', '0'));
+               $this->assertEquals('0', BackendUtility::getProcessedValue('tt_content', 'header', '0'));
        }
 
        /**
@@ -167,6 +166,36 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getProcessedValueForGroupWithOneAllowedTable() {
+               // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getRecordWSOL() {' .
+                       '    static $called = 0;' .
+                       '    ++$called;' .
+                       '    if ($called === 1) {' .
+                       '      return array(\'title\' => \'Page 1\');' .
+                       '    }' .
+                       '    if ($called === 2) {' .
+                       '      return array(\'title\' => \'Page 2\');' .
+                       '    }' .
+                       '  }' .
+                       '  static public function getRecordTitle() {' .
+                       '    static $called = 0;' .
+                       '    ++$called;' .
+                       '    if ($called === 1) {' .
+                       '      return \'Page 1\';' .
+                       '    }' .
+                       '    if ($called === 2) {' .
+                       '      return \'Page 2\';' .
+                       '    }' .
+                       '  }' .
+                       '}'
+               );
+
                $GLOBALS['TCA'] = array(
                        'tt_content' => array(
                                'columns' => array(
@@ -184,19 +213,44 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ),
                        ),
                );
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $subject = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL', 'getRecordTitle'));
-               $subject->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
-               $subject->staticExpects($this->at(1))->method('getRecordTitle')->will($this->returnValue('Page 1'));
-               $subject->staticExpects($this->at(2))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 2')));
-               $subject->staticExpects($this->at(3))->method('getRecordTitle')->will($this->returnValue('Page 2'));
-               $this->assertSame('Page 1, Page 2', $subject->getProcessedValue('tt_content', 'pages', '1,2'));
+
+               $this->assertSame('Page 1, Page 2', $subject::getProcessedValue('tt_content', 'pages', '1,2'));
        }
 
        /**
         * @test
         */
        public function getProcessedValueForGroupWithMultipleAllowedTables() {
+               // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getRecordWSOL() {' .
+                       '    static $called = 0;' .
+                       '    ++$called;' .
+                       '    if ($called === 1) {' .
+                       '      return array(\'title\' => \'Page 1\');' .
+                       '    }' .
+                       '    if ($called === 2) {' .
+                       '      return array(\'header\' => \'Content 2\');' .
+                       '    }' .
+                       '  }' .
+                       '  static public function getRecordTitle() {' .
+                       '    static $called = 0;' .
+                       '    ++$called;' .
+                       '    if ($called === 1) {' .
+                       '      return \'Page 1\';' .
+                       '    }' .
+                       '    if ($called === 2) {' .
+                       '      return \'Content 2\';' .
+                       '    }' .
+                       '  }' .
+                       '}'
+               );
+
                $GLOBALS['TCA'] = array(
                        'sys_category' => array(
                                'columns' => array(
@@ -212,13 +266,8 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ),
                        ),
                );
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $subject = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL', 'getRecordTitle'));
-               $subject->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
-               $subject->staticExpects($this->at(1))->method('getRecordTitle')->will($this->returnValue('Page 1'));
-               $subject->staticExpects($this->at(2))->method('getRecordWSOL')->will($this->returnValue(array('header' => 'Content 2')));
-               $subject->staticExpects($this->at(3))->method('getRecordTitle')->will($this->returnValue('Content 2'));
-               $this->assertSame('Page 1, Content 2', $subject->getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
+
+               $this->assertSame('Page 1, Content 2', $subject::getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
        }
 
        /**
@@ -475,10 +524,21 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
         */
        public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
+               // Disable getPagesTSconfig by returning stable result
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getPagesTSconfig() {' .
+                       '    return array();' .
+                       '  }' .
+                       '}'
+               );
+
                $GLOBALS['TCA'][$table] = $tca;
-               /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
-               $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getPagesTSconfig'), array(), '', FALSE);
-               $subject::staticExpects($this->once())->method('getPagesTSconfig')->will($this->returnValue(array()));
+
                $this->assertEquals($expectedLabel, $subject::getLabelFromItemListMerged($pageId, $table, $column, $key));
        }
 
@@ -713,6 +773,18 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider getExcludeFieldsDataProvider
         */
        public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getRegisteredFlexForms() {' .
+                       '    return array();' .
+                       '  }' .
+                       '}'
+               );
+
                $GLOBALS['TCA'] = $tca;
 
                // Stub LanguageService and let sL() return the same value that came in again
@@ -723,9 +795,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        return $name;
                                }
                        ));
-               /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
-               $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRegisteredFlexForms'), array(), '', FALSE);
-               $subject::staticExpects($this->any())->method('getRegisteredFlexForms')->will($this->returnValue(array()));
+
                $this->assertSame($expected, $subject::getExcludeFields());
        }
 
@@ -733,35 +803,6 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
-               $parsedFlexForm = array(
-                       'abarfoo' => array(
-                               'dummy' => array(
-                                       'title' => 'dummy',
-                                       'ds' => array(
-                                               'sheets' => array(
-                                                       'sGeneral' => array(
-                                                               'ROOT' => array(
-                                                                       'type' => 'array',
-                                                                       'el' => array(
-                                                                               'xmlTitle' => array(
-                                                                                       'TCEforms' => array(
-                                                                                               'exclude' => 1,
-                                                                                               'label' => 'The Title:',
-                                                                                               'config' => array(
-                                                                                                       'type' => 'input',
-                                                                                                       'size' => 48,
-                                                                                               ),
-                                                                                       ),
-                                                                               ),
-                                                                       ),
-                                                               ),
-                                                       ),
-                                               ),
-                                       ),
-                               ),
-                       ),
-               );
-
                $GLOBALS['TCA'] = array(
                        'tx_foo' => array(
                                'ctrl' => array(
@@ -859,20 +900,58 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                }
                        ));
 
-               /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
-               $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRegisteredFlexForms'), array(), '', FALSE);
-               $subject::staticExpects($this->at(0))
-                       ->method('getRegisteredFlexForms')
-                       ->will($this->returnValue(array()));
-
-               $subject::staticExpects($this->at(1))
-                       ->method('getRegisteredFlexForms')
-                       ->with('tx_foo')
-                       ->will($this->returnValue($parsedFlexForm));
-
-               $subject::staticExpects($this->at(2))
-                       ->method('getRegisteredFlexForms')
-                       ->will($this->returnValue(array()));
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getRegisteredFlexForms($table) {' .
+                       '    static $called = 0;' .
+                       '    ++$called;' .
+                       '    if ($called === 1) {' .
+                       '      return array();' .
+                       '    }' .
+                       '    if ($called === 2) {' .
+                       '      if ($table !== \'tx_foo\') {' .
+                       '        throw new Exception(\'Expected tx_foo as argument on call 2\', 1399638572);' .
+                       '      }' .
+                       '      $parsedFlexForm = array(' .
+                       '        \'abarfoo\' => array(' .
+                       '          \'dummy\' => array(' .
+                       '            \'title\' => \'dummy\',' .
+                       '            \'ds\' => array(' .
+                       '              \'sheets\' => array(' .
+                       '                \'sGeneral\' => array(' .
+                       '                  \'ROOT\' => array(' .
+                       '                    \'type\' => \'array\',' .
+                       '                    \'el\' => array(' .
+                       '                      \'xmlTitle\' => array(' .
+                       '                        \'TCEforms\' => array(' .
+                       '                          \'exclude\' => 1,' .
+                       '                          \'label\' => \'The Title:\',' .
+                       '                          \'config\' => array(' .
+                       '                            \'type\' => \'input\',' .
+                       '                            \'size\' => 48,' .
+                       '                          ),' .
+                       '                        ),' .
+                       '                      ),' .
+                       '                    ),' .
+                       '                  ),' .
+                       '                ),' .
+                       '              ),' .
+                       '            ),' .
+                       '          ),' .
+                       '        ),' .
+                       '      );' .
+                       '      return $parsedFlexForm;' .
+                       '    }' .
+                       '    if ($called === 3) {' .
+                       '      return array();' .
+                       '    }' .
+                       '  }' .
+                       '}'
+               );
 
                $this->assertSame($expectedResult, $subject::getExcludeFields());
        }
@@ -1106,7 +1185,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
                        ),
                );
-               BackendUtility::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig);
+               BackendUtility::replaceMarkersInWhereClause($where, 'dummytable', 'dummyfield', $tsConfig);
        }
 
        /**
@@ -1130,9 +1209,17 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
                $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
 
-               /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
-               $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getPagesTSconfig'), array(), '', FALSE);
-               $subject::staticExpects($this->any())->method('getPagesTSconfig')->will($this->returnValue(array()));
+               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
+               $className = uniqid('BackendUtility');
+               $subject = __NAMESPACE__ . '\\' . $className;
+               eval(
+                       'namespace ' . __NAMESPACE__ . ';' .
+                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
+                       '  static public function getPagesTSconfig() {' .
+                       '    return array();' .
+                       '  }' .
+                       '}'
+               );
 
                $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
        }
diff --git a/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Core/ClassLoader.php b/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Core/ClassLoader.php
new file mode 100644 (file)
index 0000000..1a5ce75
--- /dev/null
@@ -0,0 +1,174 @@
+<?php
+namespace TYPO3\Flow\Core;
+
+/*                                                                        *
+ * This script belongs to the TYPO3 Flow framework.                       *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License, either version 3   *
+ * of the License, or (at your option) any later version.                 *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+use TYPO3\Flow\Annotations as Flow;
+
+/**
+ * Class Loader implementation which loads .php files found in the classes
+ * directory of an object.
+ *
+ * @Flow\Proxy(false)
+ * @Flow\Scope("singleton")
+ */
+class ClassLoader {
+
+       /**
+        * @var \TYPO3\Flow\Cache\Frontend\PhpFrontend
+        */
+       protected $classesCache;
+
+       /**
+        * An array of \TYPO3\Flow\Package\Package objects
+        * @var array
+        */
+       protected $packages = array();
+
+       /**
+        * @var string
+        */
+       protected $packagesPath = FLOW_PATH_PACKAGES;
+
+       /**
+        * A list of namespaces this class loader is definitely responsible for
+        * @var array
+        */
+       protected $packageNamespaces = array(
+               'TYPO3\Flow' => 10
+       );
+
+       /**
+        * @var boolean
+        */
+       protected $considerTestsNamespace = FALSE;
+
+       /**
+        * @var array
+        */
+       protected $ignoredClassNames = array(
+               'integer' => TRUE,
+               'string' => TRUE,
+               'param' => TRUE,
+               'return' => TRUE,
+               'var' => TRUE,
+               'throws' => TRUE,
+               'api' => TRUE,
+               'todo' => TRUE,
+               'fixme' => TRUE,
+               'see' => TRUE,
+               'license' => TRUE,
+               'author' => TRUE,
+               'test' => TRUE,
+       );
+
+       /**
+        * Injects the cache for storing the renamed original classes
+        *
+        * @param \TYPO3\Flow\Cache\Frontend\PhpFrontend $classesCache
+        * @return void
+        */
+       public function injectClassesCache(\TYPO3\Flow\Cache\Frontend\PhpFrontend $classesCache) {
+               $this->classesCache = $classesCache;
+       }
+
+       /**
+        * Loads php files containing classes or interfaces found in the classes directory of
+        * a package and specifically registered classes.
+        *
+        * @param string $className Name of the class/interface to load
+        * @return boolean
+        */
+       public function loadClass($className) {
+               if ($className[0] === '\\') {
+                       $className = substr($className, 1);
+               }
+
+               // Loads any known proxied class:
+               if ($this->classesCache !== NULL && $this->classesCache->requireOnce(str_replace('\\', '_', $className)) !== FALSE) {
+                       return TRUE;
+               }
+
+               // Workaround for Doctrine's annotation parser which does a class_exists() for annotations like "@param" and so on:
+               if (isset($this->ignoredClassNames[$className]) || isset($this->ignoredClassNames[substr($className, strrpos($className, '\\') + 1)])) {
+                       return FALSE;
+               }
+
+               // Load classes from the Flow package at a very early stage where
+               // no packages have been registered yet:
+               if ($this->packages === array() && substr($className, 0, 10) === 'TYPO3\Flow') {
+                       require(FLOW_PATH_FLOW . 'Classes/TYPO3/Flow/' . str_replace('\\', '/', substr($className, 11)) . '.php');
+                       return TRUE;
+               }
+
+               // Loads any non-proxied class of registered packages:
+               foreach ($this->packageNamespaces as $packageNamespace => $packageData) {
+                       // replace underscores in classname with \ to match for packagenamespace
+                       if (substr(str_replace('_', '\\', $className), 0, $packageData['namespaceLength']) === $packageNamespace) {
+                               if ($this->considerTestsNamespace === TRUE && substr($className, $packageData['namespaceLength'] + 1, 16) === 'Tests\Functional') {
+                                       $classPathAndFilename = $this->packages[str_replace('\\', '.', $packageNamespace)]->getPackagePath() . str_replace('\\', '/', substr($className, $packageData['namespaceLength'] + 1)) . '.php';
+                               } else {
+                                       // make the classname PSR-0 compliant by replacing underscores only in the classname not in the namespace
+                                       $fileName  = '';
+                                       $lastNamespacePosition = strrpos($className, '\\');
+                                       if ($lastNamespacePosition !== FALSE) {
+                                               $namespace = substr($className, 0, $lastNamespacePosition);
+                                               $className = substr($className, $lastNamespacePosition + 1);
+                                               $fileName  = str_replace('\\', '/', $namespace) . '/';
+                                       }
+                                       $fileName .= str_replace('_', '/', $className) . '.php';
+
+                                       $classPathAndFilename = $packageData['classesPath'] . $fileName;
+                               }
+                               try {
+                                       $result = include($classPathAndFilename);
+                                       if ($result !== FALSE) {
+                                               return TRUE;
+                                       }
+                               } catch (\Exception $e) {
+                               }
+                       }
+               }
+               return FALSE;
+       }
+
+       /**
+        * Sets the available packages
+        *
+        * @param array $packages An array of \TYPO3\Flow\Package\Package objects
+        * @return void
+        */
+       public function setPackages(array $packages) {
+               $this->packages = $packages;
+               foreach ($packages as $package) {
+                       $this->packageNamespaces[$package->getNamespace()] = array('namespaceLength' => strlen($package->getNamespace()), 'classesPath' => $package->getClassesPath());
+               }
+
+               // sort longer package namespaces first, to find specific matches before generic ones
+               uksort($this->packageNamespaces, function($a, $b) {
+                       if (strlen($a) === strlen($b)) {
+                               return strcmp($a, $b);
+                       }
+                       return (strlen($a) > strlen($b)) ? -1 : 1;
+               });
+       }
+
+       /**
+        * Sets the flag which enables or disables autoloading support for functional
+        * test files.
+        *
+        * @param boolean $flag
+        * @return void
+        */
+       public function setConsiderTestsNamespace($flag) {
+               $this->considerTestsNamespace = $flag;
+       }
+}
diff --git a/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/LoggerInterface.php b/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/LoggerInterface.php
new file mode 100644 (file)
index 0000000..d56c7c2
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+namespace TYPO3\Flow\Log;
+
+/*                                                                        *
+ * This script belongs to the TYPO3 Flow framework.                       *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License, either version 3   *
+ * of the License, or (at your option) any later version.                 *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Contract for a basic logger interface
+ *
+ * The severities are (according to RFC3164) the PHP constants:
+ *   LOG_EMERG   # Emergency: system is unusable
+ *   LOG_ALERT   # Alert: action must be taken immediately
+ *   LOG_CRIT    # Critical: critical conditions
+ *   LOG_ERR     # Error: error conditions
+ *   LOG_WARNING # Warning: warning conditions
+ *   LOG_NOTICE  # Notice: normal but significant condition
+ *   LOG_INFO    # Informational: informational messages
+ *   LOG_DEBUG   # Debug: debug-level messages
+ *
+ * @api
+ */
+interface LoggerInterface {
+
+       /**
+        * Adds a backend to which the logger sends the logging data
+        *
+        * @param \TYPO3\Flow\Log\Backend\BackendInterface $backend A backend implementation
+        * @return void
+        * @api
+        */
+       public function addBackend(\TYPO3\Flow\Log\Backend\BackendInterface $backend);
+
+       /**
+        * Runs the close() method of a backend and removes the backend
+        * from the logger.
+        *
+        * @param \TYPO3\Flow\Log\Backend\BackendInterface $backend The backend to remove
+        * @return void
+        * @throws \TYPO3\Flow\Log\Exception\NoSuchBackendException if the given backend is unknown to this logger
+        * @api
+        */
+       public function removeBackend(\TYPO3\Flow\Log\Backend\BackendInterface $backend);
+
+       /**
+        * Writes the given message along with the additional information into the log.
+        *
+        * @param string $message The message to log
+        * @param integer $severity An integer value, one of the LOG_* constants
+        * @param mixed $additionalData A variable containing more information about the event to be logged
+        * @param string $packageKey Key of the package triggering the log (determined automatically if not specified)
+        * @param string $className Name of the class triggering the log (determined automatically if not specified)
+        * @param string $methodName Name of the method triggering the log (determined automatically if not specified)
+        * @return void
+        * @api
+        */
+       public function log($message, $severity = LOG_INFO, $additionalData = NULL, $packageKey = NULL, $className = NULL, $methodName = NULL);
+
+       /**
+        * Writes information about the given exception into the log.
+        *
+        * @param \Exception $exception The exception to log
+        * @param array $additionalData Additional data to log
+        * @return void
+        * @api
+        */
+       public function logException(\Exception $exception, array $additionalData = array());
+
+}
diff --git a/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/SystemLoggerInterface.php b/typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Log/SystemLoggerInterface.php
new file mode 100644 (file)
index 0000000..562901e
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+namespace TYPO3\Flow\Log;
+
+/*                                                                        *
+ * This script belongs to the TYPO3 Flow framework.                       *
+ *                                                                        *
+ * It is free software; you can redistribute it and/or modify it under    *
+ * the terms of the GNU Lesser General Public License, either version 3   *
+ * of the License, or (at your option) any later version.                 *
+ *                                                                        *
+ * The TYPO3 project - inspiring people to share!                         *
+ *                                                                        */
+
+/**
+ * Marker interface for the system logger.
+ *
+ */
+interface SystemLoggerInterface extends \TYPO3\Flow\Log\LoggerInterface {
+}
index 79ce4c1..90447f4 100644 (file)
@@ -13,6 +13,9 @@ return array(
        'transferdata' => PATH_typo3 . 'show_item.php',
        'Psr\\Log\\LoggerInterface' => PATH_typo3 . 'contrib/Psr/Log/LoggerInterface.php',
        'Psr\\Log\\InvalidArgumentException' => PATH_typo3 . 'contrib/Psr/Log/InvalidArgumentException.php',
+       'typo3\flow\core\classloader' => $flowClassesPath . 'TYPO3/Flow/Core/ClassLoader.php',
+       'typo3\flow\log\loggerinterface' => $flowClassesPath . 'TYPO3/Flow/Log/LoggerInterface.php',
+       'typo3\flow\log\systemloggerinterface' => $flowClassesPath . 'TYPO3/Flow/Log/SystemLoggerInterface.php',
        'typo3\flow\package\documentation\format' => $flowClassesPath . 'TYPO3/Flow/Package/Documentation/Format.php',
        'typo3\flow\package\documentation' => $flowClassesPath . 'TYPO3/Flow/Package/Documentation.php',
        'typo3\flow\package\exception\corruptpackageexception' => $flowClassesPath . 'TYPO3/Flow/Package/Exception/CorruptPackageException.php',
index 4fb287b..f5601ef 100644 (file)
@@ -78,6 +78,11 @@ class LocalizationUtility {
        static protected $alternativeLanguageKeys = array();
 
        /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        */
+       static protected $configurationManager = NULL;
+
+       /**
         * Returns the localized label of the LOCAL_LANG key, $key.
         *
         * @param string $key The key from the LOCAL_LANG array for which to return the value.
@@ -298,8 +303,12 @@ class LocalizationUtility {
         * @return \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
         */
        static protected function getConfigurationManager() {
+               if (!is_null(static::$configurationManager)) {
+                       return static::$configurationManager;
+               }
                $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
                $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               static::$configurationManager = $configurationManager;
                return $configurationManager;
        }
 }
index 63492f5..7d9ceae 100644 (file)
@@ -24,15 +24,19 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
 /**
  * Test case
  */
 class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Extbase\Utility\LocalizationUtility|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
+        * Instance of configurationManager, injected to subject
+        *
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
         */
-       protected $localization;
+       protected $configurationManagerMock;
 
        /**
         * LOCAL_LANG array fixture
@@ -152,8 +156,39 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                ),
        );
 
+       /**
+        * Prepare class mocking some dependencies
+        */
        public function setUp() {
-               $this->localization = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility', array('getConfigurationManager'));
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
+
+               $this->configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
+               $property = $reflectionClass->getProperty('configurationManager');
+               $property->setAccessible(TRUE);
+               $property->setValue($this->configurationManager);
+       }
+
+       /**
+        * Reset static properties
+        */
+       public function tearDown() {
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
+
+               $property = $reflectionClass->getProperty('configurationManager');
+               $property->setAccessible(TRUE);
+               $property->setValue(NULL);
+
+               $property = $reflectionClass->getProperty('LOCAL_LANG');
+               $property->setAccessible(TRUE);
+               $property->setValue(array());
+
+               $property = $reflectionClass->getProperty('languageKey');
+               $property->setAccessible(TRUE);
+               $property->setValue('default');
+
+               $property = $reflectionClass->getProperty('alternativeLanguageKeys');
+               $property->setAccessible(TRUE);
+               $property->setValue(array());
        }
 
        /**
@@ -161,13 +196,17 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
         */
        public function implodeTypoScriptLabelArrayWorks() {
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
+               $method = $reflectionClass->getMethod('flattenTypoScriptLabelArray');
+               $method->setAccessible(TRUE);
+
                $expected = array(
                        'key1' => 'value1',
                        'key2' => 'value2',
                        'key3.subkey1' => 'subvalue1',
                        'key3.subkey2.subsubkey' => 'val'
                );
-               $actual = $this->localization->_call('flattenTypoScriptLabelArray', array(
+               $input = array(
                        'key1' => 'value1',
                        'key2' => 'value2',
                        'key3' => array(
@@ -176,28 +215,23 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        'subsubkey' => 'val'
                                )
                        )
-               ));
-               $this->assertEquals($expected, $actual);
+               );
+               $result = $method->invoke(NULL, $input);
+               $this->assertEquals($expected, $result);
        }
 
        /**
         * @test
         */
        public function translateForEmptyStringKeyReturnsNull() {
-               $this->localization->_setStatic('LOCAL_LANG', array());
-               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
-               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
-               $this->assertNull($this->localization->translate('', 'extbase'));
+               $this->assertNull(LocalizationUtility::translate('', 'extbase'));
        }
 
        /**
         * @test
         */
        public function translateForEmptyStringKeyWithArgumentsReturnsNull() {
-               $this->localization->_setStatic('LOCAL_LANG', array());
-               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
-               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
-               $this->assertNull($this->localization->translate('', 'extbase', array('argument')));
+               $this->assertNull(LocalizationUtility::translate('', 'extbase', array('argument')));
        }
 
        /**
@@ -246,11 +280,21 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function translateTest($key, array $LOCAL_LANG, $languageKey, $expected, array $altLanguageKeys = array(), array $arguments = NULL) {
-               $this->localization->_setStatic('LOCAL_LANG', $LOCAL_LANG);
-               $this->localization->_setStatic('languageKey', $languageKey);
-               $this->localization->_setStatic('alternativeLanguageKeys', $altLanguageKeys);
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
+
+               $property = $reflectionClass->getProperty('LOCAL_LANG');
+               $property->setAccessible(TRUE);
+               $property->setValue($LOCAL_LANG);
+
+               $property = $reflectionClass->getProperty('languageKey');
+               $property->setAccessible(TRUE);
+               $property->setValue($languageKey);
+
+               $property = $reflectionClass->getProperty('alternativeLanguageKeys');
+               $property->setAccessible(TRUE);
+               $property->setValue($altLanguageKeys);
 
-               $this->assertEquals($expected, $this->localization->translate($key, 'extensionKey', $arguments));
+               $this->assertEquals($expected, LocalizationUtility::translate($key, 'extensionKey', $arguments));
        }
 
        /**
@@ -356,20 +400,27 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function loadTypoScriptLabels(array $LOCAL_LANG, array $typoScriptLocalLang, $languageKey, array $expected) {
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
 
-               $configurationType = \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
+               $property = $reflectionClass->getProperty('LOCAL_LANG');
+               $property->setAccessible(TRUE);
+               $property->setValue($LOCAL_LANG);
+
+               $property = $reflectionClass->getProperty('languageKey');
+               $property->setAccessible(TRUE);
+               $property->setValue($languageKey);
 
-               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
-               $configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
+               $configurationType = \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
+               $this->configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
 
-               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
+               $method = $reflectionClass->getMethod('loadTypoScriptLabels');
+               $method->setAccessible(TRUE);
+               $method->invoke(NULL, 'extensionKey');
 
-               // translations loaded from xml files
-               $this->localization->_setStatic('LOCAL_LANG', $LOCAL_LANG);
-               $this->localization->_setStatic('languageKey', $languageKey);
+               $property = $reflectionClass->getProperty('LOCAL_LANG');
+               $property->setAccessible(TRUE);
+               $result = $property->getValue();
 
-               $this->localization->_call('loadTypoScriptLabels', 'extensionKey');
-               $result = $this->localization->_getStatic('LOCAL_LANG');
                $this->assertEquals($expected, $result['extensionKey'][$languageKey]);
        }
 
@@ -378,8 +429,15 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function clearLabelWithTypoScript() {
-               $this->localization->_setStatic('LOCAL_LANG', $this->LOCAL_LANG);
-               $this->localization->_setStatic('languageKey', 'dk');
+               $reflectionClass = new \ReflectionClass('TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
+
+               $property = $reflectionClass->getProperty('LOCAL_LANG');
+               $property->setAccessible(TRUE);
+               $property->setValue($this->LOCAL_LANG);
+
+               $property = $reflectionClass->getProperty('languageKey');
+               $property->setAccessible(TRUE);
+               $property->setValue('dk');
 
                $typoScriptLocalLang = array(
                        '_LOCAL_LANG' => array(
@@ -390,14 +448,13 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                );
 
                $configurationType = \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
+               $this->configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
 
-               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
-               $configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
-
-               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
+               $method = $reflectionClass->getMethod('loadTypoScriptLabels');
+               $method->setAccessible(TRUE);
+               $method->invoke(NULL, 'extensionKey');
 
-               $this->localization->_call('loadTypoScriptLabels', 'extensionKey');
-               $result = $this->localization->translate('key1', 'extensionKey');
+               $result = LocalizationUtility::translate('key1', 'extensionKey');
                $this->assertNotNull($result);
                $this->assertEquals('', $result);
        }