Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary code for NProcFinder #93

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
];
}
}