Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/65261
Change subject: Got rid of DiffOpTestDummy
......................................................................
Got rid of DiffOpTestDummy
According to PHPUnit this was the biggest piece of CRAP with
a risk score of 72, bigger then anything else in Diff :)
Change-Id: I2b2d45f96e8fab03de92c269e526cd628168a4e3
---
M Diff.classes.php
M tests/phpunit/DiffOpFactoryTest.php
D tests/phpunit/DiffOpTestDummy.php
M tests/phpunit/diffop/DiffOpAddTest.php
M tests/phpunit/diffop/DiffOpChangeTest.php
M tests/phpunit/diffop/DiffOpRemoveTest.php
M tests/phpunit/diffop/DiffOpTest.php
M tests/phpunit/diffop/diff/DiffAsOpTest.php
8 files changed, 42 insertions(+), 98 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Diff
refs/changes/61/65261/1
diff --git a/Diff.classes.php b/Diff.classes.php
index fb806a0..39a8a52 100644
--- a/Diff.classes.php
+++ b/Diff.classes.php
@@ -44,6 +44,5 @@
'Diff\MapDiff' => 'includes/diffop/diff/MapDiff.php',
'Diff\Tests\DiffOpTest' => 'tests/phpunit/diffop/DiffOpTest.php',
- 'Diff\Tests\DiffOpTestDummy' => 'tests/phpunit/DiffOpTestDummy.php',
'Diff\Tests\DiffTestCase' => 'tests/phpunit/DiffTestCase.php',
);
diff --git a/tests/phpunit/DiffOpFactoryTest.php
b/tests/phpunit/DiffOpFactoryTest.php
index fd030ca..ee6ec6c 100644
--- a/tests/phpunit/DiffOpFactoryTest.php
+++ b/tests/phpunit/DiffOpFactoryTest.php
@@ -49,7 +49,7 @@
$diffOps[9001] = new DiffOpAdd( 4.2 );
$diffOps['42'] = new DiffOpAdd( array( 42, array( 9001 ) ) );
$diffOps[] = new DiffOpRemove( 42 );
- $diffOps[] = new DiffOpAdd( new DiffOpTestDummy( "spam" ) );
+ $diffOps[] = new DiffOpAdd( new DiffOpChange( 'spam', 'moar
spam' ) );
$atomicDiffOps = $diffOps;
@@ -87,34 +87,36 @@
* @param DiffOp $diffOp
*/
public function testNewFromArrayWithConversion( DiffOp $diffOp ) {
- $factory = new DiffOpFactory(
'Diff\Tests\DiffOpTestDummy::objectify' );
+ $unserializationFunction = function( $array ) {
+ if ( is_array( $array ) && isset( $array['type'] ) &&
$array['type'] === 'Change' ) {
+ return new DiffOpChange( $array['teh_old'],
$array['teh_new'] );
+ }
+
+ return $array;
+ };
+
+ $factory = new DiffOpFactory( $unserializationFunction );
+
+ $serializationFunction = function( $obj ) {
+ if ( $obj instanceof DiffOpChange ) {
+ return array(
+ 'type' => 'Change',
+ 'teh_old' => $obj->getOldValue(),
+ 'teh_new' => $obj->getNewValue(),
+ );
+ }
+
+ return $obj;
+ };
// try with conversion callback
- $array = $diffOp->toArray(
'Diff\Tests\DiffOpTestDummy::arrayalize' );
+ $array = $diffOp->toArray( $serializationFunction );
+
$newInstance = $factory->newFromArray( $array );
// If an equality method is implemented in DiffOp, it should be
used here
$this->assertEquals( $diffOp, $newInstance );
$this->assertEquals( $diffOp->getType(),
$newInstance->getType() );
- }
-
- public static function dummyToArray( $obj ) {
- if ( $obj instanceof DiffOpTestDummy ) {
- return array(
- 'type' => 'Dummy',
- 'text' => $obj->text,
- );
- }
-
- return $obj;
- }
-
- public static function arrayToDummy( $array ) {
- if ( is_array( $array ) && isset( $array['type'] ) &&
$array['type'] === 'Dummy' ) {
- return new DiffOpTestDummy( $array['text'] );
- }
-
- return $array;
}
public function invalidArrayFromArrayProvider() {
diff --git a/tests/phpunit/DiffOpTestDummy.php
b/tests/phpunit/DiffOpTestDummy.php
deleted file mode 100644
index 510fac1..0000000
--- a/tests/phpunit/DiffOpTestDummy.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-namespace Diff\Tests;
-
-/**
- * Dummy class for testing DiffOps.
- *
- * 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.5
- *
- * @ingroup DiffTest
- *
- * @group Diff
- *
- * @licence GNU GPL v2+
- * @author Daniel Kinzler
- */
-
-class DiffOpTestDummy {
- public $text;
-
- public function __construct( $text ) {
- $this->text = $text;
- }
-
- public function __toString() {
- return get_class( $this ) . ': ' . $this->text;
- }
-
- public static function arrayalize( $obj ) {
- if ( $obj instanceof DiffOpTestDummy ) {
- return array(
- 'type' => 'Dummy',
- 'text' => $obj->text,
- );
- }
-
- return $obj;
- }
-
- public static function objectify( $array ) {
- if ( is_array( $array ) && isset( $array['type'] ) &&
$array['type'] === 'Dummy' ) {
- return new DiffOpTestDummy( $array['text'] );
- }
-
- return $array;
- }
-}
diff --git a/tests/phpunit/diffop/DiffOpAddTest.php
b/tests/phpunit/diffop/DiffOpAddTest.php
index e1b02ae..93819e7 100644
--- a/tests/phpunit/diffop/DiffOpAddTest.php
+++ b/tests/phpunit/diffop/DiffOpAddTest.php
@@ -59,7 +59,7 @@
array( true, array() ),
array( true, true ),
array( true, 42 ),
- array( true, new DiffOpTestDummy( "spam" ) ),
+ array( true, new DiffOpAdd( "spam" ) ),
array( false ),
);
}
diff --git a/tests/phpunit/diffop/DiffOpChangeTest.php
b/tests/phpunit/diffop/DiffOpChangeTest.php
index e11246f..70fddb1 100644
--- a/tests/phpunit/diffop/DiffOpChangeTest.php
+++ b/tests/phpunit/diffop/DiffOpChangeTest.php
@@ -2,6 +2,7 @@
namespace Diff\Tests;
+use Diff\DiffOpAdd;
use Diff\DiffOpChange;
/**
@@ -63,7 +64,7 @@
array( true, 42, 42 ),
array( true, 'foo', array( 'foo' ) ),
array( true, 'foo', null ),
- array( true, new DiffOpTestDummy( "ham" ), new
DiffOpTestDummy( "spam" ) ),
+ array( true, new DiffOpAdd( "ham" ), new DiffOpAdd(
"spam" ) ),
array( true, null, null ),
array( false ),
);
diff --git a/tests/phpunit/diffop/DiffOpRemoveTest.php
b/tests/phpunit/diffop/DiffOpRemoveTest.php
index 39d94a6..4e48edf 100644
--- a/tests/phpunit/diffop/DiffOpRemoveTest.php
+++ b/tests/phpunit/diffop/DiffOpRemoveTest.php
@@ -2,6 +2,7 @@
namespace Diff\Tests;
+use Diff\DiffOpAdd;
use Diff\DiffOpRemove;
/**
@@ -59,7 +60,7 @@
array( true, array() ),
array( true, true ),
array( true, 42 ),
- array( true, new DiffOpTestDummy( "spam" ) ),
+ array( true, new DiffOpAdd( "spam" ) ),
array( false ),
);
}
diff --git a/tests/phpunit/diffop/DiffOpTest.php
b/tests/phpunit/diffop/DiffOpTest.php
index 0dbe1d5..963a453 100644
--- a/tests/phpunit/diffop/DiffOpTest.php
+++ b/tests/phpunit/diffop/DiffOpTest.php
@@ -185,7 +185,9 @@
* @dataProvider instanceProvider
*/
public function testToArrayWithConversion( DiffOp $diffOp ) {
- $array = $diffOp->toArray(
'Diff\Tests\DiffOpTestDummy::arrayalize' );
+ $array = $diffOp->toArray( function( $diffOp ) {
+ return array( 'Nyan!' );
+ } );
$this->assertInternalType( 'array', $array );
}
diff --git a/tests/phpunit/diffop/diff/DiffAsOpTest.php
b/tests/phpunit/diffop/diff/DiffAsOpTest.php
index 56f4f19..458fa91 100644
--- a/tests/phpunit/diffop/diff/DiffAsOpTest.php
+++ b/tests/phpunit/diffop/diff/DiffAsOpTest.php
@@ -3,6 +3,8 @@
namespace Diff\Tests;
use Diff\Diff;
+use Diff\DiffOpAdd;
+use Diff\DiffOpRemove;
/**
* @covers Diff\Diff
@@ -56,14 +58,14 @@
public function constructorProvider() {
$argLists = array(
array( true, array() ),
- array( true, array( new \Diff\DiffOpAdd( 42 ) ) ),
- array( true, array( new \Diff\DiffOpRemove( new
\Diff\Tests\DiffOpTestDummy( "spam" ) ) ) ),
- array( true, array( new \Diff\Diff( array( new
\Diff\DiffOpRemove( new \Diff\Tests\DiffOpTestDummy( "spam" ) ) ) ) ) ),
- array( true, array( new \Diff\DiffOpAdd( 42 ), new
\Diff\DiffOpAdd( 42 ) ) ),
- array( true, array( 'a' => new \Diff\DiffOpAdd( 42 ),
'b' => new \Diff\DiffOpAdd( 42 ) ) ),
- array( true, array( new \Diff\DiffOpAdd( 42 ), 'foo bar
baz' => new \Diff\DiffOpAdd( 42 ) ) ),
- array( true, array( 42 => new \Diff\DiffOpRemove( 42 ),
'9001' => new \Diff\DiffOpAdd( 42 ) ) ),
- array( true, array( 42 => new \Diff\DiffOpRemove( new
\stdClass() ), '9001' => new \Diff\DiffOpAdd( new \stdClass() ) ) ),
+ array( true, array( new DiffOpAdd( 42 ) ) ),
+ array( true, array( new DiffOpRemove( new DiffOpRemove(
"spam" ) ) ) ),
+ array( true, array( new Diff( array( new DiffOpRemove(
new DiffOpRemove( "spam" ) ) ) ) ) ),
+ array( true, array( new DiffOpAdd( 42 ), new DiffOpAdd(
42 ) ) ),
+ array( true, array( 'a' => new DiffOpAdd( 42 ), 'b' =>
new DiffOpAdd( 42 ) ) ),
+ array( true, array( new DiffOpAdd( 42 ), 'foo bar baz'
=> new DiffOpAdd( 42 ) ) ),
+ array( true, array( 42 => new DiffOpRemove( 42 ),
'9001' => new DiffOpAdd( 42 ) ) ),
+ array( true, array( 42 => new DiffOpRemove( new
\stdClass() ), '9001' => new DiffOpAdd( new \stdClass() ) ) ),
);
$allArgLists = $argLists;
--
To view, visit https://gerrit.wikimedia.org/r/65261
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2b2d45f96e8fab03de92c269e526cd628168a4e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Diff
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits