> We lose useful coverage and waste valuable time on keeping tags > accurate through refactors (or worse, forget to do so). > > Tracking tiny per-method details wastes time in realizing (and > fixing) when people inevitably don't keep them in sync, and time > lost in finding uncovered code to write tests to realize it was > already covered but "not yet claimed". > > Given all used methods are de-facto and liberally claimed, and > that we keep the coverage limited to the subject class, this > maintains the spirit and intent. PHPUnit offers a more precise > tool when you need it (i.e. when testing legacy monster classes), > but for well-written code, the class-wide tag suffices. Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen Change-Id: I60151a0f5a811763fe326e92a18d3dcba8082761
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Html\FormOptions;
|
|
|
|
/**
|
|
* Copyright © 2011, Antoine Musso
|
|
*
|
|
* @author Antoine Musso
|
|
* @covers \MediaWiki\Html\FormOptions
|
|
*/
|
|
class FormOptionsTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider provideTypeDetection
|
|
*/
|
|
public function testGuessTypeDetection( $expectedType, $data ) {
|
|
$this->assertEquals(
|
|
$expectedType,
|
|
FormOptions::guessType( $data )
|
|
);
|
|
}
|
|
|
|
public static function provideTypeDetection() {
|
|
yield [ FormOptions::BOOL, true ];
|
|
yield [ FormOptions::BOOL, false ];
|
|
yield [ FormOptions::INT, 0 ];
|
|
yield [ FormOptions::INT, -5 ];
|
|
yield [ FormOptions::INT, 5 ];
|
|
yield [ FormOptions::INT, 0x0F ];
|
|
yield [ FormOptions::FLOAT, 0.0 ];
|
|
yield [ FormOptions::FLOAT, 1.5 ];
|
|
yield [ FormOptions::FLOAT, 1e3 ];
|
|
yield [ FormOptions::STRING, 'true' ];
|
|
yield [ FormOptions::STRING, 'false' ];
|
|
yield [ FormOptions::STRING, '5' ];
|
|
yield [ FormOptions::STRING, '0' ];
|
|
yield [ FormOptions::STRING, '1.5' ];
|
|
yield [ FormOptions::ARR, [ 'foo' ] ];
|
|
}
|
|
|
|
public function testGuessTypeOnNullThrowException() {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$this->expectExceptionMessage( 'Unsupported datatype' );
|
|
FormOptions::guessType( null );
|
|
}
|
|
}
|