Page MenuHomePhabricator

Add basic unit tests for the Tallier class [M]
Closed, ResolvedPublic

Description

Add TallierTest class, which should extend MediaWikiUnitTestCase.

The source file should be located in SecurePoll/tests/phpunit/unit and namespaced to MediaWiki\Extensions\SecurePoll\Test\Unit.

This will involve some judgement as to what is worth testing, and what can be tested in a unit test.

We should consider whether it would be helpful to make this test extensible, as a base class for tests for the Tallier subclasses. If extra work is required to do this, we can file it as a follow-up.

Event Timeline

ARamirez_WMF renamed this task from Add basic unit tests for the Tallier class to Add basic unit tests for the Tallier class [M].May 5 2021, 4:31 PM

Change 686385 had a related patch set uploaded (by Tchanders; author: Tchanders):

[mediawiki/extensions/SecurePoll@master] Add tests for abstract Tallier class

https://gerrit.wikimedia.org/r/686385

We should consider whether it would be helpful to make this test extensible, as a base class for tests for the Tallier subclasses. If extra work is required to do this, we can file it as a follow-up.

I thought at first that it could be useful to have a base class that with a getTallier method that the sublass tests could pass a type to, along the lines of:

public function getTallier( $type ) {
	// Tallier constructor requires getOptions to return iterable
	$question = $this->createMock( Question::class );
	$question->method( 'getOptions' )
		->willReturn( [] );

	return Tallier::factory(
		$this->createMock( RequestContext::class ),
		$type,
		$this->createMock( ElectionTallier::class ),
		$question
	);
}

Note that the mocked Question requires some customization because the constructor treats the return value of getOptions as an iterable.

However, some subclass constructors also require customization of the mock constructor params, e.g. HistogramRangeTallier::__construct needs the passed-in Question to have min/max score properties.

I think this makes it not worth having a base class for these unit tests.

Change 686385 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] Add tests for abstract Tallier class

https://gerrit.wikimedia.org/r/686385