mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-17 12:23:57 +00:00
remove the MightNotMakeAssertions shim
use expectNotToPerformAssertions() instead
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
trait MightNotMakeAssertions
|
||||
{
|
||||
/**
|
||||
* This is a shim to support PHPUnit for php 5.6 and 7.0.
|
||||
*
|
||||
* It has to be named something that doesn't collide with existing
|
||||
* TestCase methods as we can't support PHP return types right now
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function noAssertionsMade()
|
||||
{
|
||||
foreach (class_parents($this) as $parent) {
|
||||
if (method_exists($parent, 'expectNotToPerformAssertions')) {
|
||||
parent::expectNotToPerformAssertions();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,15 @@ namespace Tests\Providers\Rng;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RobThree\Auth\Providers\Rng\CSRNGProvider;
|
||||
use Tests\MightNotMakeAssertions;
|
||||
|
||||
class CSRNGProviderTest extends TestCase
|
||||
{
|
||||
use NeedsRngLengths;
|
||||
use MightNotMakeAssertions;
|
||||
|
||||
/**
|
||||
* @requires function random_bytes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCSRNGProvidersReturnExpectedNumberOfBytes()
|
||||
public function testCSRNGProvidersReturnExpectedNumberOfBytes(): void
|
||||
{
|
||||
if (function_exists('random_bytes')) {
|
||||
$rng = new CSRNGProvider();
|
||||
@@ -27,7 +23,7 @@ class CSRNGProviderTest extends TestCase
|
||||
}
|
||||
$this->assertTrue($rng->isCryptographicallySecure());
|
||||
} else {
|
||||
$this->noAssertionsMade();
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,21 +8,17 @@ use PHPUnit\Framework\TestCase;
|
||||
use RobThree\Auth\Algorithm;
|
||||
use RobThree\Auth\TwoFactorAuth;
|
||||
use RobThree\Auth\TwoFactorAuthException;
|
||||
use Tests\MightNotMakeAssertions;
|
||||
|
||||
class ITimeProviderTest extends TestCase
|
||||
{
|
||||
use MightNotMakeAssertions;
|
||||
|
||||
public function testEnsureCorrectTimeDoesNotThrowForCorrectTime(): void
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
$tpr1 = new TestTimeProvider(123);
|
||||
$tpr2 = new TestTimeProvider(128);
|
||||
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, Algorithm::Sha1, null, null, $tpr1);
|
||||
$tfa->ensureCorrectTime(array($tpr2)); // 128 - 123 = 5 => within default leniency
|
||||
|
||||
$this->noAssertionsMade();
|
||||
}
|
||||
|
||||
public function testEnsureCorrectTimeThrowsOnIncorrectTime(): void
|
||||
@@ -39,9 +35,9 @@ class ITimeProviderTest extends TestCase
|
||||
|
||||
public function testEnsureDefaultTimeProviderReturnsCorrectTime(): void
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, Algorithm::Sha1);
|
||||
$tfa->ensureCorrectTime(array(new TestTimeProvider(time())), 1); // Use a leniency of 1, should the time change between both time() calls
|
||||
|
||||
$this->noAssertionsMade();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ use RobThree\Auth\TwoFactorAuthException;
|
||||
|
||||
class TwoFactorAuthTest extends TestCase
|
||||
{
|
||||
use MightNotMakeAssertions;
|
||||
|
||||
public function testConstructorThrowsOnInvalidDigits(): void
|
||||
{
|
||||
$this->expectException(TwoFactorAuthException::class);
|
||||
@@ -45,7 +43,7 @@ class TwoFactorAuthTest extends TestCase
|
||||
//new \RobThree\Auth\Providers\Time\HttpTimeProvider('https://github.com'), // github.com will periodically report times that are off by more than 5 sec
|
||||
new \RobThree\Auth\Providers\Time\HttpTimeProvider('https://yahoo.com'),
|
||||
));
|
||||
$this->noAssertionsMade();
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
public function testVerifyCodeWorksCorrectly(): void
|
||||
|
||||
Reference in New Issue
Block a user