From 6430a37adcb0f01ea736ce0372a5acd8a5d67aa0 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 27 Dec 2013 08:53:45 -0600 Subject: [PATCH] Refactor to move the network configuration capture to a separate method --- src/Rhumsaa/Uuid/Uuid.php | 28 +++++++++++++------- tests/Rhumsaa/Uuid/UuidBcTag1_1_2Test.php | 22 ---------------- tests/Rhumsaa/Uuid/UuidTest.php | 22 ---------------- tests/Rhumsaa/Uuid/functions.php | 32 ----------------------- 4 files changed, 18 insertions(+), 86 deletions(-) delete mode 100644 tests/Rhumsaa/Uuid/functions.php diff --git a/src/Rhumsaa/Uuid/Uuid.php b/src/Rhumsaa/Uuid/Uuid.php index 91451f8..ec4da8b 100644 --- a/src/Rhumsaa/Uuid/Uuid.php +++ b/src/Rhumsaa/Uuid/Uuid.php @@ -1060,6 +1060,23 @@ final class Uuid ); } + /** + * Returns the network interface configuration for the system + * + * @todo Needs evaluation and possibly modification to ensure this works + * well across multiple platforms. + * @codeCoverageIgnore + */ + protected static function getIfconfig() + { + // If we're on Windows, use ipconfig; otherwise use ifconfig + if (strtoupper(substr(php_uname('a'), 0, 3)) == 'WIN') { + return `ipconfig /all 2>&1`; + } + + return `ifconfig 2>&1`; + } + /** * Get the hardware address as a 48-bit positive integer. If all attempts to * obtain the hardware address fail, we choose a random 48-bit number with @@ -1069,25 +1086,16 @@ final class Uuid * returned. * * @return string - * @todo Needs evaluation and possibly modification to ensure this works - * well across multiple platforms. */ protected static function getNodeFromSystem() { - // If we're on Windows, use ipconfig; otherwise use ifconfig - if (strtoupper(substr(php_uname('a'), 0, 3)) == 'WIN') { - $ifconfig = `ipconfig /all 2>&1`; - } else { - $ifconfig = `ifconfig 2>&1`; - } - $node = null; $pattern = '/[^:]([0-9A-Fa-f]{2}([:-])[0-9A-Fa-f]{2}(\2[0-9A-Fa-f]{2}){4})[^:]/'; $matches = array(); // Search the ifconfig output for all MAC addresses and return // the first one found - if (preg_match_all($pattern, $ifconfig, $matches, PREG_PATTERN_ORDER)) { + if (preg_match_all($pattern, self::getIfconfig(), $matches, PREG_PATTERN_ORDER)) { $node = $matches[1][0]; $node = str_replace(':', '', $node); $node = str_replace('-', '', $node); diff --git a/tests/Rhumsaa/Uuid/UuidBcTag1_1_2Test.php b/tests/Rhumsaa/Uuid/UuidBcTag1_1_2Test.php index 87545ab..9b821b2 100644 --- a/tests/Rhumsaa/Uuid/UuidBcTag1_1_2Test.php +++ b/tests/Rhumsaa/Uuid/UuidBcTag1_1_2Test.php @@ -1,8 +1,6 @@ assertEquals('0901e600-0154-1000-9b21-0800200c9a66', sprintf('%s', $uuid)); } - /** - * This calls php_uname() in getNodeFromSystem. The first time it is - * called, it returns "WIN." Each additional times, it returns the - * normal system php_uname(). - * - * See the bottom of this test file to see where we are overriding - * php_uname() for the purpose of this test. - * - * @covers Rhumsaa\Uuid\Uuid::uuid1 - * @covers Rhumsaa\Uuid\Uuid::getNodeFromSystem - */ - public function testUuid1CoverageForWindows() - { - $uuid = Uuid::uuid1(); - $this->assertInstanceOf('\Rhumsaa\Uuid\Uuid', $uuid); - $this->assertInstanceOf('\DateTime', $uuid->getDateTime()); - $this->assertEquals(2, $uuid->getVariant()); - $this->assertEquals(1, $uuid->getVersion()); - } - /** * @covers Rhumsaa\Uuid\Uuid::uuid1 * @covers Rhumsaa\Uuid\Uuid::getNodeFromSystem diff --git a/tests/Rhumsaa/Uuid/UuidTest.php b/tests/Rhumsaa/Uuid/UuidTest.php index bbade41..1d78de5 100644 --- a/tests/Rhumsaa/Uuid/UuidTest.php +++ b/tests/Rhumsaa/Uuid/UuidTest.php @@ -1,8 +1,6 @@ assertEquals('0901e600-0154-1000-9b21-0800200c9a66', sprintf('%s', $uuid)); } - /** - * This calls php_uname() in getNodeFromSystem. The first time it is - * called, it returns "WIN." Each additional times, it returns the - * normal system php_uname(). - * - * See the bottom of this test file to see where we are overriding - * php_uname() for the purpose of this test. - * - * @covers Rhumsaa\Uuid\Uuid::uuid1 - * @covers Rhumsaa\Uuid\Uuid::getNodeFromSystem - */ - public function testUuid1CoverageForWindows() - { - $uuid = Uuid::uuid1(); - $this->assertInstanceOf('\Rhumsaa\Uuid\Uuid', $uuid); - $this->assertInstanceOf('\DateTime', $uuid->getDateTime()); - $this->assertEquals(2, $uuid->getVariant()); - $this->assertEquals(1, $uuid->getVersion()); - } - /** * @covers Rhumsaa\Uuid\Uuid::uuid1 * @covers Rhumsaa\Uuid\Uuid::getNodeFromSystem diff --git a/tests/Rhumsaa/Uuid/functions.php b/tests/Rhumsaa/Uuid/functions.php deleted file mode 100644 index 956a4f0..0000000 --- a/tests/Rhumsaa/Uuid/functions.php +++ /dev/null @@ -1,32 +0,0 @@ -