Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/345787 )

Change subject: tests: Complete code coverage to 100%
......................................................................

tests: Complete code coverage to 100%

* Add missing coverage for addCidr() errors.
* Add missing coverage for match() errors.
* Add misssing covers for addCidr() overlap case.
* Add ignore for implicit case outside 'while'.
  https://github.com/sebastianbergmann/php-code-coverage/issues/513

Change-Id: Iacb24774ba037dcf73902dee12d62aad9fd89ed0
---
M phpunit.xml.dist
M src/IPSet.php
M tests/IPSetTest.php
3 files changed, 53 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/IPSet refs/changes/87/345787/1

diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index a23ec7d..c882a8a 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,6 +1,7 @@
 <phpunit colors="true"
        beStrictAboutTestsThatDoNotTestAnything="true"
-       beStrictAboutOutputDuringTests="true">
+       beStrictAboutOutputDuringTests="true"
+       convertErrorsToExceptions="true">
        <testsuites>
                <testsuite name="IPSet Tests">
                        <directory>./tests</directory>
diff --git a/src/IPSet.php b/src/IPSet.php
index d8a417f..912f602 100644
--- a/src/IPSet.php
+++ b/src/IPSet.php
@@ -185,8 +185,8 @@
                        }
                        $node =& $node[$index];
                        ++$curBit;
-               }
-       }
+               } // Unreachable outside 'while'
+       } // @codeCoverageIgnore
 
        /**
         * Match an IP address against the set
diff --git a/tests/IPSetTest.php b/tests/IPSetTest.php
index 9494776..6e946e9 100644
--- a/tests/IPSetTest.php
+++ b/tests/IPSetTest.php
@@ -258,6 +258,19 @@
                                        'ffff:ffff:ffff:ffff:ffff:ffff:fe02:0' 
=> false,
                                ),
                        ),
+                       'overlap' => array(
+                               array(
+                                       // @covers addCidr "already added a 
larger supernet"
+                                       '10.10.10.0/25',
+                                       '10.10.10.0/26',
+                               ),
+                               array(
+                                       '0.0.0.0' => false,
+                                       '10.10.10.0' => true,
+                                       '10.10.10.1' => true,
+                                       '255.255.255.255' => false,
+                               ),
+                       ),
                );
                foreach ( $testcases as $desc => $pairs ) {
                        $testcases[$desc] = array(
@@ -281,4 +294,40 @@
                        $this->assertEquals( $expected, $result, "Incorrect 
match() result for $ip in dataset $desc" );
                }
        }
+
+       public static function provideBadIPSets() {
+               return array(
+                       'bad mask ipv4' => array( '0.0.0.0/33' ),
+                       'bad mask ipv6' => array( '2620:0:861:1::/129' ),
+                       'inet fail' => array( '0af.0af' ),
+               );
+       }
+
+       /**
+        * @expectedException PHPUnit_Framework_Error_Warning
+        * @dataProvider provideBadIPSets
+        */
+       public function testAddCidrWarning( $cidr ) {
+               // 1. Ignoring errors to reach the otherwise unreachable 
'return'.
+               //    
https://github.com/sebastianbergmann/php-code-coverage/issues/513
+               $ipset = @new IPSet( array( $cidr ) );
+               // 2. Catches error as exception
+               $ipset = new IPSet( array( $cidr ) );
+       }
+
+       public static function provideBadMatches() {
+               return array(
+                       'inet fail' => array( '0af.0af', false ),
+               );
+       }
+
+       /**
+        * @expectedException PHPUnit_Framework_Error_Warning
+        * @dataProvider provideBadMatches
+        */
+       public function testMatchWarning( $ip, $expected ) {
+               $ipset = new IPSet( array() );
+               $this->assertEquals( $expected, @$ipset->match( $ip ) );
+               $ipset->match( $ip );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/345787
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iacb24774ba037dcf73902dee12d62aad9fd89ed0
Gerrit-PatchSet: 1
Gerrit-Project: IPSet
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to