Merge branch '107_cache_system_node_provider' of https://github.com/MLoureiro/uuid into MLoureiro-107_cache_system_node_provider

This commit is contained in:
Ben Ramsey
2016-06-24 23:58:19 +02:00
2 changed files with 30 additions and 1 deletions
+2 -1
View File
@@ -25,7 +25,7 @@ class SystemNodeProvider implements NodeProviderInterface
/**
* Returns the system node ID
*
* @return string System node ID as a hexadecimal string
* @return string|false System node ID as a hexadecimal string, or false if it is not found
*/
public function getNode()
{
@@ -40,6 +40,7 @@ class SystemNodeProvider implements NodeProviderInterface
// Search the ifconfig output for all MAC addresses and return
// the first one found
$node = false;
if (preg_match_all($pattern, $this->getIfconfig(), $matches, PREG_PATTERN_ORDER)) {
$node = $matches[1][0];
$node = str_replace([':', '-'], '', $node);
@@ -84,6 +84,34 @@ TXT
$this->assertEquals('AABBCCDDEEFF', $node);
}
public function testGetNodeReturnsFalseWhenNodeIsNotFound()
{
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->getMock();
$provider->expects($this->once())
->method('getIfconfig')
->willReturn('some string that does not match the mac address');
$node = $provider->getNode();
$this->assertFalse($node);
}
public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime()
{
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->getMock();
$provider->expects($this->once())
->method('getIfconfig')
->willReturn('some string that does not match the mac address');
$provider->getNode();
$provider->getNode();
}
public function osCommandDataProvider()
{
return [