Daniel Werner has uploaded a new change for review.
https://gerrit.wikimedia.org/r/69512
Change subject: Basic tests for DataTypes\DataTypesModule
......................................................................
Basic tests for DataTypes\DataTypesModule
Change-Id: I3524ded6394ab3931c28ab0b31aebef0a0ecbaef
---
M DataTypes/includes/DataTypeFactory.php
A DataTypes/tests/phpunit/DataTypesModuleTest.php
2 files changed, 180 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/12/69512/1
diff --git a/DataTypes/includes/DataTypeFactory.php
b/DataTypes/includes/DataTypeFactory.php
index 41a8e85..35f54a7 100644
--- a/DataTypes/includes/DataTypeFactory.php
+++ b/DataTypes/includes/DataTypeFactory.php
@@ -119,7 +119,8 @@
* - if $builderSpec as an associative array, newType( $typeId,
$builderSpec )
* is called for backwards compatibility
*
- * @throws \InvalidArgumentException
+ * @throws InvalidArgumentException
+ * @throws RuntimeException
* @return DataType
*/
protected function buildType( $typeId, $builderSpec ) {
diff --git a/DataTypes/tests/phpunit/DataTypesModuleTest.php
b/DataTypes/tests/phpunit/DataTypesModuleTest.php
new file mode 100644
index 0000000..05a4db1
--- /dev/null
+++ b/DataTypes/tests/phpunit/DataTypesModuleTest.php
@@ -0,0 +1,178 @@
+<?php
+
+namespace DataTypes\Test;
+
+use DataTypes\DataTypesModule;
+use DataTypes\DataTypeFactory;
+
+/**
+ * @covers DataTypesModule
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @since 0.1
+ *
+ * @ingroup DataTypesTest
+ *
+ * @group DataTypes
+ * @group DataValueExtensions
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner < [email protected] >
+ */
+class DataTypesModuleTest extends \PHPUnit_Framework_TestCase {
+ /**
+ * Array holding arrays with keys-value pairs required in resource
definitions using the
+ * DataTypesModule class.
+ *
+ * @var array
+ */
+ protected $validResourceDefinitions = array();
+
+ /**
+ * Array of arrays where the first value is an array of invalid
resource definitions that will
+ * raise an error if used in resource definitions using the
DataTypesModule class. The second
+ * value of each 2nd level array is a string describing what is wrong
with the resource
+ * definition.
+ *
+ * @var array
+ */
+ protected $invalidResourcesCases = array();
+
+ public function __construct( $name = null, $data = array(), $dataName =
'' ) {
+ parent::__construct( $name, $data, $dataName );
+
+ $dataTypeFactory = new DataTypeFactory();
+
+ $this->validResourceDefinitions += array(
+ array(
+ 'datatypesconfigvarname' => 'foo',
+ 'datatypefactory' => function() {
+ return new DataTypeFactory();
+ }
+ ),
+ array(
+ 'datatypesconfigvarname' => 'bar123',
+ 'datatypefactory' => $dataTypeFactory
+ )
+ );
+
+ $this->invalidResourcesCases += array(
+ array(
+ array(
+ 'datatypesconfigvarname' => 'foo'
+ ),
+ 'missing "datatypefactory" field'
+ ),
+ array(
+ array(
+ 'datatypefactory' => $dataTypeFactory
+ ),
+ 'missing "datatypesconfigvarname" field'
+ ),
+ array(
+ array(),
+ 'all fields missing'
+ ),
+ array(
+ array_merge(
+ $this->validResourceDefinitions[0],
+ array(
+ 'datatypefactory' => 123
+ )
+ ),
+ '"datatypefactory" field has value of wrong
type'
+ ),
+ array(
+ array_merge(
+ $this->validResourceDefinitions[0],
+ array(
+ 'datatypefactory' => function()
{
+ return null;
+ }
+ )
+ ),
+ '"datatypefactory" callback does not return a
DataTypeFactory instance'
+ )
+ );
+ }
+
+ /**
+ * @return array [instance, resource definition]
+ */
+ public function provideDataTypesModuleAndResourceDefinition() {
+ $cases = array();
+
+ foreach( $this->validResourceDefinitions as $definition ) {
+ $instance = new DataTypesModule( $definition );
+ $cases[] = array( $instance, $definition );
+ }
+
+ return $cases;
+ }
+
+ /**
+ * @return array [invalid resource definition, case description]
+ */
+ public function provideInvalidResourceDefinition() {
+ return $this->invalidResourcesCases;
+ }
+
+ /**
+ * @dataProvider provideDataTypesModuleAndResourceDefinition
+ *
+ * @param DataTypesModule $module
+ * @param array $definition
+ */
+ public function testGetDataTypeFactory( DataTypesModule $module, array
$definition ) {
+ $this->assertInstanceOf(
+ 'DataTypes\DataTypeFactory',
+ $module->getDataTypeFactory()
+ );
+ }
+
+ /**
+ * @dataProvider provideDataTypesModuleAndResourceDefinition
+ *
+ * @param DataTypesModule $module
+ * @param array $definition
+ */
+ public function testGetConfigVarName( DataTypesModule $module, array
$definition ) {
+ $configVarName = $module->getConfigVarName();
+
+ $this->assertInternalType( 'string', $configVarName );
+
+ $this->assertSame(
+ $definition['datatypesconfigvarname'],
+ $module->getConfigVarName()
+ );
+ }
+
+ /**
+ * @dataProvider provideInvalidResourceDefinition
+ *
+ * @param array $definition
+ * @param string $caseDescription
+ */
+ public function testConstructorErrors( array $definition,
$caseDescription ) {
+ $this->setName( 'Instantiation raises exception in case ' +
$caseDescription );
+ $this->setExpectedException( 'Exception' );
+
+ new DataTypesModule( $definition );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/69512
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3524ded6394ab3931c28ab0b31aebef0a0ecbaef
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits