Skip to content

Commit

Permalink
fix: all test
Browse files Browse the repository at this point in the history
  • Loading branch information
datamweb committed Nov 15, 2023
1 parent 6054e56 commit 9c36b02
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
11 changes: 11 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
'count' => 1,
'path' => __DIR__ . '/tests/_support/Config/Registrar.php',
];
$ignoreErrors[] = [
'message' => '#^Property Tests\\\\Validation\\\\DEAValidatorTest\\:\\:\\$config type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Validation/DEAValidatorTest.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$config of class CodeIgniter\\\\Validation\\\\Validation constructor expects Config\\\\Validation, stdClass given\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Validation/DEAValidatorTest.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@

TypedPropertyFromAssignsRector::class => [
__DIR__ . '/src/Models/LogsTempEmailModel.php',
__DIR__ . '/tests/Validation/DEAValidatorTest.php',
__DIR__ . '/src/Commands/DEARulePublish.php',
__DIR__ . '/tests/_support/Config/Registrar.php',
],
Expand Down
74 changes: 39 additions & 35 deletions tests/Validation/DEAValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Validation\ValidationInterface;
use CodeIgniter\Validation\Validation;
use Config\Services;
use Datamweb\CodeIgniterDEARule\Config\DEARule;
use Datamweb\CodeIgniterDEARule\Validation\DEAValidator;

/**
* @internal
Expand All @@ -27,19 +28,22 @@ final class DEAValidatorTest extends CIUnitTestCase
{
use DatabaseTestTrait;

private ValidationInterface $validation;
private Validation $validation;
private array $config = [
'ruleSets' => [
DEAValidator::class,
],
];

protected function setUp(): void
{
parent::setUp();
$this->validation = Services::validation();
$this->validation = $this->validation = new Validation((object) $this->config, Services::renderer());
$this->validation->reset();

/** @var DEARule $config */
$config = config('DEARule');
$config->recordedAttemptsIfDisposableEmails = false;

Factories::injectMock('config', 'DEARule', $config);
}

/**
Expand Down Expand Up @@ -131,20 +135,20 @@ public static function provideIsTempEmailByMutiDBFiles(): iterable
*
* @param array<string, string> $data
*/
// public function testIsTempEmailByDomainBlacklisted(array $data, bool $expected): void
// {
// /** @var DEARule $config */
// $config = config('DEARule');
// $config->domainBlacklisted = [
// 'not-allowed-to-register.com',
// 'not-allowed-to-login.com',
// ];
public function testIsTempEmailByDomainBlacklisted(array $data, bool $expected): void
{
/** @var DEARule $config */
$config = config('DEARule');
$config->domainBlacklisted = [
'not-allowed-to-register.com',
'not-allowed-to-login.com',
];

// Factories::injectMock('config', 'DEARule', $config);
Factories::injectMock('config', 'DEARule', $config);

// $this->validation->setRules(['email' => 'is_temp_email']);
// $this->assertSame($expected, $this->validation->run($data));
// }
$this->validation->setRules(['email' => 'is_temp_email']);
$this->assertSame($expected, $this->validation->run($data));
}

/**
* @return array<array<array<string, string>|bool>> $data
Expand All @@ -166,24 +170,24 @@ public static function provideIsTempEmailByDomainBlacklisted(): iterable
*
* @param array<string, string> $data
*/
// public function testEmailIsDomainBlacklistedButEmailsWhiteListed(array $data, bool $expected): void
// {
// /** @var DEARule $config */
// $config = config('DEARule');
// $config->domainBlacklisted = [
// 'not-allowed-to-register.com',
// 'not-allowed-to-login.com',
// ];
// $config->emailsWhiteListed = [
// 'foo@not-allowed-to-register.com',
// 'foo@not-allowed-to-login.com',
// ];

// Factories::injectMock('config', 'DEARule', $config);

// $this->validation->setRules(['email' => 'is_temp_email']);
// $this->assertSame($expected, $this->validation->run($data));
// }
public function testEmailIsDomainBlacklistedButEmailsWhiteListed(array $data, bool $expected): void
{
/** @var DEARule $config */
$config = config('DEARule');
$config->domainBlacklisted = [
'not-allowed-to-register.com',
'not-allowed-to-login.com',
];
$config->emailsWhiteListed = [
'foo@not-allowed-to-register.com',
'foo@not-allowed-to-login.com',
];

Factories::injectMock('config', 'DEARule', $config);

$this->validation->setRules(['email' => 'is_temp_email']);
$this->assertSame($expected, $this->validation->run($data));
}

/**
* @return array<array<array<string, string>|bool>> $data
Expand Down

0 comments on commit 9c36b02

Please sign in to comment.