Files
php-uuid/tests/Converter/Number/BigNumberConverterTest.php
T
Brandon Morrison aa18ce15d5 Fix pure annotations (#605)
Coming from https://github.com/ramsey/uuid/pull/603, this is an attempt
to fix the errors raised by the current phpstan settings.

I went through each of the errors raised by phpstan with the following
approach.

- If a method is part of an `@immutable` class, we can consider it pure,
  assuming it only affects internal variables.
- If a potentially pure method is calling a class's method that is only
  swapped during testing (and not during normal usage), then we can
  consider the calling method pure.
- If a class is marked deprecated, don't bother with attempting to mark
  it pure or immutable.
2025-06-25 08:24:36 -05:00

52 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Ramsey\Uuid\Test\Converter\Number;
use Ramsey\Uuid\Converter\Number\BigNumberConverter;
use Ramsey\Uuid\Exception\InvalidArgumentException;
use Ramsey\Uuid\Test\TestCase;
class BigNumberConverterTest extends TestCase
{
public function testFromHexThrowsExceptionWhenStringDoesNotContainOnlyHexadecimalCharacters(): void
{
$converter = new BigNumberConverter();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"." is not a valid character in base 16');
/** @phpstan-ignore method.resultUnused */
$converter->fromHex('123.34');
}
public function testToHexThrowsExceptionWhenStringDoesNotContainOnlyDigits(): void
{
$converter = new BigNumberConverter();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'Value must be a signed integer or a string containing only digits '
. '0-9 and, optionally, a sign (+ or -)'
);
/** @phpstan-ignore method.resultUnused */
$converter->toHex('123.34');
}
public function testFromHex(): void
{
$converter = new BigNumberConverter();
$this->assertSame('65535', $converter->fromHex('ffff'));
}
public function testToHex(): void
{
$converter = new BigNumberConverter();
$this->assertSame('ffff', $converter->toHex('65535'));
}
}