mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Upgrade project to PHP 8.3, add PHPStan, upgrade almost every dependency (#36)
* start updating to PHP 8.3 * taking off! Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru> Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * dropped this Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * migrate to symfonymailer Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * this is so stupid 😭 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * ah, free, at last. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * oh, Gabriel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * now dawns thy reckoning. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * and thy gore shall GLISTEN before the temples of man. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * creature of steel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * my gratitude upon thee for my freedom. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * but the crimes thy kind has committed against humanity Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Upgrade PHP-CS-Fixer and do fix the codebase * First review round (maybe I have broken something) * are NOT forgotten. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Enable parallel PHP-CS-Fixer runner * PHPStan level 1 * PHPStan level 2 * PHPStan level 3 * PHPStan level 4 * PHPStan level 5 * Levels 6 and 7 takes too much effort. Generate a baseline and fix them eventually * Resolve TODO's related to the php-mock * Drastically reduce baseline size with the Rector * More code modernization with help of the Rector * Update GitLab CI --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru>
This commit is contained in:
@@ -9,7 +9,7 @@ use Yii;
|
||||
|
||||
class ApplicationRedisBridge extends Module {
|
||||
|
||||
protected $config = [
|
||||
protected array $config = [
|
||||
'module' => 'Redis',
|
||||
];
|
||||
|
||||
|
@@ -16,7 +16,6 @@ use yii\test\InitDbFixture;
|
||||
* TODO: try to remove
|
||||
*/
|
||||
class FixtureHelper extends Module {
|
||||
|
||||
/**
|
||||
* Redeclare visibility because codeception includes all public methods that do not start with "_"
|
||||
* and are not excluded by module settings, in actor class.
|
||||
@@ -30,21 +29,21 @@ class FixtureHelper extends Module {
|
||||
getFixture as protected;
|
||||
}
|
||||
|
||||
public function _before(TestInterface $test) {
|
||||
public function _before(TestInterface $test): void {
|
||||
$this->loadFixtures();
|
||||
}
|
||||
|
||||
public function _after(TestInterface $test) {
|
||||
public function _after(TestInterface $test): void {
|
||||
$this->unloadFixtures();
|
||||
}
|
||||
|
||||
public function globalFixtures() {
|
||||
public function globalFixtures(): array {
|
||||
return [
|
||||
InitDbFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function fixtures() {
|
||||
public function fixtures(): array {
|
||||
return [
|
||||
'accounts' => fixtures\AccountFixture::class,
|
||||
'accountSessions' => fixtures\AccountSessionFixture::class,
|
||||
|
@@ -16,10 +16,7 @@ class Fixture extends BaseFixture {
|
||||
use ArrayAccessTrait;
|
||||
use FileFixtureTrait;
|
||||
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
public $redis = 'redis';
|
||||
public string|Connection $redis = 'redis';
|
||||
|
||||
public $keysPrefix = '';
|
||||
|
||||
@@ -27,12 +24,12 @@ class Fixture extends BaseFixture {
|
||||
|
||||
public $data = [];
|
||||
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
parent::init();
|
||||
$this->redis = Instance::ensure($this->redis, Connection::class);
|
||||
}
|
||||
|
||||
public function load() {
|
||||
public function load(): void {
|
||||
$this->data = [];
|
||||
foreach ($this->getData() as $key => $data) {
|
||||
$key = $this->buildKey($key);
|
||||
@@ -47,7 +44,7 @@ class Fixture extends BaseFixture {
|
||||
}
|
||||
}
|
||||
|
||||
public function unload() {
|
||||
public function unload(): void {
|
||||
$this->redis->flushdb();
|
||||
}
|
||||
|
||||
@@ -75,7 +72,7 @@ class Fixture extends BaseFixture {
|
||||
throw new InvalidArgumentException('Unsupported input type');
|
||||
}
|
||||
|
||||
protected function buildKey($key): string {
|
||||
protected function buildKey(string|int $key): string {
|
||||
return $this->keysPrefix . $key . $this->keysPostfix;
|
||||
}
|
||||
|
||||
|
@@ -4,15 +4,14 @@ namespace common\tests\_support\queue;
|
||||
use Codeception\Exception\ModuleException;
|
||||
use Codeception\Module;
|
||||
use Codeception\Module\Yii2;
|
||||
use yii\queue\JobInterface;
|
||||
|
||||
class CodeceptionQueueHelper extends Module {
|
||||
|
||||
/**
|
||||
* Returns last sent message
|
||||
*
|
||||
* @return \yii\queue\JobInterface|null
|
||||
*/
|
||||
public function grabLastQueuedJob() {
|
||||
public function grabLastQueuedJob(): ?JobInterface {
|
||||
$messages = $this->grabQueueJobs();
|
||||
$last = end($messages);
|
||||
if ($last === false) {
|
||||
@@ -27,11 +26,10 @@ class CodeceptionQueueHelper extends Module {
|
||||
* Each message is `\PhpAmqpLib\Message\AMQPMessage` instance.
|
||||
* Useful to perform additional checks using `Asserts` module.
|
||||
*
|
||||
* @param string|null $exchange
|
||||
* @return \yii\queue\JobInterface[]
|
||||
* @throws ModuleException
|
||||
*/
|
||||
public function grabQueueJobs() {
|
||||
public function grabQueueJobs(): array {
|
||||
$amqp = $this->grabComponent('queue');
|
||||
if (!$amqp instanceof Queue) {
|
||||
throw new ModuleException($this, 'AMQP module is not mocked, can\'t test messages');
|
||||
|
@@ -6,15 +6,15 @@ use yii\queue\Queue as BaseQueue;
|
||||
|
||||
class Queue extends BaseQueue {
|
||||
|
||||
private $messages = [];
|
||||
private array $messages = [];
|
||||
|
||||
public function __set($name, $value) {
|
||||
// Yii2 components may contains some configuration
|
||||
// But we just ignore it for this mock component
|
||||
}
|
||||
|
||||
public function push($job) {
|
||||
$this->messages[] = $job;
|
||||
public function push($job): ?string {
|
||||
return (string)array_push($this->messages, $job);
|
||||
}
|
||||
|
||||
public function status($id) {
|
||||
@@ -25,8 +25,8 @@ class Queue extends BaseQueue {
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
protected function pushMessage($message, $ttr, $delay, $priority) {
|
||||
// This function is abstract, but will be not called
|
||||
protected function pushMessage($message, $ttr, $delay, $priority): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,5 +4,4 @@ use common\config\ConfigLoader;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
return ArrayHelper::merge(ConfigLoader::load('common'), [
|
||||
|
||||
]);
|
||||
|
@@ -3,8 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace common\tests\helpers;
|
||||
|
||||
use phpmock\Deactivatable;
|
||||
use phpmock\phpunit\MockObjectProxy;
|
||||
use phpmock\phpunit\PHPMock;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionClass;
|
||||
|
||||
trait ExtendedPHPMock {
|
||||
@@ -13,12 +14,35 @@ trait ExtendedPHPMock {
|
||||
defineFunctionMock as private defineOriginalFunctionMock;
|
||||
}
|
||||
|
||||
public function getFunctionMock($namespace, $name): MockObject {
|
||||
return $this->getOriginalFunctionMock(static::getClassNamespace($namespace), $name);
|
||||
/**
|
||||
* @var Deactivatable[]
|
||||
*/
|
||||
private array $deactivatables = [];
|
||||
|
||||
public function getFunctionMock($namespace, $name): MockObjectProxy {
|
||||
// @phpstan-ignore return.type
|
||||
return $this->getOriginalFunctionMock(self::getClassNamespace($namespace), $name);
|
||||
}
|
||||
|
||||
public static function defineFunctionMock($namespace, $name) {
|
||||
static::defineOriginalFunctionMock(static::getClassNamespace($namespace), $name);
|
||||
public static function defineFunctionMock($namespace, $name): void {
|
||||
self::defineOriginalFunctionMock(self::getClassNamespace($namespace), $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method since original implementation relies on the PHPUnit's state,
|
||||
* but we're dealing with the Codeception, which uses different event system
|
||||
*/
|
||||
public function registerForTearDown(Deactivatable $deactivatable): void {
|
||||
$this->deactivatables[] = $deactivatable;
|
||||
}
|
||||
|
||||
protected function _after(): void {
|
||||
parent::_after();
|
||||
foreach ($this->deactivatables as $deactivatable) {
|
||||
$deactivatable->disable();
|
||||
}
|
||||
|
||||
$this->deactivatables = [];
|
||||
}
|
||||
|
||||
private static function getClassNamespace(string $className): string {
|
||||
|
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\tests\helpers;
|
||||
|
||||
use phpmock\mockery\PHPMockery;
|
||||
use ReflectionClass;
|
||||
|
||||
class Mock {
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $function
|
||||
*
|
||||
* @return \Mockery\Expectation
|
||||
*/
|
||||
public static function func(string $className, string $function) {
|
||||
return PHPMockery::mock(self::getClassNamespace($className), $function);
|
||||
}
|
||||
|
||||
public static function define(string $className, string $function): void {
|
||||
PHPMockery::define(self::getClassNamespace($className), $function);
|
||||
}
|
||||
|
||||
private static function getClassNamespace(string $className): string {
|
||||
return (new ReflectionClass($className))->getNamespaceName();
|
||||
}
|
||||
|
||||
}
|
@@ -9,20 +9,18 @@ use yii\db\ActiveRecord;
|
||||
|
||||
class PrimaryKeyValueBehaviorTest extends TestCase {
|
||||
|
||||
public function testGenerateValueForThePrimaryKey() {
|
||||
public function testGenerateValueForThePrimaryKey(): void {
|
||||
$model = $this->createDummyModel();
|
||||
$behavior = $this->createPartialMock(PrimaryKeyValueBehavior::class, ['isValueExists']);
|
||||
$behavior->method('isValueExists')->willReturn(false);
|
||||
$behavior->value = function() {
|
||||
return 'mock';
|
||||
};
|
||||
$behavior->value = fn(): string => 'mock';
|
||||
|
||||
$model->attachBehavior('primary-key-value-behavior', $behavior);
|
||||
$behavior->setPrimaryKeyValue();
|
||||
$this->assertSame('mock', $model->id);
|
||||
}
|
||||
|
||||
public function testShouldRegenerateValueWhenGeneratedAlreadyExists() {
|
||||
public function testShouldRegenerateValueWhenGeneratedAlreadyExists(): void {
|
||||
$model = $this->createDummyModel();
|
||||
$behavior = $this->createPartialMock(PrimaryKeyValueBehavior::class, ['isValueExists', 'generateValue']);
|
||||
$behavior->expects($this->exactly(3))->method('generateValue')->willReturnOnConsecutiveCalls('1', '2', '3');
|
||||
@@ -33,11 +31,14 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
|
||||
$this->assertSame('3', $model->id);
|
||||
}
|
||||
|
||||
private function createDummyModel() {
|
||||
/**
|
||||
* @return \yii\db\ActiveRecord&object{ id: string }
|
||||
*/
|
||||
private function createDummyModel(): ActiveRecord {
|
||||
return new class extends ActiveRecord {
|
||||
public $id;
|
||||
public string $id;
|
||||
|
||||
public static function primaryKey() {
|
||||
public static function primaryKey(): array {
|
||||
return ['id'];
|
||||
}
|
||||
};
|
||||
|
@@ -14,20 +14,19 @@ use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class ApiTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var Api
|
||||
*/
|
||||
private $api;
|
||||
private Api $api;
|
||||
|
||||
private MockHandler $mockHandler;
|
||||
|
||||
/**
|
||||
* @var MockHandler
|
||||
* @var array<array{
|
||||
* request: \Psr\Http\Message\RequestInterface,
|
||||
* response: \Psr\Http\Message\ResponseInterface,
|
||||
* error: string|null,
|
||||
* options: array<mixed>,
|
||||
* }>
|
||||
*/
|
||||
private $mockHandler;
|
||||
|
||||
/**
|
||||
* @var \Psr\Http\Message\RequestInterface[]
|
||||
*/
|
||||
private $history;
|
||||
private array $history = [];
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -44,7 +43,7 @@ class ApiTest extends TestCase {
|
||||
$this->api->setClient($client);
|
||||
}
|
||||
|
||||
public function testGetTemplate() {
|
||||
public function testGetTemplate(): void {
|
||||
$this->mockHandler->append(new Response(200, [], 'mock-response'));
|
||||
|
||||
$request = new TemplateRequest('mock-name', 'mock-locale', ['find-me' => 'please']);
|
||||
|
@@ -7,18 +7,13 @@ use common\components\EmailsRenderer\Api;
|
||||
use common\components\EmailsRenderer\Component;
|
||||
use common\components\EmailsRenderer\Request\TemplateRequest;
|
||||
use common\tests\unit\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class ComponentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var Api|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $api;
|
||||
private Api&MockObject $api;
|
||||
|
||||
/**
|
||||
* @var Component
|
||||
*/
|
||||
private $component;
|
||||
private Component $component;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -30,7 +25,7 @@ class ComponentTest extends TestCase {
|
||||
'basePath' => '/images/emails-templates',
|
||||
];
|
||||
$this->component = new class($componentParams) extends Component {
|
||||
public $api;
|
||||
public Api $api;
|
||||
|
||||
protected function getApi(): Api {
|
||||
return $this->api;
|
||||
@@ -38,7 +33,7 @@ class ComponentTest extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
public function testRender() {
|
||||
public function testRender(): void {
|
||||
$expectedRequest = new TemplateRequest('mock-name', 'mock-locale', [
|
||||
'find-me' => 'please',
|
||||
'assetsHost' => 'http://localhost/images/emails-templates',
|
||||
|
@@ -7,7 +7,7 @@ use Yii;
|
||||
|
||||
class QueryBuilderTest extends TestCase {
|
||||
|
||||
public function testBuildOrderByField() {
|
||||
public function testBuildOrderByField(): void {
|
||||
$queryBuilder = new QueryBuilder(Yii::$app->db);
|
||||
$result = $queryBuilder->buildOrderBy(['dummy' => ['first', 'second']]);
|
||||
$this->assertSame("ORDER BY FIELD(`dummy`,'first','second')", $result);
|
||||
|
@@ -6,7 +6,7 @@ use common\tests\unit\TestCase;
|
||||
|
||||
class EmailHelperTest extends TestCase {
|
||||
|
||||
public function testBuildTo() {
|
||||
public function testBuildTo(): void {
|
||||
$this->assertSame(['mock@ely.by' => 'username'], EmailHelper::buildTo('username', 'mock@ely.by'));
|
||||
}
|
||||
|
||||
|
@@ -6,37 +6,29 @@ namespace common\tests\unit\emails;
|
||||
use common\emails\exceptions\CannotSendEmailException;
|
||||
use common\emails\Template;
|
||||
use common\tests\unit\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\mail\MailerInterface;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
class TemplateTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var Template|\PHPUnit\Framework\MockObject\MockObject $template
|
||||
*/
|
||||
private $template;
|
||||
private Template&MockObject $template;
|
||||
|
||||
/**
|
||||
* @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $mailer;
|
||||
private MailerInterface&MockObject $mailer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $initialFromEmail;
|
||||
private string $initialFromEmail;
|
||||
|
||||
public function testGetters() {
|
||||
public function testGetters(): void {
|
||||
$this->assertSame(['find-me' => 'Ely.by Accounts'], $this->template->getFrom());
|
||||
$this->assertSame([], $this->template->getParams());
|
||||
}
|
||||
|
||||
public function testSend() {
|
||||
public function testSend(): void {
|
||||
$this->runTestForSend(true);
|
||||
}
|
||||
|
||||
public function testNotSend() {
|
||||
public function testNotSend(): void {
|
||||
$this->expectException(CannotSendEmailException::class);
|
||||
$this->runTestForSend(false);
|
||||
}
|
||||
@@ -49,16 +41,15 @@ class TemplateTest extends TestCase {
|
||||
Yii::$app->params['fromEmail'] = 'find-me';
|
||||
}
|
||||
|
||||
protected function _after() {
|
||||
protected function _after(): void {
|
||||
parent::_after();
|
||||
Yii::$app->params['fromEmail'] = $this->initialFromEmail;
|
||||
}
|
||||
|
||||
private function runTestForSend(bool $sendResult) {
|
||||
private function runTestForSend(bool $sendResult): void {
|
||||
$this->template->expects($this->once())->method('getSubject')->willReturn('mock-subject');
|
||||
$this->template->expects($this->once())->method('getView')->willReturn('mock-view');
|
||||
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $message */
|
||||
$message = $this->createMock(MessageInterface::class);
|
||||
$message->expects($this->once())->method('setTo')->with(['to@ely.by' => 'To'])->willReturnSelf();
|
||||
$message->expects($this->once())->method('setFrom')->with(['find-me' => 'Ely.by Accounts'])->willReturnSelf();
|
||||
|
@@ -8,43 +8,32 @@ use common\emails\RendererInterface;
|
||||
use common\emails\TemplateWithRenderer;
|
||||
use common\tests\unit\TestCase;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\mail\MailerInterface;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
class TemplateWithRendererTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var TemplateWithRenderer|\PHPUnit\Framework\MockObject\MockObject $template
|
||||
*/
|
||||
private $template;
|
||||
private TemplateWithRenderer&MockObject $template;
|
||||
|
||||
/**
|
||||
* @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $mailer;
|
||||
private MailerInterface&MockObject $mailer;
|
||||
|
||||
/**
|
||||
* @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $renderer;
|
||||
private RendererInterface&MockObject $renderer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $initialFromEmail;
|
||||
private string $initialFromEmail;
|
||||
|
||||
public function testGetLocale() {
|
||||
public function testGetLocale(): void {
|
||||
$this->assertSame('en', $this->template->getLocale());
|
||||
$this->template->setLocale('find me');
|
||||
$this->assertSame('find me', $this->template->getLocale());
|
||||
}
|
||||
|
||||
public function testSend() {
|
||||
public function testSend(): void {
|
||||
$this->runTestForSend();
|
||||
}
|
||||
|
||||
public function testSendWithRenderError() {
|
||||
public function testSendWithRenderError(): void {
|
||||
$renderException = new Exception('find me');
|
||||
try {
|
||||
$this->runTestForSend($renderException);
|
||||
@@ -56,10 +45,10 @@ class TemplateWithRendererTest extends TestCase {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertFalse(true, 'no exception was thrown');
|
||||
$this->fail('no exception was thrown');
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
$this->mailer = $this->createMock(MailerInterface::class);
|
||||
$this->renderer = $this->createMock(RendererInterface::class);
|
||||
@@ -68,12 +57,15 @@ class TemplateWithRendererTest extends TestCase {
|
||||
Yii::$app->params['fromEmail'] = 'find-me';
|
||||
}
|
||||
|
||||
protected function _after() {
|
||||
protected function _after(): void {
|
||||
parent::_after();
|
||||
Yii::$app->params['fromEmail'] = $this->initialFromEmail;
|
||||
}
|
||||
|
||||
private function runTestForSend($renderException = null) {
|
||||
/**
|
||||
* @throws \common\emails\exceptions\CannotRenderEmailException
|
||||
*/
|
||||
private function runTestForSend($renderException = null): void {
|
||||
$renderMethodExpectation = $this->renderer->expects($this->once())->method('render')->with('mock-template', 'mock-locale', []);
|
||||
if ($renderException === null) {
|
||||
$renderMethodExpectation->willReturn('mock-template-contents');
|
||||
@@ -86,7 +78,6 @@ class TemplateWithRendererTest extends TestCase {
|
||||
$this->template->expects($times())->method('getSubject')->willReturn('mock-subject');
|
||||
$this->template->expects($times())->method('getTemplateName')->willReturn('mock-template');
|
||||
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $message */
|
||||
$message = $this->createMock(MessageInterface::class);
|
||||
$message->expects($times())->method('setTo')->with(['to@ely.by' => 'To'])->willReturnSelf();
|
||||
$message->expects($times())->method('setHtmlBody')->with('mock-template-contents')->willReturnSelf();
|
||||
|
@@ -8,25 +8,22 @@ use common\tests\unit\TestCase;
|
||||
use yii\base\InvalidCallException;
|
||||
use yii\mail\MailerInterface;
|
||||
|
||||
class ChangeEmailTest extends TestCase {
|
||||
final class ChangeEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ChangeEmail()|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ChangeEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setKey('mock-key');
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-key', $params['key']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
|
@@ -10,12 +10,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class ConfirmNewEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ConfirmNewEmail|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ConfirmNewEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setUsername('mock-username');
|
||||
$this->template->setKey('mock-key');
|
||||
$params = $this->template->getParams();
|
||||
@@ -26,22 +23,21 @@ class ConfirmNewEmailTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getInvalidCallsCases
|
||||
*/
|
||||
public function testInvalidCallOfParams(?string $username, ?string $key) {
|
||||
public function testInvalidCallOfParams(?string $username, ?string $key): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$username !== null && $this->template->setUsername($username);
|
||||
$key !== null && $this->template->setKey($key);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
public function getInvalidCallsCases() {
|
||||
public function getInvalidCallsCases(): iterable {
|
||||
yield [null, null];
|
||||
yield ['value', null];
|
||||
yield [null, 'value'];
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$this->template = new ConfirmNewEmail($mailer);
|
||||
}
|
||||
|
@@ -12,12 +12,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class ForgotPasswordEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ForgotPasswordEmail|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ForgotPasswordEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setParams(new ForgotPasswordParams('mock-username', 'mock-code', 'mock-link'));
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-username', $params['username']);
|
||||
@@ -25,7 +22,7 @@ class ForgotPasswordEmailTest extends TestCase {
|
||||
$this->assertSame('mock-link', $params['link']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
@@ -12,12 +12,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class RegistrationEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var RegistrationEmail()|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private RegistrationEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setParams(new RegistrationEmailParams('mock-username', 'mock-code', 'mock-link'));
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-username', $params['username']);
|
||||
@@ -25,16 +22,14 @@ class RegistrationEmailTest extends TestCase {
|
||||
$this->assertSame('mock-link', $params['link']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
/** @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject $renderer */
|
||||
$renderer = $this->createMock(RendererInterface::class);
|
||||
$this->template = new RegistrationEmail($mailer, $renderer);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use common\tests\unit\TestCase;
|
||||
|
||||
class StringHelperTest extends TestCase {
|
||||
|
||||
public function testGetEmailMask() {
|
||||
public function testGetEmailMask(): void {
|
||||
$this->assertSame('**@ely.by', StringHelper::getEmailMask('e@ely.by'));
|
||||
$this->assertSame('e**@ely.by', StringHelper::getEmailMask('es@ely.by'));
|
||||
$this->assertSame('e**i@ely.by', StringHelper::getEmailMask('eri@ely.by'));
|
||||
@@ -14,16 +14,16 @@ class StringHelperTest extends TestCase {
|
||||
$this->assertSame('эр**уч@елу.бел', StringHelper::getEmailMask('эрикскрауч@елу.бел'));
|
||||
}
|
||||
|
||||
public function testIsUuid() {
|
||||
public function testIsUuid(): void {
|
||||
$this->assertTrue(StringHelper::isUuid('a80b4487-a5c6-45a5-9829-373b4a494135'));
|
||||
$this->assertTrue(StringHelper::isUuid('a80b4487a5c645a59829373b4a494135'));
|
||||
$this->assertFalse(StringHelper::isUuid('12345678'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimProvider()
|
||||
* @dataProvider trimProvider
|
||||
*/
|
||||
public function testTrim($expected, $string) {
|
||||
public function testTrim(string $expected, string $string): void {
|
||||
$result = StringHelper::trim($string);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class StringHelperTest extends TestCase {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function trimProvider() {
|
||||
public static function trimProvider(): array {
|
||||
return [
|
||||
['foo bar', ' foo bar '], // Simple spaces
|
||||
['foo bar', ' foo bar'], // Only left side space
|
||||
|
@@ -6,19 +6,19 @@ use common\tests\unit\TestCase;
|
||||
|
||||
class AccountSessionTest extends TestCase {
|
||||
|
||||
public function testGenerateRefreshToken() {
|
||||
public function testGenerateRefreshToken(): void {
|
||||
$model = new AccountSession();
|
||||
$model->generateRefreshToken();
|
||||
$this->assertNotNull($model->refresh_token, 'method call will set refresh_token value');
|
||||
}
|
||||
|
||||
public function testSetIp() {
|
||||
public function testSetIp(): void {
|
||||
$model = new AccountSession();
|
||||
$model->setIp('127.0.0.1');
|
||||
$this->assertSame(2130706433, $model->last_used_ip, 'method should convert passed ip string to long');
|
||||
}
|
||||
|
||||
public function testGetReadableIp() {
|
||||
public function testGetReadableIp(): void {
|
||||
$model = new AccountSession();
|
||||
$model->last_used_ip = 2130706433;
|
||||
$this->assertSame('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip');
|
||||
|
@@ -17,7 +17,7 @@ use const common\LATEST_RULES_VERSION;
|
||||
*/
|
||||
class AccountTest extends TestCase {
|
||||
|
||||
public function testSetPassword() {
|
||||
public function testSetPassword(): void {
|
||||
$model = new Account();
|
||||
$model->setPassword('12345678');
|
||||
$this->assertNotEmpty($model->password_hash, 'hash should be set');
|
||||
@@ -25,19 +25,17 @@ class AccountTest extends TestCase {
|
||||
$this->assertSame(Account::PASS_HASH_STRATEGY_YII2, $model->password_hash_strategy, 'latest password hash should be used');
|
||||
}
|
||||
|
||||
public function testValidatePassword() {
|
||||
public function testValidatePassword(): void {
|
||||
// Use old hashing algorithm
|
||||
$model = new Account();
|
||||
$model->email = 'erick@skrauch.net';
|
||||
$model->password_hash = '2cfdb29eb354af970865a923335d17d9'; // 12345678
|
||||
$model->password_hash_strategy = null; // To be sure it's not set
|
||||
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_OLD_ELY), 'valid password should pass');
|
||||
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_OLD_ELY), 'invalid password should fail');
|
||||
|
||||
// Modern hash algorithm should also work
|
||||
$model = new Account();
|
||||
$model->password_hash = '$2y$04$N0q8DaHzlYILCnLYrpZfEeWKEqkPZzbawiS07GbSr/.xbRNweSLU6'; // 12345678
|
||||
$model->password_hash_strategy = null; // To be sure it's not set
|
||||
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_YII2), 'valid password should pass');
|
||||
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_YII2), 'invalid password should fail');
|
||||
|
||||
@@ -57,7 +55,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertFalse($model->validatePassword('87654321'), 'invalid password should fail');
|
||||
}
|
||||
|
||||
public function testHasMojangUsernameCollision() {
|
||||
public function testHasMojangUsernameCollision(): void {
|
||||
$model = new Account();
|
||||
$model->username = 'ErickSkrauch';
|
||||
$this->assertFalse($model->hasMojangUsernameCollision());
|
||||
@@ -69,13 +67,13 @@ class AccountTest extends TestCase {
|
||||
$this->assertTrue($model->hasMojangUsernameCollision());
|
||||
}
|
||||
|
||||
public function testGetProfileLink() {
|
||||
public function testGetProfileLink(): void {
|
||||
$model = new Account();
|
||||
$model->id = '123';
|
||||
$model->id = 123;
|
||||
$this->assertSame('http://ely.by/u123', $model->getProfileLink());
|
||||
}
|
||||
|
||||
public function testIsAgreedWithActualRules() {
|
||||
public function testIsAgreedWithActualRules(): void {
|
||||
$model = new Account();
|
||||
$this->assertFalse($model->isAgreedWithActualRules(), 'field is null');
|
||||
|
||||
@@ -86,7 +84,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertTrue($model->isAgreedWithActualRules());
|
||||
}
|
||||
|
||||
public function testSetRegistrationIp() {
|
||||
public function testSetRegistrationIp(): void {
|
||||
$account = new Account();
|
||||
$account->setRegistrationIp('42.72.205.204');
|
||||
$this->assertSame('42.72.205.204', inet_ntop($account->registration_ip));
|
||||
@@ -96,7 +94,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($account->registration_ip);
|
||||
}
|
||||
|
||||
public function testGetRegistrationIp() {
|
||||
public function testGetRegistrationIp(): void {
|
||||
$account = new Account();
|
||||
$account->setRegistrationIp('42.72.205.204');
|
||||
$this->assertSame('42.72.205.204', $account->getRegistrationIp());
|
||||
@@ -106,7 +104,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($account->getRegistrationIp());
|
||||
}
|
||||
|
||||
public function testAfterSaveInsertEvent() {
|
||||
public function testAfterSaveInsertEvent(): void {
|
||||
$account = new Account();
|
||||
$account->afterSave(true, [
|
||||
'username' => 'old-username',
|
||||
@@ -114,7 +112,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($this->tester->grabLastQueuedJob());
|
||||
}
|
||||
|
||||
public function testAfterSaveNotMeaningfulAttributes() {
|
||||
public function testAfterSaveNotMeaningfulAttributes(): void {
|
||||
$account = new Account();
|
||||
$account->afterSave(false, [
|
||||
'updatedAt' => time(),
|
||||
@@ -122,7 +120,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($this->tester->grabLastQueuedJob());
|
||||
}
|
||||
|
||||
public function testAfterSavePushEvent() {
|
||||
public function testAfterSavePushEvent(): void {
|
||||
$changedAttributes = [
|
||||
'username' => 'old-username',
|
||||
'email' => 'old-email@ely.by',
|
||||
@@ -144,7 +142,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertSame($changedAttributes, $notification->getPayloads()['changedAttributes']);
|
||||
}
|
||||
|
||||
public function testAfterDeletePushEvent() {
|
||||
public function testAfterDeletePushEvent(): void {
|
||||
$account = new Account();
|
||||
$account->id = 1;
|
||||
$account->status = Account::STATUS_REGISTERED;
|
||||
|
@@ -21,18 +21,18 @@ class EmailActivationTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getInstantiateTestCases
|
||||
*/
|
||||
public function testInstantiate(int $type, string $expectedClassType) {
|
||||
public function testInstantiate(int $type, string $expectedClassType): void {
|
||||
$this->assertInstanceOf($expectedClassType, EmailActivation::findOne(['type' => $type]));
|
||||
}
|
||||
|
||||
public function getInstantiateTestCases() {
|
||||
public function getInstantiateTestCases(): iterable {
|
||||
yield [EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION, confirmations\RegistrationConfirmation::class];
|
||||
yield [EmailActivation::TYPE_FORGOT_PASSWORD_KEY, confirmations\ForgotPassword::class];
|
||||
yield [EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION, confirmations\CurrentEmailConfirmation::class];
|
||||
yield [EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION, confirmations\NewEmailConfirmation::class];
|
||||
}
|
||||
|
||||
public function testCanResend() {
|
||||
public function testCanResend(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getResendTimeout']);
|
||||
$model->method('getResendTimeout')->willReturn(new DateInterval('PT10M'));
|
||||
|
||||
@@ -45,7 +45,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertEqualsWithDelta(Carbon::now()->subSecond(), $model->canResendAt(), 3);
|
||||
}
|
||||
|
||||
public function testCanResendWithNullTimeout() {
|
||||
public function testCanResendWithNullTimeout(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getResendTimeout']);
|
||||
$model->method('getResendTimeout')->willReturn(null);
|
||||
|
||||
@@ -54,7 +54,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertEqualsWithDelta(Carbon::now(), $model->canResendAt(), 3);
|
||||
}
|
||||
|
||||
public function testIsStale() {
|
||||
public function testIsStale(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getExpireDuration']);
|
||||
$model->method('getExpireDuration')->willReturn(new DateInterval('PT10M'));
|
||||
|
||||
@@ -65,7 +65,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertTrue($model->isStale());
|
||||
}
|
||||
|
||||
public function testIsStaleWithNullDuration() {
|
||||
public function testIsStaleWithNullDuration(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getExpireDuration']);
|
||||
$model->method('getExpireDuration')->willReturn(null);
|
||||
|
||||
|
@@ -13,30 +13,24 @@ class OauthClientQueryTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testDefaultHideDeletedEntries() {
|
||||
public function testDefaultHideDeletedEntries(): void {
|
||||
/** @var OauthClient[] $clients */
|
||||
$clients = OauthClient::find()->all();
|
||||
$this->assertEmpty(array_filter($clients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === true;
|
||||
}));
|
||||
$this->assertEmpty(array_filter($clients, fn(OauthClient $client): bool => (bool)$client->is_deleted === true));
|
||||
$this->assertNull(OauthClient::findOne('deleted-oauth-client'));
|
||||
}
|
||||
|
||||
public function testAllowFindDeletedEntries() {
|
||||
public function testAllowFindDeletedEntries(): void {
|
||||
/** @var OauthClient[] $clients */
|
||||
$clients = OauthClient::find()->includeDeleted()->all();
|
||||
$this->assertNotEmpty(array_filter($clients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === true;
|
||||
}));
|
||||
$this->assertNotEmpty(array_filter($clients, fn(OauthClient $client): bool => (bool)$client->is_deleted === true));
|
||||
$client = OauthClient::find()
|
||||
->includeDeleted()
|
||||
->andWhere(['id' => 'deleted-oauth-client'])
|
||||
->one();
|
||||
$this->assertInstanceOf(OauthClient::class, $client);
|
||||
$deletedClients = OauthClient::find()->onlyDeleted()->all();
|
||||
$this->assertEmpty(array_filter($deletedClients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === false;
|
||||
}));
|
||||
$this->assertEmpty(array_filter($deletedClients, fn(OauthClient $client): bool => (bool)$client->is_deleted === false));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ class ClearAccountSessionsTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
/** @var \common\models\Account $bannedAccount */
|
||||
$bannedAccount = $this->tester->grabFixture('accounts', 'banned-account');
|
||||
$task = new ClearAccountSessions($bannedAccount->id);
|
||||
|
@@ -19,7 +19,7 @@ class ClearOauthSessionsTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testCreateFromClient() {
|
||||
public function testCreateFromClient(): void {
|
||||
$client = new OauthClient();
|
||||
$client->id = 'mocked-id';
|
||||
|
||||
@@ -34,7 +34,7 @@ class ClearOauthSessionsTest extends TestCase {
|
||||
$this->assertEqualsWithDelta(time(), $result->notSince, 1);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
$task = new ClearOauthSessions('deleted-oauth-client-with-sessions', 1519510065);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
|
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace common\tests\unit\tasks;
|
||||
|
||||
use Carbon\Exceptions\UnreachableException;
|
||||
use common\notifications\NotificationInterface;
|
||||
use common\tasks\CreateWebHooksDeliveries;
|
||||
use common\tasks\DeliveryWebHook;
|
||||
@@ -21,7 +22,7 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
$notification = new class implements NotificationInterface {
|
||||
public static function getType(): string {
|
||||
return 'account.edit';
|
||||
@@ -33,24 +34,28 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
};
|
||||
|
||||
$queue = $this->createMock(Queue::class);
|
||||
$queue->expects($this->exactly(2))->method('push')->withConsecutive(
|
||||
[$this->callback(function(DeliveryWebHook $task): bool {
|
||||
$invocationCount = $this->exactly(2);
|
||||
$queue->expects($invocationCount)->method('push')->willReturnCallback(function(DeliveryWebHook $task) use ($invocationCount): bool {
|
||||
if ($invocationCount->numberOfInvocations() === 1) {
|
||||
$this->assertSame('account.edit', $task->type);
|
||||
$this->assertSame(['key' => 'value'], $task->payloads);
|
||||
$this->assertSame('http://localhost:80/webhooks/ely', $task->url);
|
||||
$this->assertSame('my-secret', $task->secret);
|
||||
|
||||
return true;
|
||||
})],
|
||||
[$this->callback(function(DeliveryWebHook $task): bool {
|
||||
}
|
||||
|
||||
if ($invocationCount->numberOfInvocations() === 2) {
|
||||
$this->assertSame('account.edit', $task->type);
|
||||
$this->assertSame(['key' => 'value'], $task->payloads);
|
||||
$this->assertSame('http://localhost:81/webhooks/ely', $task->url);
|
||||
$this->assertNull($task->secret);
|
||||
|
||||
return true;
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
throw new UnreachableException();
|
||||
});
|
||||
|
||||
$task = new CreateWebHooksDeliveries($notification);
|
||||
$task->execute($queue);
|
||||
|
@@ -25,7 +25,7 @@ class DeleteAccountTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$account->status = Account::STATUS_DELETED;
|
||||
@@ -46,7 +46,7 @@ class DeleteAccountTest extends TestCase {
|
||||
* When a user restores his account back, the task doesn't removed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function testExecuteOnNotDeletedAccount() {
|
||||
public function testExecuteOnNotDeletedAccount(): void {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
// By default, this account is active
|
||||
@@ -66,7 +66,7 @@ class DeleteAccountTest extends TestCase {
|
||||
* For each deletion the job will be created, so assert, that job for restored deleting will not work
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function testExecuteOnDeletedAccountWhichWasRestoredAndThenDeletedAgain() {
|
||||
public function testExecuteOnDeletedAccountWhichWasRestoredAndThenDeletedAgain(): void {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$account->status = Account::STATUS_DELETED;
|
||||
|
@@ -20,14 +20,14 @@ use yii\queue\Queue;
|
||||
*/
|
||||
class DeliveryWebHookTest extends TestCase {
|
||||
|
||||
private $historyContainer = [];
|
||||
private array $historyContainer = [];
|
||||
|
||||
/**
|
||||
* @var Response|\GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
private $response;
|
||||
|
||||
public function testCanRetry() {
|
||||
public function testCanRetry(): void {
|
||||
$task = new DeliveryWebHook();
|
||||
$this->assertFalse($task->canRetry(1, new \Exception()));
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
@@ -38,7 +38,7 @@ class DeliveryWebHookTest extends TestCase {
|
||||
$this->assertFalse($task->canRetry(5, new ServerException('', $request, $response)));
|
||||
}
|
||||
|
||||
public function testExecuteSuccessDelivery() {
|
||||
public function testExecuteSuccessDelivery(): void {
|
||||
$this->response = new Response();
|
||||
$task = $this->createMockedTask();
|
||||
$task->type = 'account.edit';
|
||||
@@ -58,7 +58,7 @@ class DeliveryWebHookTest extends TestCase {
|
||||
$this->assertSame('key=value&another=value', (string)$request->getBody());
|
||||
}
|
||||
|
||||
public function testExecuteSuccessDeliveryWithSignature() {
|
||||
public function testExecuteSuccessDeliveryWithSignature(): void {
|
||||
$this->response = new Response();
|
||||
$task = $this->createMockedTask();
|
||||
$task->type = 'account.edit';
|
||||
@@ -79,7 +79,7 @@ class DeliveryWebHookTest extends TestCase {
|
||||
$this->assertSame('key=value&another=value', (string)$request->getBody());
|
||||
}
|
||||
|
||||
public function testExecuteHandleClientException() {
|
||||
public function testExecuteHandleClientException(): void {
|
||||
$this->response = new Response(403);
|
||||
$task = $this->createMockedTask();
|
||||
$task->type = 'account.edit';
|
||||
@@ -92,7 +92,7 @@ class DeliveryWebHookTest extends TestCase {
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
}
|
||||
|
||||
public function testExecuteUnhandledException() {
|
||||
public function testExecuteUnhandledException(): void {
|
||||
$this->expectException(ServerException::class);
|
||||
|
||||
$this->response = new Response(502);
|
||||
@@ -114,11 +114,11 @@ class DeliveryWebHookTest extends TestCase {
|
||||
return new class($container, $response) extends DeliveryWebHook {
|
||||
private $historyContainer;
|
||||
|
||||
private $response;
|
||||
|
||||
public function __construct(array &$historyContainer, $response) {
|
||||
public function __construct(
|
||||
array & $historyContainer,
|
||||
private $response,
|
||||
) {
|
||||
$this->historyContainer = &$historyContainer;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
protected function createStack(): HandlerStack {
|
||||
|
@@ -30,7 +30,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function _before() {
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|MojangApi $mockApi */
|
||||
@@ -40,14 +40,14 @@ class PullMojangUsernameTest extends TestCase {
|
||||
Yii::$container->set(MojangApi::class, $mockApi);
|
||||
}
|
||||
|
||||
public function testCreateFromAccount() {
|
||||
public function testCreateFromAccount(): void {
|
||||
$account = new Account();
|
||||
$account->username = 'find-me';
|
||||
$result = PullMojangUsername::createFromAccount($account);
|
||||
$this->assertSame('find-me', $result->username);
|
||||
}
|
||||
|
||||
public function testExecuteUsernameExists() {
|
||||
public function testExecuteUsernameExists(): void {
|
||||
$this->mockedMethod->willReturn(new ProfileInfo('069a79f444e94726a5befca90e38aaf5', 'Notch'));
|
||||
|
||||
/** @var MojangUsername $mojangUsernameFixture */
|
||||
@@ -62,7 +62,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
$this->assertLessThanOrEqual(time(), $mojangUsername->last_pulled_at);
|
||||
}
|
||||
|
||||
public function testExecuteChangedUsernameExists() {
|
||||
public function testExecuteChangedUsernameExists(): void {
|
||||
$this->mockedMethod->willReturn(new ProfileInfo('069a79f444e94726a5befca90e38aaf5', 'Notch'));
|
||||
|
||||
/** @var MojangUsername $mojangUsernameFixture */
|
||||
@@ -77,7 +77,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
$this->assertLessThanOrEqual(time(), $mojangUsername->last_pulled_at);
|
||||
}
|
||||
|
||||
public function testExecuteChangedUsernameNotExists() {
|
||||
public function testExecuteChangedUsernameNotExists(): void {
|
||||
$this->mockedMethod->willReturn(new ProfileInfo('607153852b8c4909811f507ed8ee737f', 'Chest'));
|
||||
|
||||
$task = new PullMojangUsername();
|
||||
@@ -88,7 +88,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
$this->assertInstanceOf(MojangUsername::class, $mojangUsername);
|
||||
}
|
||||
|
||||
public function testExecuteRemoveIfExistsNoMore() {
|
||||
public function testExecuteRemoveIfExistsNoMore(): void {
|
||||
$this->mockedMethod->willThrowException(new NoContentException(new Request('GET', ''), new Response()));
|
||||
|
||||
$username = $this->tester->grabFixture('mojangUsernames', 'not-exists')['username'];
|
||||
@@ -100,7 +100,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
$this->assertNull($mojangUsername);
|
||||
}
|
||||
|
||||
public function testExecuteUuidUpdated() {
|
||||
public function testExecuteUuidUpdated(): void {
|
||||
$this->mockedMethod->willReturn(new ProfileInfo('f498513ce8c84773be26ecfc7ed5185d', 'jeb'));
|
||||
|
||||
/** @var MojangUsername $mojangInfo */
|
||||
|
@@ -8,11 +8,13 @@ use common\models\AccountQuery;
|
||||
use common\models\confirmations\CurrentEmailConfirmation;
|
||||
use common\tasks\SendCurrentEmailConfirmation;
|
||||
use common\tests\unit\TestCase;
|
||||
use Yii;
|
||||
use yii\queue\Queue;
|
||||
use yii\symfonymailer\Message;
|
||||
|
||||
class SendCurrentEmailConfirmationTest extends TestCase {
|
||||
|
||||
public function testCreateFromConfirmation() {
|
||||
public function testCreateFromConfirmation(): void {
|
||||
$account = new Account();
|
||||
$account->username = 'mock-username';
|
||||
$account->email = 'mock@ely.by';
|
||||
@@ -31,8 +33,8 @@ class SendCurrentEmailConfirmationTest extends TestCase {
|
||||
$this->assertSame('ABCDEFG', $result->code);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
$task = new SendCurrentEmailConfirmation();
|
||||
public function testExecute(): void {
|
||||
$task = new SendCurrentEmailConfirmation(Yii::$app->mailer);
|
||||
$task->username = 'mock-username';
|
||||
$task->email = 'mock@ely.by';
|
||||
$task->code = 'GFEDCBA';
|
||||
@@ -40,12 +42,11 @@ class SendCurrentEmailConfirmationTest extends TestCase {
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->tester->canSeeEmailIsSent(1);
|
||||
/** @var \yii\swiftmailer\Message $email */
|
||||
/** @var Message $email */
|
||||
$email = $this->tester->grabSentEmails()[0];
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account change E-mail confirmation', $email->getSubject());
|
||||
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||
$this->assertStringContainsString('GFEDCBA', $children->getBody());
|
||||
$this->assertStringContainsString('GFEDCBA', $email->getSymfonyEmail()->getTextBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ use yii\queue\Queue;
|
||||
|
||||
class SendNewEmailConfirmationTest extends TestCase {
|
||||
|
||||
public function testCreateFromConfirmation() {
|
||||
public function testCreateFromConfirmation(): void {
|
||||
$account = new Account();
|
||||
$account->username = 'mock-username';
|
||||
$account->lang = 'id';
|
||||
@@ -31,7 +31,7 @@ class SendNewEmailConfirmationTest extends TestCase {
|
||||
$this->assertSame('ABCDEFG', $result->code);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
$task = new SendNewEmailConfirmation();
|
||||
$task->username = 'mock-username';
|
||||
$task->email = 'mock@ely.by';
|
||||
@@ -40,12 +40,11 @@ class SendNewEmailConfirmationTest extends TestCase {
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->tester->canSeeEmailIsSent(1);
|
||||
/** @var \yii\swiftmailer\Message $email */
|
||||
/** @var \yii\symfonymailer\Message $email */
|
||||
$email = $this->tester->grabSentEmails()[0];
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account new E-mail confirmation', $email->getSubject());
|
||||
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||
$this->assertStringContainsString('GFEDCBA', $children->getBody());
|
||||
$this->assertStringContainsString('GFEDCBA', $email->getSymfonyEmail()->getTextBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,17 +9,15 @@ use common\models\AccountQuery;
|
||||
use common\models\confirmations\ForgotPassword;
|
||||
use common\tasks\SendPasswordRecoveryEmail;
|
||||
use common\tests\unit\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\queue\Queue;
|
||||
|
||||
class SendPasswordRecoveryEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $renderer;
|
||||
private RendererInterface&MockObject $renderer;
|
||||
|
||||
public function testCreateFromConfirmation() {
|
||||
public function testCreateFromConfirmation(): void {
|
||||
$account = new Account();
|
||||
$account->username = 'mock-username';
|
||||
$account->email = 'mock@ely.by';
|
||||
@@ -40,7 +38,7 @@ class SendPasswordRecoveryEmailTest extends TestCase {
|
||||
$this->assertSame('id', $result->locale);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
$task = new SendPasswordRecoveryEmail();
|
||||
$task->username = 'mock-username';
|
||||
$task->email = 'mock@ely.by';
|
||||
@@ -57,14 +55,14 @@ class SendPasswordRecoveryEmailTest extends TestCase {
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->tester->canSeeEmailIsSent(1);
|
||||
/** @var \yii\swiftmailer\Message $email */
|
||||
/** @var \yii\symfonymailer\Message $email */
|
||||
$email = $this->tester->grabSentEmails()[0];
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account forgot password', $email->getSubject());
|
||||
$this->assertSame('mock-template', $email->getSwiftMessage()->getBody());
|
||||
$this->assertSame('mock-template', $email->getSymfonyEmail()->getHtmlBody());
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
|
||||
$this->renderer = $this->createMock(RendererInterface::class);
|
||||
|
@@ -9,17 +9,15 @@ use common\models\AccountQuery;
|
||||
use common\models\confirmations\RegistrationConfirmation;
|
||||
use common\tasks\SendRegistrationEmail;
|
||||
use common\tests\unit\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\queue\Queue;
|
||||
|
||||
class SendRegistrationEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $renderer;
|
||||
private RendererInterface&MockObject $renderer;
|
||||
|
||||
public function testCreateFromConfirmation() {
|
||||
public function testCreateFromConfirmation(): void {
|
||||
$account = new Account();
|
||||
$account->username = 'mock-username';
|
||||
$account->email = 'mock@ely.by';
|
||||
@@ -40,7 +38,7 @@ class SendRegistrationEmailTest extends TestCase {
|
||||
$this->assertSame('ru', $result->locale);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
public function testExecute(): void {
|
||||
$task = new SendRegistrationEmail();
|
||||
$task->username = 'mock-username';
|
||||
$task->email = 'mock@ely.by';
|
||||
@@ -57,11 +55,11 @@ class SendRegistrationEmailTest extends TestCase {
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->tester->canSeeEmailIsSent(1);
|
||||
/** @var \yii\swiftmailer\Message $email */
|
||||
/** @var \yii\symfonymailer\Message $email */
|
||||
$email = $this->tester->grabSentEmails()[0];
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account registration', $email->getSubject());
|
||||
$this->assertSame('mock-template', $email->getSwiftMessage()->getBody());
|
||||
$this->assertSame('mock-template', $email->getSymfonyEmail()->getHtmlBody());
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
|
@@ -3,9 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace common\tests\unit\validators;
|
||||
|
||||
use common\models\Account;
|
||||
use common\tests\fixtures\AccountFixture;
|
||||
use common\tests\unit\TestCase;
|
||||
use common\validators\EmailValidator;
|
||||
use Generator;
|
||||
use yii\base\Model;
|
||||
use yii\validators\EmailValidator as YiiEmailValidator;
|
||||
|
||||
@@ -16,7 +18,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
|
||||
private EmailValidator $validator;
|
||||
|
||||
public function _before() {
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
|
||||
self::defineFunctionMock(YiiEmailValidator::class, 'checkdnsrr');
|
||||
@@ -25,7 +27,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->validator = new EmailValidator();
|
||||
}
|
||||
|
||||
public function testValidateTrimming() {
|
||||
public function testValidateTrimming(): void {
|
||||
// Prevent it to access to db
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
|
||||
|
||||
@@ -35,7 +37,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertSame('testemail@ely.by', $model->field);
|
||||
}
|
||||
|
||||
public function testValidateAttributeRequired() {
|
||||
public function testValidateAttributeRequired(): void {
|
||||
$model = $this->createModel('');
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.email_required'], $model->getErrors('field'));
|
||||
@@ -45,14 +47,14 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertNotSame(['error.email_required'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeLength() {
|
||||
public function testValidateAttributeLength(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
|
||||
|
||||
$model = $this->createModel(
|
||||
'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' .
|
||||
'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' .
|
||||
'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' .
|
||||
'@gmail.com' // = 256 symbols
|
||||
'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail'
|
||||
. 'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail'
|
||||
. 'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail'
|
||||
. '@gmail.com', // = 256 symbols
|
||||
);
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.email_too_long'], $model->getErrors('field'));
|
||||
@@ -62,7 +64,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertNotSame(['error.email_too_long'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeEmailCaseNotExistsDomain() {
|
||||
public function testValidateAttributeEmailCaseNotExistsDomain(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->never());
|
||||
|
||||
@@ -71,7 +73,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertSame(['error.email_invalid'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeEmailCaseExistsDomainButWithoutMXRecord() {
|
||||
public function testValidateAttributeEmailCaseExistsDomainButWithoutMXRecord(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->exactly(2))->willReturnOnConsecutiveCalls(false, true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
@@ -80,7 +82,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertNotSame(['error.email_invalid'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeEmailCaseExistsDomainWithMXRecord() {
|
||||
public function testValidateAttributeEmailCaseExistsDomainWithMXRecord(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['mx.google.com']);
|
||||
|
||||
@@ -98,7 +100,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertSame(['error.email_invalid'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeTempmail() {
|
||||
public function testValidateAttributeTempmail(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
@@ -114,7 +116,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getValidateAttributeBlacklistedHostTestCases
|
||||
*/
|
||||
public function testValidateAttributeBlacklistedHost(string $email, bool $expectValid) {
|
||||
public function testValidateAttributeBlacklistedHost(string $email, bool $expectValid): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
@@ -128,7 +130,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public function getValidateAttributeBlacklistedHostTestCases() {
|
||||
public static function getValidateAttributeBlacklistedHostTestCases(): Generator {
|
||||
yield 'seznam.cz' => ['user@seznam.cz', false];
|
||||
yield 'valid' => ['valid@google.com', true];
|
||||
}
|
||||
@@ -136,7 +138,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getValidateAttributeIdnaTestCases
|
||||
*/
|
||||
public function testValidateAttributeIdna(string $input, string $expectedOutput) {
|
||||
public function testValidateAttributeIdna(string $input, string $expectedOutput): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
@@ -145,13 +147,13 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertSame($expectedOutput, $model->field);
|
||||
}
|
||||
|
||||
public function getValidateAttributeIdnaTestCases() {
|
||||
public static function getValidateAttributeIdnaTestCases(): Generator {
|
||||
yield ['qdushyantasunassm@❕.gq', 'qdushyantasunassm@xn--bei.gq'];
|
||||
yield ['Rafaelaabraão@gmail.com', 'xn--rafaelaabrao-dcb@gmail.com'];
|
||||
yield ['valid-email@gmail.com', 'valid-email@gmail.com'];
|
||||
}
|
||||
|
||||
public function testValidateAttributeUnique() {
|
||||
public function testValidateAttributeUnique(): void {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
@@ -159,7 +161,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
'accounts' => AccountFixture::class,
|
||||
]);
|
||||
|
||||
/** @var \common\models\Account $accountFixture */
|
||||
/** @var Account $accountFixture */
|
||||
$accountFixture = $this->tester->grabFixture('accounts', 'admin');
|
||||
|
||||
$model = $this->createModel($accountFixture->email);
|
||||
@@ -167,9 +169,7 @@ final class EmailValidatorTest extends TestCase {
|
||||
$this->assertSame(['error.email_not_available'], $model->getErrors('field'));
|
||||
|
||||
$model = $this->createModel($accountFixture->email);
|
||||
$this->validator->accountCallback = function() use ($accountFixture) {
|
||||
return $accountFixture->id;
|
||||
};
|
||||
$this->validator->accountCallback = fn() => $accountFixture->id;
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertNotSame(['error.email_not_available'], $model->getErrors('field'));
|
||||
$this->validator->accountCallback = null;
|
||||
@@ -180,12 +180,11 @@ final class EmailValidatorTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fieldValue
|
||||
* @return Model
|
||||
* @return Model&object{ field: mixed }
|
||||
*/
|
||||
private function createModel(string $fieldValue): Model {
|
||||
$class = new class extends Model {
|
||||
public $field;
|
||||
public string $field;
|
||||
};
|
||||
|
||||
$class->field = $fieldValue;
|
||||
|
@@ -9,7 +9,7 @@ class MinecraftServerAddressValidatorTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider domainNames
|
||||
*/
|
||||
public function testValidate($address, $shouldBeValid) {
|
||||
public function testValidate(string $address, bool $shouldBeValid): void {
|
||||
$validator = new MinecraftServerAddressValidator();
|
||||
$validator->message = 'mock message';
|
||||
$validator->validate($address, $errors);
|
||||
@@ -20,7 +20,7 @@ class MinecraftServerAddressValidatorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public function domainNames() {
|
||||
public function domainNames(): array {
|
||||
return [
|
||||
['localhost', true],
|
||||
['localhost:25565', true],
|
||||
|
@@ -8,24 +8,21 @@ use yii\base\Model;
|
||||
|
||||
class UsernameValidatorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var UsernameValidator
|
||||
*/
|
||||
private $validator;
|
||||
private UsernameValidator $validator;
|
||||
|
||||
public function _before() {
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->validator = new UsernameValidator();
|
||||
}
|
||||
|
||||
public function testValidateTrimming() {
|
||||
public function testValidateTrimming(): void {
|
||||
$model = $this->createModel("HereIsJohnny#\u{feff}"); // Zero width no-break space (U+FEFF)
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.username_invalid'], $model->getErrors('field'));
|
||||
$this->assertSame('HereIsJohnny#', $model->field);
|
||||
}
|
||||
|
||||
public function testValidateAttributeRequired() {
|
||||
public function testValidateAttributeRequired(): void {
|
||||
$model = $this->createModel('');
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.username_required'], $model->getErrors('field'));
|
||||
@@ -35,7 +32,7 @@ class UsernameValidatorTest extends TestCase {
|
||||
$this->assertNotSame(['error.username_required'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeLength() {
|
||||
public function testValidateAttributeLength(): void {
|
||||
$model = $this->createModel('at');
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.username_too_short'], $model->getErrors('field'));
|
||||
@@ -51,7 +48,7 @@ class UsernameValidatorTest extends TestCase {
|
||||
}
|
||||
|
||||
// TODO: rewrite this test with @provider usage
|
||||
public function testValidateAttributePattern() {
|
||||
public function testValidateAttributePattern(): void {
|
||||
$shouldBeValid = [
|
||||
'русский_ник', 'русский_ник_на_грани!', 'numbers1132', '*__*-Stars-*__*', '1-_.!$%^&*()[]',
|
||||
'[ESP]Эрик', 'Свят_помидор;', 'зроблена_ў_беларусі:)',
|
||||
@@ -72,7 +69,7 @@ class UsernameValidatorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidateAttributeUnique() {
|
||||
public function testValidateAttributeUnique(): void {
|
||||
$this->tester->haveFixtures([
|
||||
'accounts' => AccountFixture::class,
|
||||
]);
|
||||
@@ -85,9 +82,7 @@ class UsernameValidatorTest extends TestCase {
|
||||
$this->assertSame(['error.username_not_available'], $model->getErrors('field'));
|
||||
|
||||
$model = $this->createModel($accountFixture->username);
|
||||
$this->validator->accountCallback = function() use ($accountFixture) {
|
||||
return $accountFixture->id;
|
||||
};
|
||||
$this->validator->accountCallback = fn() => $accountFixture->id;
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertNotSame(['error.username_not_available'], $model->getErrors('field'));
|
||||
$this->validator->accountCallback = null;
|
||||
@@ -99,11 +94,11 @@ class UsernameValidatorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @param string $fieldValue
|
||||
* @return Model
|
||||
* @return Model&object{ field: string }
|
||||
*/
|
||||
private function createModel(string $fieldValue): Model {
|
||||
$class = new class extends Model {
|
||||
public $field;
|
||||
public string $field;
|
||||
};
|
||||
|
||||
$class->field = $fieldValue;
|
||||
|
Reference in New Issue
Block a user