Skip to content

Commit

Permalink
Remove unnecessary code for NProcFinder (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 16, 2022
1 parent a29d68f commit f6b95e1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
13 changes: 0 additions & 13 deletions src/Finder/NProcFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

namespace Fidry\CpuCoreCounter\Finder;

use function filter_var;
use function is_int;
use function sprintf;
use const FILTER_VALIDATE_INT;

/**
* The number of (logical) cores.
Expand Down Expand Up @@ -51,14 +48,4 @@ protected function getCommand(): string
{
return 'nproc'.($this->all ? ' --all' : '').' 2>&1';
}

/**
* @return positive-int|null
*/
public static function countCpuCores(string $nproc): ?int
{
$cpuCount = filter_var($nproc, FILTER_VALIDATE_INT);

return is_int($cpuCount) && $cpuCount > 0 ? $cpuCount : null;
}
}
48 changes: 1 addition & 47 deletions tests/Finder/NProcFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function finderProvider(): iterable
}

/**
* @dataProvider nprocProvider
* @dataProvider \Fidry\CpuCoreCounter\Test\Finder\ProcOpenBasedFinderTestCase::processResultProvider
*/
public function test_it_can_count_the_number_of_cpu_cores(
string $nproc,
Expand All @@ -65,50 +65,4 @@ public function test_it_can_count_the_number_of_cpu_cores(

self::assertSame($expected, $actual);
}

public static function nprocProvider(): iterable
{
yield 'empty' => [
<<<'EOF'

EOF
,
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF
,
null,
];

// $ docker run --tty --rm --platform linux/amd64 alpine:3.14 nproc --all
yield 'example from an alpine Docker image' => [
<<<'EOF'
3

EOF
,
3,
];
yield 'example with extra spaces' => [
<<<'EOF'
3

EOF
,
3,
];

yield 'no processor' => [
<<<'EOF'
0

EOF
,
null,
];
}
}

0 comments on commit f6b95e1

Please sign in to comment.