adapt testcases to also mock getsysfs, to get the old code path tested

This commit is contained in:
Robbert Müller
2017-10-18 10:33:54 +02:00
parent 10e022c05c
commit 3572bf8755
+37 -7
View File
@@ -15,9 +15,13 @@ class SystemNodeProviderTest extends TestCase
public function testGetNodeReturnsSystemNodeFromMacAddress()
{
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$provider->expects($this->once())
->method('getIfconfig')
->willReturn(PHP_EOL . 'AA-BB-CC-DD-EE-FF' . PHP_EOL);
@@ -50,11 +54,15 @@ class SystemNodeProviderTest extends TestCase
{
//Using a stub to provide data for the protected method that gets the node
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->method('getIfconfig')
->willReturn(PHP_EOL . $formatted . PHP_EOL);
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$node = $provider->getNode();
$this->assertEquals($expected, $node);
}
@@ -67,13 +75,17 @@ class SystemNodeProviderTest extends TestCase
{
//Using a stub to provide data for the protected method that gets the node
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->method('getIfconfig')
->willReturn(PHP_EOL . 'AA-BB-CC-DD-EE-FF' . PHP_EOL .
'00-11-22-33-44-55' . PHP_EOL .
'FF-11-EE-22-DD-33' . PHP_EOL);
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$node = $provider->getNode();
$this->assertEquals('AABBCCDDEEFF', $node);
}
@@ -85,13 +97,17 @@ class SystemNodeProviderTest extends TestCase
public function testGetNodeReturnsFalseWhenNodeIsNotFound()
{
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->expects($this->once())
->method('getIfconfig')
->willReturn('some string that does not match the mac address');
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$node = $provider->getNode();
$this->assertFalse($node);
}
@@ -103,13 +119,17 @@ class SystemNodeProviderTest extends TestCase
public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime()
{
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->expects($this->once())
->method('getIfconfig')
->willReturn('some string that does not match the mac address');
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$provider->getNode();
$provider->getNode();
}
@@ -137,7 +157,14 @@ class SystemNodeProviderTest extends TestCase
AspectMock::func('Ramsey\Uuid\Provider\Node', 'php_uname', $os);
$passthru = AspectMock::func('Ramsey\Uuid\Provider\Node', 'passthru', 'whatever');
$provider = new SystemNodeProvider();
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getsysfs'])
->getMock();
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$provider->getNode();
$passthru->verifyInvokedOnce([$command]);
}
@@ -168,11 +195,14 @@ class SystemNodeProviderTest extends TestCase
{
//Using a mock to verify the provider only gets the node from ifconfig one time
$provider = $this->getMockBuilder('Ramsey\Uuid\Provider\Node\SystemNodeProvider')
->setMethods(['getIfconfig'])
->setMethods(['getIfconfig','getsysfs'])
->getMock();
$provider->expects($this->once())
->method('getIfconfig')
->willReturn(PHP_EOL . 'AA-BB-CC-DD-EE-FF' . PHP_EOL);
$provider->expects($this->once())
->method('getsysfs')
->willReturn(false);
$provider->getNode();
$provider->getNode();
}