Get rid of mockery library. Still have some troubles with functional tests for api

This commit is contained in:
ErickSkrauch 2019-12-14 00:16:05 +03:00
parent d9ef27b745
commit e8b71d33d0
37 changed files with 217 additions and 374 deletions

View File

@ -56,7 +56,7 @@ class OauthClientForm {
public function delete(): bool {
$transaction = Yii::$app->db->beginTransaction();
$client = $this->client;
$client = $this->getClient();
$client->is_deleted = true;
Assert::true($client->save(), 'Cannot update oauth client');
@ -70,7 +70,7 @@ class OauthClientForm {
public function reset(bool $regenerateSecret = false): bool {
$transaction = Yii::$app->db->beginTransaction();
$client = $this->client;
$client = $this->getClient();
if ($regenerateSecret) {
$client->generateSecret();
Assert::true($client->save(), 'Cannot update oauth client');

View File

@ -1,4 +1,7 @@
<?php
Codeception\PHPUnit\Init::init();
defined('YII_DEBUG') || define('YII_DEBUG', true);
defined('YII_ENV') || define('YII_ENV', 'test');

View File

@ -10,7 +10,6 @@ modules:
recreateApplication: true
transaction: false
- common\tests\_support\FixtureHelper
- common\tests\_support\Mockery
- REST:
depends: Yii2
- Redis:

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\functional\accounts;
use api\tests\_pages\AccountsRoute;
@ -18,7 +20,7 @@ class ChangeEmailSubmitNewEmailCest {
}
public function testSubmitNewEmail(FunctionalTester $I) {
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturnTrue();
// Mock::func(EmailValidator::class, 'checkdnsrr')->andReturnTrue();
$I->wantTo('submit new email');
$id = $I->amAuthenticated('ILLIMUNATI');

View File

@ -7,4 +7,3 @@ modules:
part: [orm, email, fixtures]
configFile: tests/config/unit.php
- common\tests\_support\queue\CodeceptionQueueHelper
- common\tests\_support\Mockery

View File

@ -4,19 +4,13 @@ declare(strict_types=1);
namespace api\tests\unit;
use Codeception\Test\Unit;
use Mockery;
use common\tests\helpers\ExtendedPHPMock;
/**
* @property \api\tests\UnitTester $tester
*/
class TestCase extends Unit {
/**
* @var \api\tests\UnitTester
*/
protected $tester;
protected function tearDown(): void {
parent::tearDown();
Mockery::close();
}
use ExtendedPHPMock;
/**
* A list of fixtures that will be loaded before the test, but after the database is cleaned up

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace codeception\api\unit\components\ReCaptcha;
use api\components\ReCaptcha\Validator;
@ -12,14 +14,14 @@ use ReflectionClass;
class ValidatorTest extends TestCase {
public function testValidateEmptyValue() {
$validator = new Validator(mock(ClientInterface::class));
$validator = new Validator($this->createMock(ClientInterface::class));
$this->assertFalse($validator->validate('', $error));
$this->assertSame('error.captcha_required', $error, 'Get error.captcha_required, if passed empty value');
}
public function testValidateInvalidValue() {
$mockClient = mock(ClientInterface::class);
$mockClient->shouldReceive('request')->andReturn(new Response(200, [], json_encode([
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->method('request')->willReturn(new Response(200, [], json_encode([
'success' => false,
'error-codes' => [
'invalid-input-response', // The response parameter is invalid or malformed.
@ -32,14 +34,16 @@ class ValidatorTest extends TestCase {
}
public function testValidateWithNetworkTroubles() {
$mockClient = mock(ClientInterface::class);
$mockClient->shouldReceive('request')->andThrow(mock(ConnectException::class))->once();
$mockClient->shouldReceive('request')->andReturn(new Response(200, [], json_encode([
'success' => true,
'error-codes' => [
'invalid-input-response', // The response parameter is invalid or malformed.
],
])))->once();
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->expects($this->exactly(2))->method('request')->willReturnOnConsecutiveCalls(
$this->throwException($this->createMock(ConnectException::class)),
$this->returnValue(new Response(200, [], json_encode([
'success' => true,
'error-codes' => [
'invalid-input-response', // The response parameter is invalid or malformed.
],
])))
);
PHPMockery::mock($this->getClassNamespace(Validator::class), 'sleep')->once();
$validator = new Validator($mockClient);
@ -48,8 +52,8 @@ class ValidatorTest extends TestCase {
}
public function testValidateWithHugeNetworkTroubles() {
$mockClient = mock(ClientInterface::class);
$mockClient->shouldReceive('request')->andThrow(mock(ConnectException::class))->times(3);
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->expects($this->exactly(3))->method('request')->willThrowException($this->createMock(ConnectException::class));
PHPMockery::mock($this->getClassNamespace(Validator::class), 'sleep')->times(2);
$validator = new Validator($mockClient);
@ -58,8 +62,8 @@ class ValidatorTest extends TestCase {
}
public function testValidateValidValue() {
$mockClient = mock(ClientInterface::class);
$mockClient->shouldReceive('request')->andReturn(new Response(200, [], json_encode([
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->method('request')->willReturn(new Response(200, [], json_encode([
'success' => true,
])));
$validator = new Validator($mockClient);

View File

@ -46,27 +46,24 @@ class ComponentTest extends TestCase {
$this->assertNull($component->getActiveSession());
// Identity is a Oauth2Identity
$component->setIdentity(mock(LegacyOAuth2Identity::class));
$component->setIdentity($this->createMock(LegacyOAuth2Identity::class));
$this->assertNull($component->getActiveSession());
// Identity is correct, but have no jti claim
/** @var JwtIdentity|\Mockery\MockInterface $identity */
$identity = mock(JwtIdentity::class);
$identity->shouldReceive('getToken')->andReturn(new Token());
$identity = $this->createMock(JwtIdentity::class);
$identity->method('getToken')->willReturn(new Token());
$component->setIdentity($identity);
$this->assertNull($component->getActiveSession());
// Identity is correct and has jti claim, but there is no associated session
/** @var JwtIdentity|\Mockery\MockInterface $identity */
$identity = mock(JwtIdentity::class);
$identity->shouldReceive('getToken')->andReturn(new Token([], ['jti' => new Basic('jti', 999999)]));
$identity = $this->createMock(JwtIdentity::class);
$identity->method('getToken')->willReturn(new Token([], ['jti' => new Basic('jti', 999999)]));
$component->setIdentity($identity);
$this->assertNull($component->getActiveSession());
// Identity is correct, has jti claim and associated session exists
/** @var JwtIdentity|\Mockery\MockInterface $identity */
$identity = mock(JwtIdentity::class);
$identity->shouldReceive('getToken')->andReturn(new Token([], ['jti' => new Basic('jti', 1)]));
$identity = $this->createMock(JwtIdentity::class);
$identity->method('getToken')->willReturn(new Token([], ['jti' => new Basic('jti', 1)]));
$component->setIdentity($identity);
$session = $component->getActiveSession();
$this->assertNotNull($session);
@ -77,9 +74,8 @@ class ComponentTest extends TestCase {
/** @var AccountSession $session */
$session = $this->tester->grabFixture('sessions', 'admin2');
/** @var Component|\Mockery\MockInterface $component */
$component = mock(Component::class . '[getActiveSession]')->makePartial();
$component->shouldReceive('getActiveSession')->times(1)->andReturn($session);
$component = $this->createPartialMock(Component::class, ['getActiveSession']);
$component->expects($this->once())->method('getActiveSession')->willReturn($session);
/** @var Account $account */
$account = $this->tester->grabFixture('accounts', 'admin');

View File

@ -18,7 +18,7 @@ class ForgotPasswordFormTest extends TestCase {
protected function setUp(): void {
parent::setUp();
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
Yii::$container->set(ReCaptchaValidator::class, new class($this->createMock(ClientInterface::class)) extends ReCaptchaValidator {
public function validateValue($value) {
return null;
}

View File

@ -13,7 +13,6 @@ use common\tasks\SendRegistrationEmail;
use common\tests\fixtures\AccountFixture;
use common\tests\fixtures\EmailActivationFixture;
use common\tests\fixtures\UsernameHistoryFixture;
use common\tests\helpers\Mock;
use GuzzleHttp\ClientInterface;
use Yii;
use yii\validators\EmailValidator;
@ -25,7 +24,7 @@ class RegistrationFormTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->mockRequest();
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
Yii::$container->set(ReCaptchaValidator::class, new class($this->createMock(ClientInterface::class)) extends ReCaptchaValidator {
public function validateValue($value) {
return null;
}
@ -57,8 +56,8 @@ class RegistrationFormTest extends TestCase {
}
public function testSignup() {
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(EmailValidator::class, 'dns_get_record')->andReturn(['']);
$this->getFunctionMock(EmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
$this->getFunctionMock(EmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['']);
$model = new RegistrationForm([
'username' => 'some_username',
'email' => 'some_email@example.com',
@ -75,8 +74,8 @@ class RegistrationFormTest extends TestCase {
}
public function testSignupWithDefaultLanguage() {
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(EmailValidator::class, 'dns_get_record')->andReturn(['']);
$this->getFunctionMock(EmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
$this->getFunctionMock(EmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['']);
$model = new RegistrationForm([
'username' => 'some_username',
'email' => 'some_email@example.com',

View File

@ -19,7 +19,7 @@ class RepeatAccountActivationFormTest extends TestCase {
protected function setUp(): void {
parent::setUp();
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
Yii::$container->set(ReCaptchaValidator::class, new class($this->createMock(ClientInterface::class)) extends ReCaptchaValidator {
public function validateValue($value) {
return null;
}

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\accounts\models;
use api\modules\accounts\models\AcceptRulesForm;
@ -9,9 +11,8 @@ use const common\LATEST_RULES_VERSION;
class AcceptRulesFormTest extends TestCase {
public function testAgreeWithLatestRules() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->rules_agreement_version = LATEST_RULES_VERSION - 1;
$model = new AcceptRulesForm($account);

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\accounts\models;
use api\modules\accounts\models\ChangeLanguageForm;
@ -8,9 +10,8 @@ use common\models\Account;
class ChangeLanguageFormTest extends TestCase {
public function testApplyLanguage() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$model = new ChangeLanguageForm($account);
$model->lang = 'ru';

View File

@ -10,7 +10,6 @@ use common\components\UserPass;
use common\helpers\Error as E;
use common\models\Account;
use Yii;
use yii\db\Transaction;
class ChangePasswordFormTest extends TestCase {
@ -57,21 +56,13 @@ class ChangePasswordFormTest extends TestCase {
}
public function testPerformAction() {
$component = mock(Component::class . '[terminateSessions]');
$component->shouldNotReceive('terminateSessions');
$component = $this->createPartialMock(Component::class, ['terminateSessions']);
$component->expects($this->never())->method('terminateSessions');
Yii::$app->set('user', $component);
$transaction = mock(Transaction::class . '[commit]');
$transaction->shouldReceive('commit');
$connection = mock(Yii::$app->db);
$connection->shouldReceive('beginTransaction')->andReturn($transaction);
Yii::$app->set('db', $connection);
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->setPassword('password_0');
$model = new ChangePasswordForm($account, [
@ -85,9 +76,8 @@ class ChangePasswordFormTest extends TestCase {
$this->assertTrue($account->validatePassword('my-new-password'), 'new password should be successfully stored into account');
$this->assertGreaterThanOrEqual($callTime, $account->password_changed_at, 'password change time updated');
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->email = 'mock@ely.by';
$account->password_hash_strategy = Account::PASS_HASH_STRATEGY_OLD_ELY;
$account->password_hash = UserPass::make($account->email, '12345678');
@ -106,14 +96,12 @@ class ChangePasswordFormTest extends TestCase {
}
public function testPerformActionWithLogout() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->setPassword('password_0');
/** @var Component|\Mockery\MockInterface $component */
$component = mock(Component::class . '[terminateSessions]');
$component->shouldReceive('terminateSessions')->once()->withArgs([$account, Component::KEEP_CURRENT_SESSION]);
$component = $this->createPartialMock(Component::class, ['terminateSessions']);
$component->expects($this->once())->method('terminateSessions')->with($account, Component::KEEP_CURRENT_SESSION);
Yii::$app->set('user', $component);

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\accounts\models;
use api\modules\accounts\models\DisableTwoFactorAuthForm;
@ -9,16 +11,15 @@ use common\models\Account;
class DisableTwoFactorAuthFormTest extends TestCase {
public function testPerformAction() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class)->makePartial();
$account->shouldReceive('save')->once()->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->expects($this->once())->method('save')->willReturn(true);
$account->is_otp_enabled = true;
$account->otp_secret = 'mock secret';
/** @var DisableTwoFactorAuthForm|\Mockery\MockInterface $model */
$model = mock(DisableTwoFactorAuthForm::class . '[validate]', [$account]);
$model->shouldReceive('validate')->once()->andReturn(true);
$model = $this->createPartialMock(DisableTwoFactorAuthForm::class, ['getAccount', 'validate']);
$model->method('getAccount')->willReturn($account);
$model->expects($this->once())->method('validate')->willReturn(true);
$this->assertTrue($model->performAction());
$this->assertNull($account->otp_secret);

View File

@ -13,21 +13,18 @@ use Yii;
class EnableTwoFactorAuthFormTest extends TestCase {
public function testPerformAction() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->is_otp_enabled = false;
$account->otp_secret = 'mock secret';
/** @var Component|\Mockery\MockInterface $component */
$component = mock(Component::class . '[terminateSessions]');
$component->shouldReceive('terminateSessions')->withArgs([$account, Component::KEEP_CURRENT_SESSION]);
$component = $this->createPartialMock(Component::class, ['terminateSessions']);
$component->method('terminateSessions')->with($account, Component::KEEP_CURRENT_SESSION);
Yii::$app->set('user', $component);
/** @var EnableTwoFactorAuthForm|\Mockery\MockInterface $model */
$model = mock(EnableTwoFactorAuthForm::class . '[validate]', [$account]);
$model->shouldReceive('validate')->andReturn(true);
$model = $this->createPartialMock(EnableTwoFactorAuthForm::class, ['getAccount', 'validate']);
$model->method('getAccount')->willReturn($account);
$model->expects($this->once())->method('validate')->willReturn(true);
$this->assertTrue($model->performAction());
$this->assertTrue($account->is_otp_enabled);

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\accounts\models;
use api\modules\accounts\models\SendNewEmailVerificationForm;
@ -9,7 +11,6 @@ use common\models\EmailActivation;
use common\tasks\SendNewEmailConfirmation;
use common\tests\fixtures\AccountFixture;
use common\tests\fixtures\EmailActivationFixture;
use common\tests\helpers\Mock;
use yii\validators\EmailValidator;
class SendNewEmailVerificationFormTest extends TestCase {
@ -42,7 +43,7 @@ class SendNewEmailVerificationFormTest extends TestCase {
'key' => $key,
'email' => 'my-new-email@ely.by',
]);
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true);
$this->getFunctionMock(EmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
$this->assertTrue($model->performAction());
$this->assertNull(EmailActivation::findOne($key));
/** @var EmailActivation $activation */

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\accounts\models;
use api\modules\accounts\models\TwoFactorAuthInfo;
@ -8,9 +10,8 @@ use common\models\Account;
class TwoFactorAuthInfoTest extends TestCase {
public function testGetCredentials() {
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->email = 'mock@email.com';
$account->otp_secret = null;
@ -18,7 +19,7 @@ class TwoFactorAuthInfoTest extends TestCase {
$model = new TwoFactorAuthInfo($account);
$result = $model->getCredentials();
$this->assertTrue(is_array($result));
$this->assertIsArray($result);
$this->assertArrayHasKey('qr', $result);
$this->assertArrayHasKey('uri', $result);
$this->assertArrayHasKey('secret', $result);
@ -31,9 +32,8 @@ class TwoFactorAuthInfoTest extends TestCase {
libxml_use_internal_errors($previous);
$this->assertEmpty(libxml_get_errors());
/** @var Account|\Mockery\MockInterface $account */
$account = mock(Account::class . '[save]');
$account->shouldReceive('save')->andReturn(true);
$account = $this->createPartialMock(Account::class, ['save']);
$account->method('save')->willReturn(true);
$account->email = 'mock@email.com';
$account->otp_secret = 'AAAA';

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\oauth\models;
use api\modules\oauth\models\BaseOauthClientType;
@ -10,9 +12,7 @@ class BaseOauthClientTypeTest extends TestCase {
public function testApplyTyClient(): void {
$client = new OauthClient();
/** @var BaseOauthClientType|\Mockery\MockInterface $form */
$form = mock(BaseOauthClientType::class);
$form->makePartial();
$form = $this->getMockForAbstractClass(BaseOauthClientType::class);
$form->name = 'Application name';
$form->websiteUrl = 'http://example.com';

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\oauth\models;
use api\modules\oauth\models\OauthClientForm;
@ -10,24 +12,19 @@ use common\tasks\ClearOauthSessions;
class OauthClientFormTest extends TestCase {
public function testSave() {
/** @var OauthClient|\Mockery\MockInterface $client */
$client = mock(OauthClient::class . '[save]');
$client->shouldReceive('save')->andReturn(true);
$client = $this->createPartialMock(OauthClient::class, ['save']);
$client->method('save')->willReturn(true);
$client->account_id = 1;
$client->type = OauthClient::TYPE_APPLICATION;
$client->name = 'Test application';
/** @var OauthClientForm|\Mockery\MockInterface $form */
$form = mock(OauthClientForm::class . '[isClientExists]', [$client]);
$form->shouldAllowMockingProtectedMethods();
$form->shouldReceive('isClientExists')
->times(3)
->andReturnValues([true, true, false]);
$form = $this->createPartialMock(OauthClientForm::class, ['getClient', 'isClientExists']);
$form->method('getClient')->willReturn($client);
$form->expects($this->exactly(3))->method('isClientExists')->willReturnOnConsecutiveCalls(true, true, false);
/** @var OauthClientTypeForm|\Mockery\MockInterface $requestType */
$requestType = mock(OauthClientTypeForm::class);
$requestType->shouldReceive('validate')->once()->andReturn(true);
$requestType->shouldReceive('applyToClient')->once()->withArgs([$client]);
$requestType = $this->createMock(OauthClientTypeForm::class);
$requestType->expects($this->once())->method('validate')->willReturn(true);
$requestType->expects($this->once())->method('applyToClient')->with($client);
$this->assertTrue($form->save($requestType));
$this->assertSame('test-application2', $client->id);
@ -36,9 +33,8 @@ class OauthClientFormTest extends TestCase {
}
public function testSaveUpdateExistsModel() {
/** @var OauthClient|\Mockery\MockInterface $client */
$client = mock(OauthClient::class . '[save]');
$client->shouldReceive('save')->andReturn(true);
$client = $this->createPartialMock(OauthClient::class, ['save']);
$client->method('save')->willReturn(true);
$client->setIsNewRecord(false);
$client->id = 'application-id';
$client->secret = 'application_secret';
@ -49,10 +45,9 @@ class OauthClientFormTest extends TestCase {
$client->redirect_uri = 'http://example.com/oauth/ely';
$client->website_url = 'http://example.com';
/** @var OauthClientForm|\Mockery\MockInterface $form */
$form = mock(OauthClientForm::class . '[isClientExists]', [$client]);
$form->shouldAllowMockingProtectedMethods();
$form->shouldReceive('isClientExists')->andReturn(false);
$form = $this->createPartialMock(OauthClientForm::class, ['getClient', 'isClientExists']);
$form->method('getClient')->willReturn($client);
$form->method('isClientExists')->willReturn(false);
$request = new class implements OauthClientTypeForm {
public function load($data): bool {
@ -83,11 +78,10 @@ class OauthClientFormTest extends TestCase {
}
public function testDelete() {
/** @var OauthClient|\Mockery\MockInterface $client */
$client = mock(OauthClient::class . '[save]');
$client = $this->createPartialMock(OauthClient::class, ['save']);
$client->method('save')->willReturn(true);
$client->id = 'mocked-id';
$client->type = OauthClient::TYPE_APPLICATION;
$client->shouldReceive('save')->andReturn(true);
$form = new OauthClientForm($client);
$this->assertTrue($form->delete());
@ -100,12 +94,11 @@ class OauthClientFormTest extends TestCase {
}
public function testReset() {
/** @var OauthClient|\Mockery\MockInterface $client */
$client = mock(OauthClient::class . '[save]');
$client = $this->createPartialMock(OauthClient::class, ['save']);
$client->method('save')->willReturn(true);
$client->id = 'mocked-id';
$client->secret = 'initial_secret';
$client->type = OauthClient::TYPE_APPLICATION;
$client->shouldReceive('save')->andReturn(true);
$form = new OauthClientForm($client);
$this->assertTrue($form->reset());
@ -118,12 +111,11 @@ class OauthClientFormTest extends TestCase {
}
public function testResetWithSecret() {
/** @var OauthClient|\Mockery\MockInterface $client */
$client = mock(OauthClient::class . '[save]');
$client = $this->createPartialMock(OauthClient::class, ['save']);
$client->method('save')->willReturn(true);
$client->id = 'mocked-id';
$client->secret = 'initial_secret';
$client->type = OauthClient::TYPE_APPLICATION;
$client->shouldReceive('save')->andReturn(true);
$form = new OauthClientForm($client);
$this->assertTrue($form->reset(true));

View File

@ -22,9 +22,8 @@ class AccountOwnerTest extends TestCase {
$this->assertFalse($rule->execute('some token', $item, ['accountId' => 123]));
// Identity presented, but have no account
/** @var IdentityInterface|\Mockery\MockInterface $identity */
$identity = mock(IdentityInterface::class);
$identity->shouldReceive('getAccount')->andReturn(null);
$identity = $this->createMock(IdentityInterface::class);
$identity->method('getAccount')->willReturn(null);
Yii::$app->user->setIdentity($identity);
$this->assertFalse($rule->execute('some token', $item, ['accountId' => 123]));
@ -35,9 +34,8 @@ class AccountOwnerTest extends TestCase {
$account->status = Account::STATUS_ACTIVE;
$account->rules_agreement_version = LATEST_RULES_VERSION;
/** @var IdentityInterface|\Mockery\MockInterface $identity */
$identity = mock(IdentityInterface::class);
$identity->shouldReceive('getAccount')->andReturn($account);
$identity = $this->createMock(IdentityInterface::class);
$identity->method('getAccount')->willReturn($account);
Yii::$app->user->setIdentity($identity);

View File

@ -33,9 +33,8 @@ class OauthClientOwnerTest extends TestCase {
$this->assertFalse($rule->execute('some token', $item, ['clientId' => 'ely']));
// Client exists, identity presented, but have no account
/** @var IdentityInterface|\Mockery\MockInterface $identity */
$identity = mock(IdentityInterface::class);
$identity->shouldReceive('getAccount')->andReturn(null);
$identity = $this->createMock(IdentityInterface::class);
$identity->method('getAccount')->willReturn(null);
Yii::$app->user->setIdentity($identity);
$this->assertFalse($rule->execute('some token', $item, ['clientId' => 'ely']));
@ -46,9 +45,8 @@ class OauthClientOwnerTest extends TestCase {
$account->status = Account::STATUS_ACTIVE;
$account->rules_agreement_version = LATEST_RULES_VERSION;
/** @var IdentityInterface|\Mockery\MockInterface $identity */
$identity = mock(IdentityInterface::class);
$identity->shouldReceive('getAccount')->andReturn($account);
$identity = $this->createMock(IdentityInterface::class);
$identity->method('getAccount')->willReturn($account);
Yii::$app->user->setIdentity($identity);
$this->assertTrue($rule->execute('token', $item, ['clientId' => 'admin-oauth-client']));

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace codeception\api\unit\validators;
use api\rbac\Permissions as P;
@ -26,9 +28,8 @@ class PasswordRequiredValidatorTest extends TestCase {
$this->assertNull($this->callProtected($model, 'validateValue', '12345678'));
// Skip validation if user can skip identity verification
/** @var User|\Mockery\MockInterface $component */
$component = mock(User::class . '[can]', [['identityClass' => '']]);
$component->shouldReceive('can')->withArgs([P::ESCAPE_IDENTITY_VERIFICATION])->andReturn(true);
$component = $this->createPartialMock(User::class, ['can']);
$component->method('can')->with(P::ESCAPE_IDENTITY_VERIFICATION)->willReturn(true);
$model->user = $component;
$this->assertNull($this->callProtected($model, 'validateValue', ''));
}

View File

@ -1,31 +0,0 @@
<?php
namespace common\tests\_support;
use Codeception\Module;
use Codeception\TestInterface;
class Mockery extends Module {
/**
* @var bool Run mockery expectations after test or not
*/
private $assert_mocks = true;
public function _before(TestInterface $test) {
\Mockery::globalHelpers();
}
public function _after(TestInterface $test) {
if ($this->assert_mocks) {
\Mockery::close();
} else {
\Mockery::getContainer()->mockery_close();
\Mockery::resetContainer();
}
}
public function _failed(TestInterface $test, $fail) {
$this->assert_mocks = false;
}
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace common\tests\helpers;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass;
trait ExtendedPHPMock {
use PHPMock {
getFunctionMock as private getOriginalFunctionMock;
defineFunctionMock as private defineOriginalFunctionMock;
}
public function getFunctionMock($namespace, $name): MockObject {
return $this->getOriginalFunctionMock(static::getClassNamespace($namespace), $name);
}
public static function defineFunctionMock($namespace, $name) {
static::defineOriginalFunctionMock(static::getClassNamespace($namespace), $name);
}
private static function getClassNamespace(string $className): string {
return (new ReflectionClass($className))->getNamespaceName();
}
}

View File

@ -6,4 +6,3 @@ modules:
part: [orm, email, fixtures]
configFile: tests/config/unit.php
- common\tests\_support\queue\CodeceptionQueueHelper
- common\tests\_support\Mockery

View File

@ -4,19 +4,13 @@ declare(strict_types=1);
namespace common\tests\unit;
use Codeception\Test\Unit;
use Mockery;
use common\tests\helpers\ExtendedPHPMock;
/**
* @property \common\tests\UnitTester $tester
*/
class TestCase extends Unit {
/**
* @var \common\tests\UnitTester
*/
protected $tester;
protected function tearDown(): void {
parent::tearDown();
Mockery::close();
}
use ExtendedPHPMock;
/**
* A list of fixtures that will be loaded before the test, but after the database is cleaned up

View File

@ -35,7 +35,7 @@ class ClearAccountSessionsTest extends TestCase {
$bannedAccount = $this->tester->grabFixture('accounts', 'banned-account');
$task = new ClearAccountSessions();
$task->accountId = $bannedAccount->id;
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
$this->assertEmpty($bannedAccount->sessions);
$this->assertEmpty($bannedAccount->minecraftAccessKeys);
$this->assertEmpty($bannedAccount->oauthSessions);

View File

@ -36,20 +36,20 @@ class ClearOauthSessionsTest extends TestCase {
$task = new ClearOauthSessions();
$task->clientId = 'deleted-oauth-client-with-sessions';
$task->notSince = 1519510065;
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 3])->exists());
$this->assertTrue(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
$task = new ClearOauthSessions();
$task->clientId = 'deleted-oauth-client-with-sessions';
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
$task = new ClearOauthSessions();
$task->clientId = 'some-not-exists-client-id';
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
}
}

View File

@ -69,7 +69,7 @@ class CreateWebHooksDeliveriesTest extends TestCase {
'status' => 0,
],
];
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var DeliveryWebHook[] $tasks */
$tasks = $this->tester->grabQueueJobs();
$this->assertCount(2, $tasks);

View File

@ -45,7 +45,7 @@ class DeliveryWebHookTest extends TestCase {
'key' => 'value',
'another' => 'value',
];
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var Request $request */
$request = $this->historyContainer[0]['request'];
$this->assertSame('http://localhost:81/webhooks/ely', (string)$request->getUri());
@ -66,7 +66,7 @@ class DeliveryWebHookTest extends TestCase {
'key' => 'value',
'another' => 'value',
];
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var Request $request */
$request = $this->historyContainer[0]['request'];
$this->assertSame('http://localhost:81/webhooks/ely', (string)$request->getUri());
@ -87,7 +87,7 @@ class DeliveryWebHookTest extends TestCase {
'key' => 'value',
'another' => 'value',
];
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
}
public function testExecuteUnhandledException() {
@ -102,7 +102,7 @@ class DeliveryWebHookTest extends TestCase {
'key' => 'value',
'another' => 'value',
];
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
}
private function createMockedTask(): DeliveryWebHook {

View File

@ -54,7 +54,7 @@ class PullMojangUsernameTest extends TestCase {
$mojangUsernameFixture = $this->tester->grabFixture('mojangUsernames', 'Notch');
$task = new PullMojangUsername();
$task->username = 'Notch';
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne('Notch');
$this->assertInstanceOf(MojangUsername::class, $mojangUsername);
@ -69,7 +69,7 @@ class PullMojangUsernameTest extends TestCase {
$mojangUsernameFixture = $this->tester->grabFixture('mojangUsernames', 'Notch');
$task = new PullMojangUsername();
$task->username = 'Notch';
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne('Notch');
$this->assertInstanceOf(MojangUsername::class, $mojangUsername);
@ -82,7 +82,7 @@ class PullMojangUsernameTest extends TestCase {
$task = new PullMojangUsername();
$task->username = 'Chest';
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne('Chest');
$this->assertInstanceOf(MojangUsername::class, $mojangUsername);
@ -94,7 +94,7 @@ class PullMojangUsernameTest extends TestCase {
$username = $this->tester->grabFixture('mojangUsernames', 'not-exists')['username'];
$task = new PullMojangUsername();
$task->username = $username;
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne($username);
$this->assertNull($mojangUsername);
@ -108,7 +108,7 @@ class PullMojangUsernameTest extends TestCase {
$username = $mojangInfo['username'];
$task = new PullMojangUsername();
$task->username = $username;
$task->execute(mock(Queue::class));
$task->execute($this->createMock(Queue::class));
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne($username);
$this->assertInstanceOf(MojangUsername::class, $mojangUsername);

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace common\tests\unit\validators;
use common\tests\fixtures\AccountFixture;
use common\tests\helpers\Mock;
use common\tests\unit\TestCase;
use common\validators\EmailValidator;
use yii\base\Model;
@ -20,15 +19,15 @@ class EmailValidatorTest extends TestCase {
public function _before() {
parent::_before();
Mock::define(YiiEmailValidator::class, 'checkdnsrr');
Mock::define(YiiEmailValidator::class, 'dns_get_record');
self::defineFunctionMock(YiiEmailValidator::class, 'checkdnsrr');
self::defineFunctionMock(YiiEmailValidator::class, 'dns_get_record');
$this->validator = new EmailValidator();
}
public function testValidateTrimming() {
// Prevent it to access to db
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(false);
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
$model = $this->createModel("testemail@ely.by\u{feff}"); // Zero width no-break space (U+FEFF)
$this->validator->validateAttribute($model, 'field');
@ -47,7 +46,7 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeLength() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(false);
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
$model = $this->createModel(
'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' .
@ -64,8 +63,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeEmailCaseNotExistsDomain() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(false);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->times(0);
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(false);
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->never());
$model = $this->createModel('non-email@this-domain-does-not-exists.de');
$this->validator->validateAttribute($model, 'field');
@ -73,8 +72,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeEmailCaseExistsDomainButWithoutMXRecord() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturnValues([false, true]);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']);
$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']);
$model = $this->createModel('non-email@this-domain-has-no-mx-record.de');
$this->validator->validateAttribute($model, 'field');
@ -82,8 +81,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeEmailCaseExistsDomainWithMXRecord() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['mx.google.com']);
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['mx.google.com']);
$model = $this->createModel('valid-email@gmail.com');
$this->validator->validateAttribute($model, 'field');
@ -91,8 +90,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeTempmail() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']);
$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']);
$model = $this->createModel('ibrpycwyjdnt@dropmail.me');
$this->validator->validateAttribute($model, 'field');
@ -104,8 +103,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeIdna() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']);
$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']);
$model = $this->createModel('qdushyantasunassm@❕.gq');
$this->validator->validateAttribute($model, 'field');
@ -117,8 +116,8 @@ class EmailValidatorTest extends TestCase {
}
public function testValidateAttributeUnique() {
Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true);
Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']);
$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']);
$this->tester->haveFixtures([
'accounts' => AccountFixture::class,

View File

@ -39,8 +39,7 @@
"ely/php-code-style": "^0.3.0",
"flow/jsonpath": "^0.4.0",
"fzaninotto/faker": "^1.8",
"mockery/mockery": "^1.0.0",
"php-mock/php-mock-mockery": "^1.2.0",
"php-mock/php-mock-phpunit": "^2.5",
"predis/predis": "^1.1",
"roave/security-advisories": "dev-master"
},

164
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "82ac19d11c57682ccd84c9b95a4c1d63",
"content-hash": "d79b05dfd2bb6a2e053eaf534d42622e",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -3555,120 +3555,6 @@
],
"time": "2019-12-12T13:22:17+00:00"
},
{
"name": "hamcrest/hamcrest-php",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/hamcrest/hamcrest-php.git",
"reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad",
"reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad",
"shasum": ""
},
"require": {
"php": "^5.3|^7.0"
},
"replace": {
"cordoval/hamcrest-php": "*",
"davedevelopment/hamcrest-php": "*",
"kodova/hamcrest-php": "*"
},
"require-dev": {
"phpunit/php-file-iterator": "1.3.3",
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"classmap": [
"hamcrest"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"description": "This is the PHP port of Hamcrest Matchers",
"keywords": [
"test"
],
"time": "2016-01-20T08:20:44+00:00"
},
{
"name": "mockery/mockery",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/mockery/mockery.git",
"reference": "5571962a4f733fbb57bede39778f71647fae8e66"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mockery/mockery/zipball/5571962a4f733fbb57bede39778f71647fae8e66",
"reference": "5571962a4f733fbb57bede39778f71647fae8e66",
"shasum": ""
},
"require": {
"hamcrest/hamcrest-php": "~2.0",
"lib-pcre": ">=7.0",
"php": ">=5.6.0",
"sebastian/comparator": "^1.2.4|^3.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Mockery": "library/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Pádraic Brady",
"email": "padraic.brady@gmail.com",
"homepage": "http://blog.astrumfutura.com"
},
{
"name": "Dave Marshall",
"email": "dave.marshall@atstsolutions.co.uk",
"homepage": "http://davedevelopment.co.uk"
}
],
"description": "Mockery is a simple yet flexible PHP mock object framework",
"homepage": "https://github.com/mockery/mockery",
"keywords": [
"BDD",
"TDD",
"library",
"mock",
"mock objects",
"mockery",
"stub",
"test",
"test double",
"testing"
],
"time": "2019-11-24T07:54:50+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.9.3",
@ -3872,27 +3758,27 @@
},
{
"name": "php-mock/php-mock",
"version": "2.0.0",
"version": "2.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-mock/php-mock.git",
"reference": "22d297231118e6fd5b9db087fbe1ef866c2b95d2"
"reference": "35379d7b382b787215617f124662d9ead72c15e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-mock/php-mock/zipball/22d297231118e6fd5b9db087fbe1ef866c2b95d2",
"reference": "22d297231118e6fd5b9db087fbe1ef866c2b95d2",
"url": "https://api.github.com/repos/php-mock/php-mock/zipball/35379d7b382b787215617f124662d9ead72c15e3",
"reference": "35379d7b382b787215617f124662d9ead72c15e3",
"shasum": ""
},
"require": {
"php": ">=5.6",
"php": "^5.6 || ^7.0",
"phpunit/php-text-template": "^1"
},
"replace": {
"malkusch/php-mock": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.0"
},
"suggest": {
"php-mock/php-mock-phpunit": "Allows integration into PHPUnit testcase with the trait PHPMock."
@ -3929,7 +3815,7 @@
"test",
"test double"
],
"time": "2017-02-17T20:52:52+00:00"
"time": "2019-06-05T20:10:01+00:00"
},
{
"name": "php-mock/php-mock-integration",
@ -3985,31 +3871,31 @@
"time": "2017-02-17T21:31:34+00:00"
},
{
"name": "php-mock/php-mock-mockery",
"version": "1.3.0",
"name": "php-mock/php-mock-phpunit",
"version": "2.5.0",
"source": {
"type": "git",
"url": "https://github.com/php-mock/php-mock-mockery.git",
"reference": "d6d3df9d9232f1623f1ca3cfdaacd53415593825"
"url": "https://github.com/php-mock/php-mock-phpunit.git",
"reference": "7df4bd123ce196bbba19f142c4906c20be8ec546"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-mock/php-mock-mockery/zipball/d6d3df9d9232f1623f1ca3cfdaacd53415593825",
"reference": "d6d3df9d9232f1623f1ca3cfdaacd53415593825",
"url": "https://api.github.com/repos/php-mock/php-mock-phpunit/zipball/7df4bd123ce196bbba19f142c4906c20be8ec546",
"reference": "7df4bd123ce196bbba19f142c4906c20be8ec546",
"shasum": ""
},
"require": {
"mockery/mockery": "^1",
"php": ">=5.6",
"php-mock/php-mock-integration": "^2"
},
"require-dev": {
"phpunit/phpunit": "^4|^5"
"php": ">=7",
"php-mock/php-mock-integration": "^2",
"phpunit/phpunit": "^6 || ^7 || ^8"
},
"type": "library",
"autoload": {
"files": [
"autoload.php"
],
"psr-4": {
"phpmock\\mockery\\": "classes/"
"phpmock\\phpunit\\": "classes/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -4024,19 +3910,19 @@
"role": "Developer"
}
],
"description": "Mock built-in PHP functions (e.g. time()) with Mockery. This package relies on PHP's namespace fallback policy. No further extension is needed.",
"homepage": "https://github.com/php-mock/php-mock-mockery",
"description": "Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.",
"homepage": "https://github.com/php-mock/php-mock-phpunit",
"keywords": [
"BDD",
"TDD",
"function",
"mock",
"mockery",
"phpunit",
"stub",
"test",
"test double"
],
"time": "2018-03-27T07:00:25+00:00"
"time": "2019-10-05T21:44:04+00:00"
},
{
"name": "phpdocumentor/reflection-common",

View File

@ -4,5 +4,4 @@ modules:
- Yii2:
part: [orm, email, fixtures]
configFile: tests/config/unit.php
- common\tests\_support\Mockery
- common\tests\_support\queue\CodeceptionQueueHelper

View File

@ -4,17 +4,13 @@ declare(strict_types=1);
namespace console\tests\unit;
use Codeception\Test\Unit;
use Mockery;
use common\tests\helpers\ExtendedPHPMock;
/**
* @property \console\tests\UnitTester $tester
*/
class TestCase extends Unit {
protected function tearDown(): void {
parent::tearDown();
Mockery::close();
}
use ExtendedPHPMock;
/**
* A list of fixtures that will be loaded before the test, but after the database is cleaned up