[TASK] Increase code coverage of SignalSlot/Dispatcher
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Thu, 17 Jan 2013 16:15:11 +0000 (17:15 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Fri, 18 Jan 2013 12:19:55 +0000 (13:19 +0100)
Added some missing tests to achieve 100% code coverage.
Also adjusted the copyright header and author annotations.

Releases: 6.1
Resolves: #44611
Change-Id: I9ffb474b5cd44d30c9eff49ae37ab55f5f68a5ce
Reviewed-on: https://review.typo3.org/17580
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/extbase/Tests/Unit/SignalSlot/DispatcherTest.php

index 522d220..76ba801 100644 (file)
@@ -4,12 +4,10 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\SignalSlot;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2011 Felix Oertel <f@oer.tel>
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
  *  All rights reserved
  *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
- *
  *  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
@@ -18,6 +16,9 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\SignalSlot;
  *
  *  The GNU General Public License can be found at
  *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
  *
  *  This script is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,21 +29,25 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\SignalSlot;
  ***************************************************************/
 /**
  * Testcase for the Signal Dispatcher Class
+ *
+ * @author Felix Oertel <f@oer.tel>
+ * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
  */
 class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
         */
        protected $signalSlotDispatcher;
 
        public function setUp() {
-               $accessibleClassName = $this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
+               $accessibleClassName = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher', array('dummy'));
                $this->signalSlotDispatcher = new $accessibleClassName();
        }
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function connectAllowsForConnectingASlotWithASignal() {
                $mockSignal = $this->getMock('ClassA', array('emitSomeSignal'));
@@ -56,6 +61,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function connectAlsoAcceptsObjectsInPlaceOfTheClassName() {
                $mockSignal = $this->getMock('ClassA', array('emitSomeSignal'));
@@ -69,6 +75,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function connectAlsoAcceptsClosuresActingAsASlot() {
                $mockSignal = $this->getMock('ClassA', array('emitSomeSignal'));
@@ -83,6 +90,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function dispatchPassesTheSignalArgumentsToTheSlotMethod() {
                $arguments = array();
@@ -96,6 +104,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function dispatchRetrievesSlotInstanceFromTheObjectManagerIfOnlyAClassNameWasSpecified() {
                $slotClassName = uniqid('Mock_');
@@ -114,6 +123,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         * @expectedException \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
+        * @author Felix Oertel <f@oer.tel>
         */
        public function dispatchThrowsAnExceptionIfTheSpecifiedClassOfASlotIsUnknown() {
                $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
@@ -127,6 +137,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         * @expectedException \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
+        * @author Felix Oertel <f@oer.tel>
         */
        public function dispatchThrowsAnExceptionIfTheSpecifiedSlotMethodDoesNotExist() {
                $slotClassName = uniqid('Mock_');
@@ -144,6 +155,7 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        * @author Felix Oertel <f@oer.tel>
         */
        public function dispatchPassesFirstArgumentContainingSlotInformationIfTheConnectionStatesSo() {
                $arguments = array();
@@ -157,6 +169,36 @@ class DispatcherTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->signalSlotDispatcher->dispatch('SignalClassName', 'methodName', array('foo' => 'bar', 'baz' => 'quux'));
                $this->assertSame(array('bar', 'quux', 'SignalClassName::methodName'), $arguments);
        }
+
+       /**
+        * @test
+        * @expectedException \InvalidArgumentException
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function connectThrowsInvalidArgumentExceptionIfSlotMethodNameIsEmptyAndSlotClassNameIsNoClosure() {
+               $this->signalSlotDispatcher->connect('ClassA', 'emitSomeSignal', 'ClassB', '');
+       }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function dispatchReturnsVoidIfSignalNameAndOrSignalClassNameIsNotRegistered() {
+               $this->assertSame(NULL, $this->signalSlotDispatcher->dispatch('ClassA', 'emitSomeSignal'));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function dispatchThrowsInvalidSlotExceptionIfObjectManagerOfSignalSlotDispatcherIsNotSet() {
+               $this->signalSlotDispatcher->_set('isInitialized', TRUE);
+               $this->signalSlotDispatcher->_set('objectManager', NULL);
+               $this->signalSlotDispatcher->_set('slots', array('ClassA' => array('emitSomeSignal' => array(array()))));
+
+               $this->assertSame(NULL, $this->signalSlotDispatcher->dispatch('ClassA', 'emitSomeSignal'));
+       }
 }
 
 ?>
\ No newline at end of file