Skip to content

Commit

Permalink
Merge pull request #6 from SemanticMediaWiki/testcs
Browse files Browse the repository at this point in the history
Improvements to test code
  • Loading branch information
mwjames committed Jun 19, 2016
2 parents b362d71 + b0a7441 commit ee34ad9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 55 deletions.
16 changes: 4 additions & 12 deletions tests/phpunit/Unit/EchoNotificationsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
*/
class EchoNotificationsManagerTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {

$this->assertInstanceOf(
EchoNotificationsManager::class,
new EchoNotificationsManager()
);
}

public function testAddNotificationsDefinitions() {

$instance = new EchoNotificationsManager();
Expand Down Expand Up @@ -98,7 +90,7 @@ public function testGetNotificationsBundle() {
'revid' => 1001
);

$echoEvent = $this->getMockBuilder( '\EchoEvent' )
$echoEvent = $this->getMockBuilder( \EchoEvent::class )
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -127,11 +119,11 @@ public function testGetNotificationsBundle() {

public function testCreateEvent() {

$agent = $this->getMockBuilder( '\User' )
$agent = $this->getMockBuilder( \User::class )
->disableOriginalConstructor()
->getMock();

$title = $this->getMockBuilder( '\Title' )
$title = $this->getMockBuilder( \Title::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -144,7 +136,7 @@ public function testCreateEvent() {
$instance = new EchoNotificationsManager();

$this->assertInstanceOf(
'\EchoEvent',
\EchoEvent::class,
$instance->createEvent( $event )
);
}
Expand Down
30 changes: 14 additions & 16 deletions tests/phpunit/Unit/HookRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace SMW\Notifications\Tests;

use SMW\DataTypeRegistry;
use SMW\DIWikiPage;
use SMW\Notifications\HookRegistry;
use SMW\PropertyRegistry;
use SMW\SemanticData;
use SMW\SQLStore\CompositePropertyTableDiffIterator;
use SMWSQLStore3;

/**
* @covers \SMW\Notifications\HookRegistry
Expand All @@ -15,14 +21,6 @@
*/
class HookRegistryTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {

$this->assertInstanceOf(
HookRegistry::class,
new HookRegistry()
);
}

public function testRegister() {

$instance = new HookRegistry();
Expand All @@ -41,7 +39,7 @@ public function doTestRegisteredSMWPropertyInitProperties( $instance ) {

$handler = 'SMW::Property::initProperties';

$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' )
$propertyRegistry = $this->getMockBuilder( PropertyRegistry::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -59,7 +57,7 @@ public function doTestRegisteredSMWDataTypeInitTypes( $instance ) {

$handler = 'SMW::DataType::initTypes';

$dataTypeRegistry = $this->getMockBuilder( '\SMW\DataTypeRegistry' )
$dataTypeRegistry = $this->getMockBuilder( DataTypeRegistry::class )
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -131,7 +129,7 @@ public function doTestRegisteredEchoGetBundleRules( $instance ) {
$instance->isRegistered( $handler )
);

$echoEvent = $this->getMockBuilder( '\EchoEvent' )
$echoEvent = $this->getMockBuilder( \EchoEvent::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -151,7 +149,7 @@ public function doTestRegisteredEchoGetDefaultNotifiedUsers( $instance ) {
$instance->isRegistered( $handler )
);

$echoEvent = $this->getMockBuilder( '\EchoEvent' )
$echoEvent = $this->getMockBuilder( \EchoEvent::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -171,23 +169,23 @@ public function doTestRegisteredSMWSQLStoreAfterDataUpdateComplete( $instance )
$instance->isRegistered( $handler )
);

$subject = $this->getMockBuilder( '\SMW\DIWikiPage' )
$subject = $this->getMockBuilder( DIWikiPage::class )
->disableOriginalConstructor()
->getMock();

$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
$store = $this->getMockBuilder( SMWSQLStore3::class )
->disableOriginalConstructor()
->getMock();

$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
$semanticData = $this->getMockBuilder( SemanticData::class )
->disableOriginalConstructor()
->getMock();

$semanticData->expects( $this->once() )
->method( 'getSubject' )
->will( $this->returnValue( $subject ) );

$compositePropertyTableDiffIterator = $this->getMockBuilder( '\SMW\SQLStore\CompositePropertyTableDiffIterator' )
$compositePropertyTableDiffIterator = $this->getMockBuilder( CompositePropertyTableDiffIterator::class )
->disableOriginalConstructor()
->getMock();

Expand Down
20 changes: 7 additions & 13 deletions tests/phpunit/Unit/IteratorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace SMW\Notifications\Tests;

use RecursiveIterator;
use SMW\Notifications\IteratorFactory;
use SMW\Notifications\Iterator\CallbackIterator;
use SMW\Notifications\Iterator\RecursiveGroupMembersIterator;
use SMW\Notifications\Iterator\ChildlessRecursiveIterator;
use RecursiveIteratorIterator;
use SMW\Store;

/**
* @covers \SMW\Notifications\IteratorFactory
Expand All @@ -19,41 +21,33 @@
*/
class IteratorFactoryTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {

$this->assertInstanceOf(
IteratorFactory::class,
new IteratorFactory()
);
}

public function testCanConstructCallbackIterator() {

$instance = new IteratorFactory();

$this->assertInstanceOf(
CallbackIterator::class,
$instance->newCallbackIterator( array(), function(){} )
$instance->newCallbackIterator( [], function() {} )
);
}

public function testCanConstructRecursiveGroupMembersIterator() {

$store = $this->getMockBuilder( '\SMW\Store' )
$store = $this->getMockBuilder( Store::class )
->disableOriginalConstructor()
->getMockForAbstractClass();

$instance = new IteratorFactory();

$this->assertInstanceOf(
RecursiveGroupMembersIterator::class,
$instance->newRecursiveGroupMembersIterator( array(), $store )
$instance->newRecursiveGroupMembersIterator( [], $store )
);
}

public function testCanConstructRecursiveIteratorIterator() {

$recursiveIterator = $this->getMockBuilder( '\RecursiveIterator' )
$recursiveIterator = $this->getMockBuilder( RecursiveIterator::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -71,7 +65,7 @@ public function testCanConstructChildlessRecursiveIterator() {

$this->assertInstanceOf(
ChildlessRecursiveIterator::class,
$instance->newChildlessRecursiveIterator( array() )
$instance->newChildlessRecursiveIterator( [] )
);
}

Expand Down
21 changes: 7 additions & 14 deletions tests/phpunit/Unit/PropertyRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,9 @@
*/
class PropertyRegistryTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {

$this->assertInstanceOf(
PropertyRegistry::class,
new PropertyRegistry()
);
}

public function testRegistry() {

$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' )
->disableOriginalConstructor()
->getMock();

$instance = new PropertyRegistry();
$instance->register( $propertyRegistry );
$instance->register( $this->newSmwPropertyRegistry() );

$this->assertSame(
SMW_NOTIFICATIONS_ON,
Expand All @@ -54,4 +41,10 @@ public function testRegistry() {
);
}

private function newSmwPropertyRegistry() {
return $this->getMockBuilder( \SMW\PropertyRegistry::class )
->disableOriginalConstructor()
->getMock();
}

}

0 comments on commit ee34ad9

Please sign in to comment.