ObjectFactory: Complete code coverage for ObjectFactoryTest
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 1 Apr 2017 01:07:59 +0000 (18:07 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 1 Apr 2017 01:07:59 +0000 (18:07 -0700)
Cover missing case of expandClosures() where the array contains
both a closure and a non-closure.

Change-Id: I30ea8cf3fb909a499a95bf9bd24792f4dd6b5c64

tests/phpunit/includes/libs/ObjectFactoryTest.php

index f8dda6f..3e0a61e 100644 (file)
@@ -26,20 +26,24 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase {
        public function testClosureExpansionDisabled() {
                $obj = ObjectFactory::getObjectFromSpec( [
                        'class' => 'ObjectFactoryTestFixture',
-                       'args' => [ function() {
-                               return 'unwrapped';
-                       }, ],
+                       'args' => [
+                               function() {
+                                       return 'wrapped';
+                               },
+                               'unwrapped',
+                       ],
                        'calls' => [
                                'setter' => [ function() {
-                                       return 'unwrapped';
+                                       return 'wrapped';
                                }, ],
                        ],
                        'closure_expansion' => false,
                ] );
                $this->assertInstanceOf( 'Closure', $obj->args[0] );
-               $this->assertSame( 'unwrapped', $obj->args[0]() );
+               $this->assertSame( 'wrapped', $obj->args[0]() );
+               $this->assertSame( 'unwrapped', $obj->args[1] );
                $this->assertInstanceOf( 'Closure', $obj->setterArgs[0] );
-               $this->assertSame( 'unwrapped', $obj->setterArgs[0]() );
+               $this->assertSame( 'wrapped', $obj->setterArgs[0]() );
        }
 
        /**
@@ -49,20 +53,24 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase {
        public function testClosureExpansionEnabled() {
                $obj = ObjectFactory::getObjectFromSpec( [
                        'class' => 'ObjectFactoryTestFixture',
-                       'args' => [ function() {
-                               return 'unwrapped';
-                       }, ],
+                       'args' => [
+                               function() {
+                                       return 'wrapped';
+                               },
+                               'unwrapped',
+                       ],
                        'calls' => [
                                'setter' => [ function() {
-                                       return 'unwrapped';
+                                       return 'wrapped';
                                }, ],
                        ],
                        'closure_expansion' => true,
                ] );
                $this->assertInternalType( 'string', $obj->args[0] );
-               $this->assertSame( 'unwrapped', $obj->args[0] );
+               $this->assertSame( 'wrapped', $obj->args[0] );
+               $this->assertSame( 'unwrapped', $obj->args[1] );
                $this->assertInternalType( 'string', $obj->setterArgs[0] );
-               $this->assertSame( 'unwrapped', $obj->setterArgs[0] );
+               $this->assertSame( 'wrapped', $obj->setterArgs[0] );
 
                $obj = ObjectFactory::getObjectFromSpec( [
                        'class' => 'ObjectFactoryTestFixture',