From 734f0150350b1946ea93ce877b3b9e735ab45f3c Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 17 Aug 2016 09:26:38 -0700 Subject: [PATCH] ObjectFactoryTest: Add tests for 'factory' option Increase coverage of getObjectFromSpec(): * Case for 'factory' option. * Case for 'class' option with no arguments. * Case for missing 'factory' and 'class' options. Change-Id: Idc9ee73de4f6e55372b4ab5b1afbaa4c7e54509a --- .../includes/libs/ObjectFactoryTest.php | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/libs/ObjectFactoryTest.php b/tests/phpunit/includes/libs/ObjectFactoryTest.php index 043be4e17c..f8dda6f8af 100644 --- a/tests/phpunit/includes/libs/ObjectFactoryTest.php +++ b/tests/phpunit/includes/libs/ObjectFactoryTest.php @@ -81,6 +81,44 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { $this->assertSame( 'unwrapped', $obj->setterArgs[0] ); } + /** + * @covers ObjectFactory::getObjectFromSpec + */ + public function testGetObjectFromFactory() { + $args = [ 'a', 'b' ]; + $obj = ObjectFactory::getObjectFromSpec( [ + 'factory' => function ( $a, $b ) { + return new ObjectFactoryTestFixture( $a, $b ); + }, + 'args' => $args, + ] ); + $this->assertSame( $args, $obj->args ); + } + + /** + * @covers ObjectFactory::getObjectFromSpec + * @expectedException InvalidArgumentException + */ + public function testGetObjectFromInvalid() { + $args = [ 'a', 'b' ]; + $obj = ObjectFactory::getObjectFromSpec( [ + // Missing 'class' or 'factory' + 'args' => $args, + ] ); + } + + /** + * @covers ObjectFactory::getObjectFromSpec + * @dataProvider provideConstructClassInstance + */ + public function testGetObjectFromClass( $args ) { + $obj = ObjectFactory::getObjectFromSpec( [ + 'class' => 'ObjectFactoryTestFixture', + 'args' => $args, + ] ); + $this->assertSame( $args, $obj->args ); + } + /** * @covers ObjectFactory::constructClassInstance * @dataProvider provideConstructClassInstance @@ -92,7 +130,7 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { $this->assertSame( $args, $obj->args ); } - public function provideConstructClassInstance() { + public static function provideConstructClassInstance() { // These args go to 11. I thought about making 10 one louder, but 11! return [ '0 args' => [ [] ], -- 2.20.1