Skip to content

Commit

Permalink
Merge "Null change op implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 6, 2017
2 parents f156500 + f1f3d13 commit 5b5c4ae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
29 changes: 29 additions & 0 deletions repo/includes/ChangeOp/NullChangeOp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Wikibase\Repo\ChangeOp;

use ValueValidators\Result;
use Wikibase\ChangeOp\ChangeOp;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\Summary;

/**
* @license GPL-2.0+
*/
class NullChangeOp implements ChangeOp {

/**
* @see ChangeOp::validate()
*/
public function validate( EntityDocument $entity ) {
return Result::newSuccess();
}

/**
* @see ChangeOp::apply()
*/
public function apply( EntityDocument $entity, Summary $summary = null ) {
// no op
}

}
40 changes: 40 additions & 0 deletions repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Wikibase\Repo\Tests\ChangeOp;

use PHPUnit_Framework_MockObject_MockObject;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\Repo\ChangeOp\NullChangeOp;

/**
* @covers Wikibase\Repo\ChangeOp\NullChangeOp
*
* @group Wikibase
* @license GPL-2.0+
*/
class NullChangeOpTest extends \PHPUnit_Framework_TestCase {

public function testReturnsValidResult_WhenValidatesEntityDocument() {
/** @var EntityDocument $entityDocument */
$entityDocument = $this->getMock( EntityDocument::class );
$nullChangeOp = new NullChangeOp();

$result = $nullChangeOp->validate( $entityDocument );

self::assertTrue( $result->isValid() );
}

public function testDoesNotCallAnyMethodOnEntity_WhenApplied() {
/** @var EntityDocument|PHPUnit_Framework_MockObject_MockObject $entityDocument */
$entityDocument = $this->getMock( EntityDocument::class );
$nullChangeOp = new NullChangeOp();

$this->expectNoMethodWillBeEverCalledOn( $entityDocument );
$nullChangeOp->apply( $entityDocument );
}

private function expectNoMethodWillBeEverCalledOn( PHPUnit_Framework_MockObject_MockObject $entityMock ) {
$entityMock->expects( $this->never() )->method( self::anything() );
}

}

0 comments on commit 5b5c4ae

Please sign in to comment.