Skip to content
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.5|^11.2"
"phpunit/phpunit": "^10.5|^11.2|^12.0"
},
"suggest": {
"ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).",
Expand Down
28 changes: 14 additions & 14 deletions tests/HashidsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Hashids\Hashids;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresFunction;
use PHPUnit\Framework\TestCase;

class HashidsTest extends TestCase
Expand Down Expand Up @@ -64,7 +66,7 @@ public static function alphabetProvider()
];
}

/** @dataProvider alphabetProvider */
#[DataProvider('alphabetProvider')]
public function testAlphabet($alphabets)
{
$numbers = [1, 2, 3];
Expand All @@ -88,7 +90,7 @@ public static function saltProvider()
];
}

/** @dataProvider saltProvider */
#[DataProvider('saltProvider')]
public function testSalt($salts)
{
$numbers = [1, 2, 3];
Expand All @@ -111,7 +113,7 @@ public static function minLengthProvider()
];
}

/** @dataProvider minLengthProvider */
#[DataProvider('minLengthProvider')]
public function testMinLength($lengths)
{
$numbers = [1, 2, 3];
Expand All @@ -133,7 +135,7 @@ public static function encodeTypesProvider()
];
}

/** @dataProvider encodeTypesProvider */
#[DataProvider('encodeTypesProvider')]
public function testEncodeTypes($params)
{
$numbers = [1, 2, 3];
Expand Down Expand Up @@ -169,7 +171,7 @@ public static function defaultParamsProvider()
];
}

/** @dataProvider defaultParamsProvider */
#[DataProvider('defaultParamsProvider')]
public function testDefaultParams($id, $numbers)
{
$hashids = new Hashids();
Expand Down Expand Up @@ -202,7 +204,7 @@ public static function customParamsProvider()
];
}

/** @dataProvider customParamsProvider */
#[DataProvider('customParamsProvider')]
public function testCustomParams($id, $numbers)
{
$minLength = 30;
Expand Down Expand Up @@ -232,7 +234,7 @@ public static function defaultParamsHexProvider()
];
}

/** @dataProvider defaultParamsHexProvider */
#[DataProvider('defaultParamsHexProvider')]
public function testDefaultParamsHex($id, $hex)
{
$hashids = new Hashids();
Expand All @@ -258,7 +260,7 @@ public static function customParamsHexProvider()
];
}

/** @dataProvider customParamsHexProvider */
#[DataProvider('customParamsHexProvider')]
public function testCustomParamsHex($id, $hex)
{
$minLength = 30;
Expand All @@ -283,15 +285,15 @@ public static function bigNumberDataProvider()
];
}

/** @dataProvider bigNumberDataProvider */
#[DataProvider('bigNumberDataProvider')]
public function testBigNumberEncode($number, $hash)
{
$hashids = new Hashids('this is my salt');
$encoded = $hashids->encode($number);
$this->assertEquals($hash, $encoded);
}

/** @dataProvider bigNumberDataProvider */
#[DataProvider('bigNumberDataProvider')]
public function testBigNumberDecode($number, $hash)
{
$hashids = new Hashids('this is my salt');
Expand All @@ -309,16 +311,14 @@ public static function jsHashidsDataProvider()
];
}

/** @dataProvider jsHashidsDataProvider */
#[DataProvider('jsHashidsDataProvider')]
public function testJsHashidsCompatible($salt, $minHashLength, $alphabet, $numbers, $hash)
{
$hashids = new Hashids($salt, $minHashLength, $alphabet);
$this->assertEquals($hash, $hashids->encode($numbers));
}

/**
* @requires function bcscale
*/
#[RequiresFunction('bcscale')]
public function testBehaviourForDifferentBCMathAccuracy()
{
bcscale(2);
Expand Down
15 changes: 8 additions & 7 deletions tests/MathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hashids\Math\BCMath;
use Hashids\Math\Gmp;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use RuntimeException;

Expand All @@ -36,45 +37,45 @@ public static function mathProvider()
throw new RuntimeException('Missing math extension for Hashids, install either bcmath or gmp.');
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testAdd($math)
{
$this->assertEquals($math->get(3), $math->add(1, 2));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testMultiply($math)
{
$this->assertEquals($math->get(12), $math->multiply(2, 6));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testDivide($math)
{
$this->assertEquals($math->get(2), $math->divide(4, 2));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testGreaterThan($math)
{
$this->assertTrue($math->greaterThan('18446744073709551615', '9223372036854775807'));
$this->assertFalse($math->greaterThan('9223372036854775807', '18446744073709551615'));
$this->assertFalse($math->greaterThan('9223372036854775807', '9223372036854775807'));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testMod($math)
{
$this->assertEquals($math->get(15), $math->mod('18446744073709551615', '100'));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testIntval($math)
{
$this->assertSame(9223372036854775807, $math->intval('9223372036854775807'));
}

/** @dataProvider mathProvider */
#[DataProvider('mathProvider')]
public function testStrval($math)
{
$this->assertSame('18446744073709551615', $math->strval($math->add('0', '18446744073709551615')));
Expand Down