[TASK] Add test integrity test
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 11 Sep 2012 17:14:32 +0000 (19:14 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 11 Sep 2012 17:47:20 +0000 (19:47 +0200)
In the past it happened quite often that some test did not take care
of proper backing up globals or other environment settings. This
usually leads to failing tests if they are run afterwards. Those
side effects are often hard to track down and take quite some time
if searching for the one test that breaks the environment.

Therefor, a new "Integrity" test is added to the system that is
executed as the very last test in the list of test suites. It checks
that important things that were messed up in the past are still working.

Currently it checks that the registered singleton instances are still
there, that $GLOBALS['TYPO3_DB'] still has a valid resource link to
the database, and $GLOBALS['typo3CacheManager'] is still a valid
class instance.

If one of this test fails after any merge (especially combined with
travis), it is now obvious that this merge broke the environment, so
the evil test can be found much quicker and the evil merge can be
reverted directly.

Change-Id: I0dc733081ea9ad0c050a7dbcf4d95dd8f819f1bf
Resolves: #40832
Releases: 6.0
Reviewed-on: http://review.typo3.org/14524
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
tests/Build/UnitTests.xml
typo3/sysext/core/Tests/Integrity/IntegrityTest.php [new file with mode: 0644]

index 52cb86a..506e776 100644 (file)
        verbose="false">
 
        <testsuites>
-               <testsuite name="EXT:core Tests">
+               <testsuite name="EXT:core tests">
                        <directory>../../typo3/sysext/core/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:backend Tests">
+               <testsuite name="EXT:backend tests">
                        <directory>../../typo3/sysext/backend/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:frontend Tests">
+               <testsuite name="EXT:frontend tests">
                        <directory>../../typo3/sysext/frontend/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="Core Tests">
+               <testsuite name="Core tests">
                        <directory>../../tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:beuser Tests">
+               <testsuite name="EXT:beuser tests">
                        <directory>../../typo3/sysext/beuser/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:extbase Tests">
+               <testsuite name="EXT:extbase tests">
                        <directory>../../typo3/sysext/extbase/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:extensionmanager Tests">
+               <testsuite name="EXT:extensionmanager tests">
                        <directory>../../typo3/sysext/extensionmanager/Tests/Unit/</directory>
                </testsuite>
-               <testsuite name="EXT:fluid Tests">
+               <testsuite name="EXT:fluid tests">
                        <directory>../../typo3/sysext/fluid/Tests/Unit/</directory>
                </testsuite>
+               <testsuite name="Suite integrity tests">
+                       <directory>../../typo3/sysext/core/Tests/Integrity/</directory>
+               </testsuite>
        </testsuites>
 
 </phpunit>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Integrity/IntegrityTest.php b/typo3/sysext/core/Tests/Integrity/IntegrityTest.php
new file mode 100644 (file)
index 0000000..3f77ba5
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Integrity;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This test case is used in test suites to check for healthy
+ * environments after other tests were run.
+ *
+ * This test is usually executed as the very last file in a suite and
+ * should fail if some other test before destroys the environment with
+ * invalid mocking or backups.
+ */
+class IntegrityTest extends \Tx_Phpunit_TestCase {
+
+       /**
+        * This test fails if some test before either set
+        * $backupGlobals to TRUE and did not add TYPO3_DB to
+        * $backupGlobalsBlacklist, or if it mocked
+        * TYPO3\CMS\Core\Database\DatabaseConnection and
+        * did not reconstitute the existing connection.
+        *
+        * @test
+        */
+       public function globalsTypo3DbDatabaseLinkIsAResource() {
+               $this->assertTrue(is_resource($GLOBALS['TYPO3_DB']->link));
+       }
+
+       /**
+        * This test fails if some test before mocked or substituted
+        * $GLOBALS['typo3CacheManager'] but did not reconstitute correctly.
+        *
+        * @test
+        */
+       public function globalsTypo3CacheManagerIsInstanceOfCoreCacheManager() {
+               $this->assertTrue(is_object($GLOBALS['typo3CacheManager']));
+               $this->assertTrue($GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager);
+       }
+
+       /**
+        * This test fails if some test before called
+        * \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances() without a proper
+        * backup via \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances()
+        * and a reconstitution via \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances().
+        *
+        * The test for CacheManager should never fail since this object is
+        * already instantiated during bootstrap and must always be there.
+        *
+        * @test
+        */
+       public function standardSingletonIsRegistered() {
+               $registeredSingletons = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+               $this->assertArrayHasKey('TYPO3\CMS\Core\Cache\CacheManager', $registeredSingletons);
+       }
+}
+
+?>
\ No newline at end of file