mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-24 17:35:57 +03:00
Merge branch 'MLoureiro-107_cache_system_node_provider'
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);
|
||||
|
||||
@@ -18,15 +18,9 @@ class SystemNodeProviderTest extends TestCase
|
||||
->setMethods(['getIfconfig'])
|
||||
->getMock();
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
$provider->method('getIfconfig')
|
||||
->willReturn(<<<TXT
|
||||
vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
|
||||
ether 0a:00:27:00:00:00
|
||||
inet 192.168.60.1 netmask 0xffffff00 broadcast 192.168.60.255
|
||||
TXT
|
||||
);
|
||||
// @codingStandardsIgnoreEnd
|
||||
$provider->expects($this->once())
|
||||
->method('getIfconfig')
|
||||
->willReturn(PHP_EOL . 'AA-BB-CC-DD-EE-FF' . PHP_EOL);
|
||||
|
||||
$node = $provider->getNode();
|
||||
|
||||
@@ -84,6 +78,42 @@ TXT
|
||||
$this->assertEquals('AABBCCDDEEFF', $node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
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