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

@ -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));