Clean-up tests and use PHPStan max level for tests

This commit is contained in:
Ben Ramsey
2019-12-15 00:44:18 -06:00
parent 650cb9f545
commit 81f0f9a9b4
32 changed files with 487 additions and 591 deletions
+33 -30
View File
@@ -3,10 +3,10 @@
namespace Ramsey\Uuid\Test\Provider\Node;
use AspectMock\Proxy\FuncProxy;
use AspectMock\Test as AspectMock;
use InvalidArgumentException;
use Ramsey\Uuid\Provider\Node\SystemNodeProvider;
use Ramsey\Uuid\Test\TestCase;
use AspectMock\Test as AspectMock;
/**
* Tests for the SystemNodeProvider class
@@ -44,7 +44,9 @@ class SystemNodeProviderTest extends TestCase
const PROVIDER_NAMESPACE = 'Ramsey\\Uuid\\Provider\\Node';
/** @var FuncProxy[] */
/**
* @var FuncProxy[]
*/
private $functionProxies = [];
/**
@@ -56,7 +58,7 @@ class SystemNodeProviderTest extends TestCase
* @param string $netstatOutput
* @param string $expected
*/
public function testGetNodeReturnsSystemNodeFromMacAddress($netstatOutput, $expected)
public function testGetNodeReturnsSystemNodeFromMacAddress($netstatOutput, $expected): void
{
/*/ Arrange mocks for native functions /*/
$this->arrangeMockFunctions(
@@ -93,7 +95,7 @@ class SystemNodeProviderTest extends TestCase
*
* @param string $netstatOutput
*/
public function testGetNodeShouldNotReturnsSystemNodeForInvalidMacAddress($netstatOutput)
public function testGetNodeShouldNotReturnsSystemNodeForInvalidMacAddress($netstatOutput): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -125,7 +127,7 @@ class SystemNodeProviderTest extends TestCase
* @param string $formatted
* @param string $expected
*/
public function testGetNodeReturnsNodeStrippedOfNotationalFormatting($formatted, $expected)
public function testGetNodeReturnsNodeStrippedOfNotationalFormatting($formatted, $expected): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -156,7 +158,7 @@ class SystemNodeProviderTest extends TestCase
*
* @param string $formatted
*/
public function testGetNodeDoesNotAcceptIncorrectNotationalFormatting($formatted)
public function testGetNodeDoesNotAcceptIncorrectNotationalFormatting($formatted): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -183,7 +185,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testGetNodeReturnsFirstMacAddressFound()
public function testGetNodeReturnsFirstMacAddressFound(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -210,7 +212,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testGetNodeReturnsFalseWhenNodeIsNotFound()
public function testGetNodeReturnsFalseWhenNodeIsNotFound(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -237,7 +239,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime()
public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -270,7 +272,7 @@ class SystemNodeProviderTest extends TestCase
* @param string $os
* @param string $command
*/
public function testGetNodeGetsNetworkInterfaceConfig($os, $command)
public function testGetNodeGetsNetworkInterfaceConfig($os, $command): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -311,7 +313,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testGetNodeReturnsSameNodeUponSubsequentCalls()
public function testGetNodeReturnsSameNodeUponSubsequentCalls(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -339,7 +341,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testSubsequentCallsToGetNodeDoNotRecallIfconfig()
public function testSubsequentCallsToGetNodeDoNotRecallIfconfig(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -372,7 +374,7 @@ class SystemNodeProviderTest extends TestCase
* @param string $os
* @param string $command
*/
public function testCallGetsysfsOnLinux($os, $command)
public function testCallGetsysfsOnLinux($os, $command): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -425,7 +427,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testCallGetsysfsOnLinuxWhenGlobReturnsFalse()
public function testCallGetsysfsOnLinuxWhenGlobReturnsFalse(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -458,7 +460,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testCallGetsysfsOnLinuxWhenGlobReturnsEmptyArray()
public function testCallGetsysfsOnLinuxWhenGlobReturnsEmptyArray(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -491,7 +493,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testCallGetsysfsOnLinuxWhenGlobFilesAreNotReadable()
public function testCallGetsysfsOnLinuxWhenGlobFilesAreNotReadable(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -527,7 +529,7 @@ class SystemNodeProviderTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testGetNodeReturnsFalseWhenPassthruIsDisabled()
public function testGetNodeReturnsFalseWhenPassthruIsDisabled(): void
{
/*/ Arrange /*/
$this->arrangeMockFunctions(
@@ -562,6 +564,7 @@ class SystemNodeProviderTest extends TestCase
* @param callback|mixed|null $passthruBody
* @param callback|mixed|null $constantBody
* @param callback|mixed|null $iniGetDisableFunctionsBody
* @param callback|mixed|null $isReadableBody
*/
private function arrangeMockFunctions(
$fileGetContentsBody,
@@ -570,7 +573,7 @@ class SystemNodeProviderTest extends TestCase
$constantBody,
$iniGetDisableFunctionsBody,
$isReadableBody = true
) {
): void {
$mockFunction = [
self::MOCK_FILE_GET_CONTENTS => $fileGetContentsBody,
self::MOCK_GLOB => $globBody,
@@ -590,12 +593,12 @@ class SystemNodeProviderTest extends TestCase
*
* Provide a NULL to assert a function is never called.
*
* @param array|null $fileGetContentsAssert
* @param array|null $globBodyAssert
* @param array|null $passthruBodyAssert
* @param array|null $constantBodyAssert
* @param array|null $iniGetDisableFunctionsAssert
* @param array|null $isReadableAssert
* @param string[]|array[]|null $fileGetContentsAssert
* @param string[]|array[]|null $globBodyAssert
* @param string[]|array[]|null $passthruBodyAssert
* @param string[]|array[]|null $constantBodyAssert
* @param string[]|array[]|null $iniGetDisableFunctionsAssert
* @param string[]|array[]|null $isReadableAssert
*/
private function assertMockFunctions(
$fileGetContentsAssert,
@@ -604,7 +607,7 @@ class SystemNodeProviderTest extends TestCase
$constantBodyAssert,
$iniGetDisableFunctionsAssert,
$isReadableAssert = null
) {
): void {
$mockFunctionAsserts = [
self::MOCK_FILE_GET_CONTENTS => $fileGetContentsAssert,
self::MOCK_GLOB => $globBodyAssert,
@@ -639,7 +642,7 @@ class SystemNodeProviderTest extends TestCase
*
* @return array[]
*/
public function provideCommandPerOs()
public function provideCommandPerOs(): array
{
return [
'windows' => ['Windows', 'ipconfig /all 2>&1'],
@@ -656,7 +659,7 @@ class SystemNodeProviderTest extends TestCase
*
* @return array[]
*/
public function provideInvalidNetStatOutput()
public function provideInvalidNetStatOutput(): array
{
return [
'Not an octal value' => [
@@ -681,7 +684,7 @@ class SystemNodeProviderTest extends TestCase
*
* @return array[]
*/
public function provideInvalidNotationalFormats()
public function provideInvalidNotationalFormats(): array
{
return [
['01:23-45-67-89-ab'],
@@ -700,7 +703,7 @@ class SystemNodeProviderTest extends TestCase
*
* @return array[]
*/
public function provideNotationalFormats()
public function provideNotationalFormats(): array
{
return [
['01-23-45-67-89-ab', '0123456789ab'],
@@ -713,7 +716,7 @@ class SystemNodeProviderTest extends TestCase
*
* @return array[]
*/
public function provideValidNetStatOutput()
public function provideValidNetStatOutput(): array
{
return [
/*/ Full output of related command /*/