Skip to content

Commit

Permalink
update model test
Browse files Browse the repository at this point in the history
  • Loading branch information
datamweb committed Nov 15, 2023
1 parent 9c36b02 commit 50397cb
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
11 changes: 10 additions & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@
'count' => 1,
'path' => __DIR__ . '/tests/Validation/DEAValidatorTest.php',
];

$ignoreErrors[] = [
'message' => '#^Property Tests\\\\Models\\\\LogsTempEmailModelTest\\:\\:\\$config type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Models/LogsTempEmailModelTest.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$config of class CodeIgniter\\\\Validation\\\\Validation constructor expects Config\\\\Validation, stdClass given\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Models/LogsTempEmailModelTest.php',
];
return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@

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
83 changes: 83 additions & 0 deletions tests/Models/LogsTempEmailModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter-DEA-Rule.
*
* (c) 2023 Datamweb <pooya_parsa_dadashi@yahoo.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Models;

use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Validation\Validation;
use Config\Services;
use Datamweb\CodeIgniterDEARule\Config\DEARule;
use Datamweb\CodeIgniterDEARule\Validation\DEAValidator;

/**
* @internal
*/
final class LogsTempEmailModelTest extends CIUnitTestCase
{
use DatabaseTestTrait;

/**
* @var bool
*/
protected $migrate = true;

/**
* @var string
*/
protected $namespace = 'Datamweb\CodeIgniterDEARule';

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

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

public function testSeeDBForTempEmail(): void
{
$this->validation->setRules(['email' => 'is_temp_email']);
$this->assertFalse($this->validation->run(['email' => 'foo@0-mail.com']));

$this->seeInDatabase('logs_temp_email', [
'email' => 'foo@0-mail.com',
'filter_by' => 'filesBlacklisted',
]);
}

public function testSeeDBForTempEmailByDomainBlacklisted(): void
{
/** @var DEARule $config */
$config = config('DEARule');
$config->domainBlacklisted = [
'not-allowed-to-register.com',
];
Factories::injectMock('config', 'DEARule', $config);

$this->validation->setRules(['email' => 'is_temp_email']);
$this->assertFalse($this->validation->run(['email' => 'foo@not-allowed-to-register.com']));

$this->seeInDatabase('logs_temp_email', [
'email' => 'foo@not-allowed-to-register.com',
'filter_by' => 'domainBlacklisted',
]);
}
}

0 comments on commit 50397cb

Please sign in to comment.