From 5eba9f361a97db3f7f5dee2429d8a11ae0bb3101 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 23 Jan 2012 14:50:54 +0000 Subject: [PATCH] FileRepo: check constructor parameters new FileRepo() requires an array of parameters having at least the 'name' and 'backend' key setup. TODO: 'backend' keyword should probably default to FileBackend. --- includes/filerepo/FileRepo.php | 11 +++++- .../includes/filerepo/FileRepoTest.php | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/includes/filerepo/FileRepoTest.php diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index e7608ca4f2..c9e5e7ff66 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -39,7 +39,16 @@ class FileRepo { var $oldFileFactory = false; var $fileFactoryKey = false, $oldFileFactoryKey = false; - function __construct( $info ) { + function __construct( Array $info = null ) { + // Verify required settings presence + if( + $info === null + || !array_key_exists( 'name', $info ) + || !array_key_exists( 'backend', $info ) + ) { + throw new MWException( __CLASS__ . " requires an array of options having both 'name' and 'backend' keys.\n" ); + } + // Required settings $this->name = $info['name']; if ( $info['backend'] instanceof FileBackendBase ) { diff --git a/tests/phpunit/includes/filerepo/FileRepoTest.php b/tests/phpunit/includes/filerepo/FileRepoTest.php new file mode 100644 index 0000000000..ca34442a7e --- /dev/null +++ b/tests/phpunit/includes/filerepo/FileRepoTest.php @@ -0,0 +1,34 @@ + 'foobar' + ) ); + } + /** + * @expectedException MWException + */ + function testFileRepoConstructionOptionNeedBackendKey() { + $f = new FileRepo( array( + 'name' => 'foobar' + ) ); + } + +} -- 2.20.1