Execute system call only once even if the node is not found

This commit is contained in:
Marcos
2016-06-23 20:57:21 +02:00
parent b4fe3b7387
commit 5dbd993b4b
2 changed files with 16 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);
@@ -71,6 +71,20 @@ class SystemNodeProviderTest extends TestCase
$this->assertEquals('AABBCCDDEEFF', $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 [