Skip to content

Commit

Permalink
Tests: data providers need to be static
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Feb 8, 2024
1 parent b0c0a82 commit 89f0d3c
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 32 deletions.
8 changes: 4 additions & 4 deletions tests/Unit/Crypt/AES/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function _checkEngine($aes)
*
* @return array
*/
public function continuousBufferCombos()
public static function continuousBufferCombos()
{
$modes = [
'ctr',
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testKeyPaddingAES()
*
* @return list<array{string, string, array}>
*/
public function continuousBufferBatteryCombos()
public static function continuousBufferBatteryCombos()
{
$modes = [
'ctr',
Expand Down Expand Up @@ -176,9 +176,9 @@ public function continuousBufferBatteryCombos()
/**
* @return array<array{string, string, array}>
*/
public function continuousBufferBatteryCombosWithoutSingleCombos()
public static function continuousBufferBatteryCombosWithoutSingleCombos()
{
return array_filter($this->continuousBufferBatteryCombos(), function (array $continuousBufferBatteryCombo) {
return array_filter(self::continuousBufferBatteryCombos(), function (array $continuousBufferBatteryCombo) {
return count($continuousBufferBatteryCombo[2]) > 1;
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Crypt/BlowfishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class BlowfishTest extends PhpseclibTestCase
{
public function engineVectors()
public static function engineVectors()
{
$engines = [
'PHP',
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Crypt/EC/CurveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class CurveTest extends PhpseclibTestCase
{
public function curves()
public static function curves()
{
$curves = [];
foreach (new \DirectoryIterator(__DIR__ . '/../../../../phpseclib/Crypt/EC/Curves/') as $file) {
Expand All @@ -38,7 +38,7 @@ public function curves()
return $curves;
}

public function allCurves()
public static function allCurves()
{
$curves = [];
foreach (new \DirectoryIterator(__DIR__ . '/../../../../phpseclib/Crypt/EC/Curves/') as $file) {
Expand All @@ -55,7 +55,7 @@ public function allCurves()
return $curves;
}

public function curvesWithOIDs()
public static function curvesWithOIDs()
{
$class = new \ReflectionClass('phpseclib3\Crypt\EC\Formats\Keys\PKCS8');

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Crypt/GCMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GCMTest extends PhpseclibTestCase
*
* @return array
*/
public function engine128Vectors()
public static function engine128Vectors()
{
$engines = [
'PHP',
Expand Down Expand Up @@ -131,7 +131,7 @@ public function test128Vectors($engine, $key, $plaintext, $nonce, $aad, $ciphert
*
* @return array
*/
public function engine256Vectors()
public static function engine256Vectors()
{
$engines = [
'PHP',
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Crypt/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function testGetLengthKnown($algorithm, $length)
$this->assertSame($hash->getLengthInBytes(), $length);
}

public function lengths()
public static function lengths()
{
return [
// known
Expand All @@ -439,7 +439,7 @@ public function lengths()
];
}

public function UMACs()
public static function UMACs()
{
return [
['', 'umac-32', '113145FB', "umac-32 and message of <empty>"],
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Crypt/RC2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

class RC2Test extends PhpseclibTestCase
{
public $engines = [
public static $engines = [
'PHP',
'Eval',
'mcrypt',
'OpenSSL',
];

public function engineVectors()
public static function engineVectors()
{
// tests from https://tools.ietf.org/html/rfc2268#page-8
$tests = [
Expand All @@ -37,7 +37,7 @@ public function engineVectors()

$result = [];

foreach ($this->engines as $engine) {
foreach (self::$engines as $engine) {
foreach ($tests as $test) {
$result[] = [$engine, $test[0], $test[1], $test[2], $test[3]];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Crypt/RC4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class RC4Test extends PhpseclibTestCase
{
public function engineVectors()
public static function engineVectors()
{
$engines = [
'PHP',
Expand Down
10 changes: 2 additions & 8 deletions tests/Unit/Crypt/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class RandomTest extends PhpseclibTestCase
{
public function stringLengthData()
public static function stringLengthData()
{
return array_map([$this, 'wrap'], [
return array_map(function($x) { return [$x]; }, [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 20, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 111, 128, 1000,
1024, 10000, 12345, 100000, 123456
Expand Down Expand Up @@ -50,10 +50,4 @@ public function testStringUniqueness()
$values[$rand] = true;
}
}

protected function wrap($x)
{
// array() is not a function, but $this->wrap() is.
return [$x];
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Crypt/Salsa20Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Salsa20Test extends PhpseclibTestCase
{
public function engineVectors()
public static function engineVectors()
{
$engines = [
'PHP',
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Crypt/TripleDESTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

class TripleDESTest extends PhpseclibTestCase
{
public $engines = [
public static $engines = [
'PHP',
'Eval',
'mcrypt',
'OpenSSL',
];

public function engineVectors()
public static function engineVectors()
{
// tests from http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf#page=273
$tests = [
Expand Down Expand Up @@ -94,7 +94,7 @@ public function engineVectors()

$result = [];

foreach ($this->engines as $engine) {
foreach (self::$engines as $engine) {
foreach ($tests as $test) {
$result[] = [$engine, $test[0], $test[1], $test[2]];
}
Expand All @@ -121,7 +121,7 @@ public function testVectors($engine, $key, $plaintext, $expected)
$this->assertEquals($result, $expected, "Failed asserting that $plaintext yielded expected output in $engine engine");
}

public function engineIVVectors()
public static function engineIVVectors()
{
$engines = [
'PHP',
Expand Down Expand Up @@ -184,7 +184,7 @@ public function testInnerChaining()
$des->setKey('abcdefghijklmnopqrstuvwx');
$des->setIV(str_repeat("\0", $des->getBlockLength() >> 3));

foreach ($this->engines as $engine) {
foreach (self::$engines as $engine) {
$des->setPreferredEngine($engine);
if (!$des->isValidEngine($engine)) {
self::markTestSkipped("Unable to initialize $engine engine");
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testCorrectSelfUseInLambda($key, $expectedCiphertext)
/**
* @return list<array{string, string}>
*/
public function provideForCorrectSelfUseInLambda()
public static function provideForCorrectSelfUseInLambda()
{
return [
['YWFhYWFhYWFhYWFhYWFhYWFhYWG9l9gm', 'fDSmC5bbLdx8NKYLltst3Hw0pguW2y3cfDSmC5bbLdxmhqEOIeS2ig=='],
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Net/SSH2UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class SSH2UnitTest extends PhpseclibTestCase
{
public function formatLogDataProvider()
public static function formatLogDataProvider()
{
return [
[
Expand Down

0 comments on commit 89f0d3c

Please sign in to comment.