generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the "get the string which contains the info" and the "retrieve the info from the string" in order to add unit tests to the 2nd one.
- Loading branch information
Showing
2 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry CPUCounter Config package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fidry\CpuCounter\Test; | ||
|
||
use Fidry\CpuCounter\CpuInfoFinder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Fidry\CpuCounter\CpuInfoFinder | ||
* | ||
* @internal | ||
*/ | ||
final class CpuInfoFinderTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider cpuInfoProvider | ||
*/ | ||
public function test_it_can_count_the_number_of_cpu_cores( | ||
string $cpuInfo, | ||
?int $expected | ||
): void { | ||
$actual = CpuInfoFinder::countCpuCores($cpuInfo); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public static function cpuInfoProvider(): iterable | ||
{ | ||
yield 'empty' => [ | ||
<<<'EOF' | ||
|
||
EOF, | ||
null, | ||
]; | ||
|
||
// $ docker run --tty --rm --platform linux/amd64 alpine:3.14 cat /proc/cpuinfo | ||
yield 'example from an alpine Docker image' => [ | ||
<<<'EOF' | ||
processor : 0 | ||
BogoMIPS : 48.00 | ||
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint | ||
CPU implementer : 0x00 | ||
CPU architecture: 8 | ||
CPU variant : 0x0 | ||
CPU part : 0x000 | ||
CPU revision : 0 | ||
processor : 1 | ||
BogoMIPS : 48.00 | ||
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint | ||
CPU implementer : 0x00 | ||
CPU architecture: 8 | ||
CPU variant : 0x0 | ||
CPU part : 0x000 | ||
CPU revision : 0 | ||
processor : 2 | ||
BogoMIPS : 48.00 | ||
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint | ||
CPU implementer : 0x00 | ||
CPU architecture: 8 | ||
CPU variant : 0x0 | ||
CPU part : 0x000 | ||
CPU revision : 0 | ||
|
||
EOF, | ||
3, | ||
]; | ||
} | ||
} |