From: Timo Tijhof Date: Wed, 17 Aug 2016 16:26:38 +0000 (-0700) Subject: ObjectFactoryTest: Add tests for 'factory' option X-Git-Tag: 1.31.0-rc.0~6014^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=734f0150350b1946ea93ce877b3b9e735ab45f3c;p=lhc%2Fweb%2Fwiklou.git 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 --- 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' => [ [] ],