mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Execute system call only once even if the node is not found
This commit is contained in:
@@ -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 [
|
||||
|
||||
Reference in New Issue
Block a user