We'd lose more useful coverage and spend more effort keeping these accurate through refactors etc than is worth the theoretically "bad" accidental coverage. Plus, even then we still very often forget to update these and waste time digging into seemingly uncovered code and either write duplicate test or discover they are already covered. Especially for private methods this can be a flawed endavour as we tend to trust tests when changing those and thus feel we shouldn't update tests, except it's riddled with private method mentions for coverage purposes (not in terms of actual called code). I think the best practice is to write good narrow unit tests, not to write bad tests and then hide their coverage. Generally that's what we do. Maybe these are useful when invoking a huge legacy class, but generally we don't need these I think, at least in the libs our team maintains. Change-Id: I4c7d826c7ec654b9efa20778c46c498784661f1c
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers SqlBagOStuff
|
|
* @group BagOStuff
|
|
*/
|
|
class SqlBagOStuffTest extends MediaWikiUnitTestCase {
|
|
public static function provideMakeKey() {
|
|
yield [ 'local', 'first', [ 'second', 'third' ],
|
|
'local:first:second:third' ];
|
|
yield [ 'local with spaces', 'first:first', [ 'second:second' ],
|
|
'local_with_spaces:first%3Afirst:second%3Asecond' ];
|
|
$longA = str_repeat( 'a', 128 );
|
|
$longB = str_repeat( 'b', 128 );
|
|
$longC = str_repeat( 'c', 128 );
|
|
yield [ 'global fairly long', 'first', [ $longA, $longB ],
|
|
'global_fairly_long:first:' . $longA . ':#73045f89f89b1604b62a6ae1ab4d4133' ];
|
|
yield [ 'global really long', 'first', [ $longA, $longB, $longC ],
|
|
'global_really_long:BagOStuff-long-key:##99f6adc828cfb6c892501f20153bd028' ];
|
|
}
|
|
|
|
/**
|
|
* @param string $keyspace
|
|
* @param string $class
|
|
* @param array $components
|
|
* @param string $expected
|
|
* @dataProvider SqlBagOStuffTest::provideMakeKey
|
|
*/
|
|
public function testMakeKey(
|
|
string $keyspace,
|
|
string $class,
|
|
array $components,
|
|
string $expected
|
|
) {
|
|
$cache = new SqlBagOStuff( [
|
|
'keyspace' => $keyspace,
|
|
'servers' => []
|
|
] );
|
|
$this->assertSame( $expected, $cache->makeKey( $class, ...$components ) );
|
|
}
|
|
}
|