Skip to content

Commit

Permalink
Increase code coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
thiemowmde committed Mar 15, 2016
1 parent d4745ef commit d658952
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
8 changes: 8 additions & 0 deletions tests/phpunit/Comparer/ComparableComparerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function testDifferentValuesAreNotEqual( $firstValue, $secondValue ) {

public function unequalProvider() {
return array(
array(
null,
null
),
array(
new StubComparable( 1 ),
null
),
array(
new StubComparable( 1 ),
new StubComparable( 2 ),
Expand Down
16 changes: 12 additions & 4 deletions tests/phpunit/DiffOp/Diff/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,15 @@ public function testEquals( Diff $diff, Diff $target ) {
}

public function equalsProvider() {
$empty = new Diff();

return array(
// Identity
array( $empty, $empty ),

// Empty diffs
array( new Diff(), new Diff() ),
array( new Diff(), new Diff( array(), null ) ),
array( $empty, new Diff() ),
array( $empty, new Diff( array(), null ) ),

// Simple diffs
array( new Diff( array( new DiffOpAdd( 1 ) ) ), new Diff( array( new DiffOpAdd( 1 ) ) ) ),
Expand All @@ -697,13 +702,16 @@ public function equalsProvider() {
/**
* @dataProvider notEqualsProvider
*/
public function testNotEquals( Diff $diff, Diff $target ) {
public function testNotEquals( Diff $diff, $target ) {
$this->assertFalse( $diff->equals( $target ) );
$this->assertFalse( $target->equals( $diff ) );
}

public function notEqualsProvider() {
return array(
// Not an instance or subclass of Diff
array( new Diff(), null ),
array( new Diff(), new DiffOpAdd( 1 ) ),

// Empty diffs
array( new Diff(), new Diff( array(), false ) ),
array( new Diff(), new Diff( array(), true ) ),
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/Differ/ListDifferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Diff\Tests\Differ;

use Diff\ArrayComparer\NativeArrayComparer;
use Diff\ArrayComparer\StrictArrayComparer;
use Diff\Differ\Differ;
use Diff\Differ\ListDiffer;
use Diff\DiffOp\DiffOpAdd;
Expand All @@ -20,6 +21,32 @@
*/
class ListDifferTest extends DiffTestCase {

public function arrayComparerProvider() {
$add = array( new DiffOpAdd( 1 ) );

return array(
'null' => array( null, $add ),
'native const' => array( ListDiffer::MODE_NATIVE, array() ),
'strict const' => array( ListDiffer::MODE_STRICT, $add ),
'native object' => array( new NativeArrayComparer(), array() ),
'strict object' => array( new StrictArrayComparer(), $add ),
);
}

/**
* @dataProvider arrayComparerProvider
*/
public function testConstructor( $arrayComparer, array $expected ) {
$differ = new ListDiffer( $arrayComparer );
$diff = $differ->doDiff( array( 1 ), array( 1, 1 ) );
$this->assertEquals( $expected, $diff );
}

public function testInvalidConstructorArgument() {
$this->setExpectedException( 'InvalidArgumentException' );
new ListDiffer( 2 );
}

/**
* Returns those that both work for native and strict mode.
*/
Expand Down

0 comments on commit d658952

Please sign in to comment.