[MediaWiki-commits] [Gerrit] cdb[master]: tests: Improve code coverage

2017-04-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348662 )

Change subject: tests: Improve code coverage
..


tests: Improve code coverage

* Update PHPUnit to latest 4.x.
* Remove 5.3.3 from Travis CI matrix.
* Add 'composer run cover' command.
* Call parent::tearDown() after local logic, not before.
* Add missing @covers.
* Remove @group (leftover from MediaWiki).

* Add tests for
  - Reader::open()
  - Writer::open()
  - Writer::__destruct()
  - Reader\DBA::__construct() - file open error
  - Reader\PHP::__construct() - file open error
  - Reader\PHP::__construct() - file size error
  - Reader\DBA::get() - key not found
  - Reader\PHP::get() - key not found
  - Writer\PHP::finish() - empty case (0 keys)
Also fixed array_fill warning.
* Ignore coverage:
  - Reader::haveExtension() - mocked environment check

Change-Id: I42a8adf747c7baa3675c97e43b5f642f66b14e66
---
M .travis.yml
M composer.json
M phpunit.xml.dist
M src/Reader.php
M src/Writer.php
M src/Writer/PHP.php
M tests/CdbTest.php
A tests/Reader/DBATest.php
M tests/Reader/HashTest.php
A tests/Reader/PHPTest.php
10 files changed, 131 insertions(+), 21 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified
  Jforrester: Looks good to me, but someone else must approve



diff --git a/.travis.yml b/.travis.yml
index 5b4fcc5..19a0ad5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
 language: php
 php:
-  - "5.3.3"
   - "5.3"
   - "5.4"
   - "5.5"
@@ -10,8 +9,6 @@
 env:
   global:
 - COMPOSER_DISABLE_XDEBUG_WARN=1
-before_install:
-  - if [ "$TRAVIS_PHP_VERSION" = "5.3.3" ]; then composer config disable-tls 
true; composer config secure-http false; fi
 install:
   - composer install
 script:
diff --git a/composer.json b/composer.json
index bf54635..2c17e96 100644
--- a/composer.json
+++ b/composer.json
@@ -30,14 +30,15 @@
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9",
-   "phpunit/phpunit": "4.6.*",
+   "phpunit/phpunit": "^4.8",
"mediawiki/mediawiki-codesniffer": "0.5.0"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor",
"phpunit $PHPUNIT_ARGS",
-   "phpcs -p"
-   ]
+   "phpcs -p -s"
+   ],
+   "cover": "phpunit --coverage-html coverage"
}
 }
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 8cffd80..d4c95c0 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,6 +1,7 @@
 
+   beStrictAboutOutputDuringTests="true"
+   verbose="true">


./tests
diff --git a/src/Reader.php b/src/Reader.php
index b1aaa02..565676f 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -38,7 +38,6 @@
 * Open a file and return a subclass instance
 *
 * @param string $fileName
-*
 * @return Reader
 */
public static function open( $fileName ) {
@@ -51,6 +50,7 @@
 * Returns true if the native extension is available
 *
 * @return bool
+* @codeCoverageIgnore
 */
public static function haveExtension() {
if ( !function_exists( 'dba_handlers' ) ) {
diff --git a/src/Writer.php b/src/Writer.php
index 5321604..9e4e24d 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -51,7 +51,6 @@
 * The user must have write access to the directory, for temporary file 
creation.
 *
 * @param string $fileName
-*
 * @return Writer
 */
public static function open( $fileName ) {
diff --git a/src/Writer/PHP.php b/src/Writer/PHP.php
index 4676b5e..2fd5405 100644
--- a/src/Writer/PHP.php
+++ b/src/Writer/PHP.php
@@ -173,7 +173,12 @@
// Excessively clever and indulgent code to simultaneously fill 
$packedTables
// with the packed hashtables, and adjust the elements of 
$starts
// to actually point to the starts instead of the ends.
-   $packedTables = array_fill( 0, $this->numentries, false );
+   if ( $this->numentries > 0 ) {
+   $packedTables = array_fill( 0, $this->numentries, false 
);
+   } else {
+   // array_fill(): Number of elements must be positive
+   $packedTables = array();
+   }
foreach ( $this->hplist as $item ) {
$packedTables[--$starts[255 & $item['h']]] = $item;
}
diff --git a/tests/CdbTest.php b/tests/CdbTest.php
index 6ef4655..2ed655e 100644
--- a/tests/CdbTest.php
+++ b/tests/CdbTest.php
@@ -7,9 +7,6 @@
 
 /**
  * Test the CDB reader/writer
- * @group Cdb
- * @covers Cdb\Writer\PHP
- * @covers Cdb\Writer\DBA
  */
 class 

[MediaWiki-commits] [Gerrit] cdb[master]: tests: Improve code coverage

2017-04-17 Thread Krinkle (Code Review)
Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/348662 )

Change subject: tests: Improve code coverage
..

tests: Improve code coverage

* Update PHPUnit to latest 4.x.
* Remove 5.3.3 from Travis CI matrix.
* Add 'composer run cover' command.
* Call parent::tearDown() after local logic, not before.
* Add missing @covers.
* Remove @group (leftover from MediaWiki).

* Add tests for
  - Reader::open()
  - Writer::open()
  - Reader\DBA::__construct() - file open error
  - Reader\PHP::__construct() - file open error
  - Reader\PHP::__construct() - file size error
  - Reader\DBA::get() - key not found
  - Reader\PHP::get() - key not found
  - Writer::__destruct()
* Ignore coverage:
  - Reader::haveExtension() - mocked environment check

Change-Id: I42a8adf747c7baa3675c97e43b5f642f66b14e66
---
M .travis.yml
M composer.json
M phpunit.xml.dist
M src/Reader.php
M src/Writer.php
M tests/CdbTest.php
A tests/Reader/DBATest.php
M tests/Reader/HashTest.php
A tests/Reader/PHPTest.php
9 files changed, 108 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/cdb refs/changes/62/348662/1

diff --git a/.travis.yml b/.travis.yml
index 5b4fcc5..19a0ad5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
 language: php
 php:
-  - "5.3.3"
   - "5.3"
   - "5.4"
   - "5.5"
@@ -10,8 +9,6 @@
 env:
   global:
 - COMPOSER_DISABLE_XDEBUG_WARN=1
-before_install:
-  - if [ "$TRAVIS_PHP_VERSION" = "5.3.3" ]; then composer config disable-tls 
true; composer config secure-http false; fi
 install:
   - composer install
 script:
diff --git a/composer.json b/composer.json
index bf54635..2c17e96 100644
--- a/composer.json
+++ b/composer.json
@@ -30,14 +30,15 @@
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9",
-   "phpunit/phpunit": "4.6.*",
+   "phpunit/phpunit": "^4.8",
"mediawiki/mediawiki-codesniffer": "0.5.0"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor",
"phpunit $PHPUNIT_ARGS",
-   "phpcs -p"
-   ]
+   "phpcs -p -s"
+   ],
+   "cover": "phpunit --coverage-html coverage"
}
 }
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 8cffd80..d4c95c0 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,6 +1,7 @@
 
+   beStrictAboutOutputDuringTests="true"
+   verbose="true">


./tests
diff --git a/src/Reader.php b/src/Reader.php
index b1aaa02..565676f 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -38,7 +38,6 @@
 * Open a file and return a subclass instance
 *
 * @param string $fileName
-*
 * @return Reader
 */
public static function open( $fileName ) {
@@ -51,6 +50,7 @@
 * Returns true if the native extension is available
 *
 * @return bool
+* @codeCoverageIgnore
 */
public static function haveExtension() {
if ( !function_exists( 'dba_handlers' ) ) {
diff --git a/src/Writer.php b/src/Writer.php
index 5321604..9e4e24d 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -51,7 +51,6 @@
 * The user must have write access to the directory, for temporary file 
creation.
 *
 * @param string $fileName
-*
 * @return Writer
 */
public static function open( $fileName ) {
diff --git a/tests/CdbTest.php b/tests/CdbTest.php
index 6ef4655..1643b2e 100644
--- a/tests/CdbTest.php
+++ b/tests/CdbTest.php
@@ -7,9 +7,6 @@
 
 /**
  * Test the CDB reader/writer
- * @group Cdb
- * @covers Cdb\Writer\PHP
- * @covers Cdb\Writer\DBA
  */
 class CdbTest extends \PHPUnit_Framework_TestCase {
/** @var string */
@@ -29,9 +26,9 @@
}
 
protected function tearDown() {
-   parent::tearDown();
unlink( $this->phpCdbFile );
unlink( $this->dbaCdbFile );
+   parent::tearDown();
}
 
/**
@@ -48,11 +45,43 @@
return $s;
}
 
+   private function cdbAssert( $msg, $key, $expected, $actual ) {
+   $this->assertSame(
+   $expected,
+   $actual,
+   $msg . ', k=' . bin2hex( $key )
+   );
+   }
+
/**
+* @covers Cdb\Reader::open
+*/
+   public function testReaderOpen() {
+   $this->assertInstanceOf(
+   Reader::class,
+   Reader::open( $this->phpCdbFile )
+   );
+   }
+
+   /**
+* @covers Cdb\Writer::open
+*/
+   public function testWriterOpen() {
+   $this->assertInstanceOf(
+   Writer::class,
+