Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
test(refactor): removed AbstractFormValidationTestCase.php and use …
Browse files Browse the repository at this point in the history
…`FormServiceManager`
  • Loading branch information
sanakhandvsa committed Jan 10, 2024
1 parent 539684d commit e5bc57a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1,400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Common\Form\Element\DynamicMultiCheckbox;
use Common\Form\Element\DynamicRadio;
use Common\Form\Element\DynamicSelect;
use Common\FormService\FormServiceManager;
use Common\Service\Translator\TranslationLoader;
use Laminas\I18n\Translator\LoaderPluginManager;
use Laminas\I18n\View\Helper\Translate;
Expand All @@ -13,7 +14,6 @@
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use OlcsTest\FormService\Form\Lva\Stub\AbstractOverviewSubmissionStub;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;

/**
* @covers Olcs\FormService\Form\Lva\AbstractOverviewSubmission
Expand All @@ -23,29 +23,17 @@ class AbstractOverviewSubmissionTest extends MockeryTestCase
/** @var AbstractOverviewSubmissionStub */
private $sut;

/** @var m\MockInterface */
private $mockSm;
/** @var m\MockInterface | \Laminas\Form\FormInterface */
private $mockForm;
/** @var m\MockInterface | \Common\Service\Helper\FormHelperService */
private $mockFormHlp;

private $mockTranslationHelper;

/**
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}

public function setUp(): void
{
$this->mockForm = m::mock(\Laminas\Form\FormInterface::class);

$this->mockSm = $this->getServiceManager();

$this->mockTranslationHelper = m::mock(Translate::class);
$this->mockTranslationHelper
->shouldReceive('translateReplace')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Laminas\Form\Form;
use Laminas\Http\Request;
use OlcsTest\FormService\Form\Lva\Traits\ButtonsAlterations;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;
use ZfcRbac\Service\AuthorizationService;

/**
Expand All @@ -44,28 +43,18 @@ class ApplicationFinancialEvidenceTest extends MockeryTestCase
/** @var m\MockInterface */
protected $translator;

/**
* Added this method for backwards compatibility
*
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}

public function setUp(): void
{
$this->fh = m::mock(FormHelperService::class)->makePartial();
$this->fsm = m::mock(\Common\FormService\FormServiceManager::class)->makePartial();
$this->urlHelper = m::mock(UrlHelperService::class);
$this->translator = m::mock(TranslationHelperService::class);

$sm = $this->getServiceManager();
$sm->setService('Helper\Url', $this->urlHelper);
$sm->setService('Helper\Translation', $this->translator);

$this->fsm->shouldReceive('getServiceLocator')->andReturn($sm);
$this->fsm->setService('Helper\Url', $this->urlHelper);
$this->fsm->setService('Helper\Translation', $this->translator);

$this->fsm->shouldReceive('getServiceLocator')->andReturn($this->fsm);

$this->sut = new ApplicationFinancialEvidence($this->fh, m::mock(AuthorizationService::class), $this->translator, $this->urlHelper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Laminas\Form\Form;
use Common\Service\Helper\FormHelperService;
use Common\RefData;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;
use ZfcRbac\Service\AuthorizationService;

class VariationOperatingCentresTest extends MockeryTestCase
Expand All @@ -38,31 +37,17 @@ class VariationOperatingCentresTest extends MockeryTestCase

protected $translator;

/**
* We can access service manager if we need to add a mock for certain applications
*
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}

public function setUp(): void
{
$this->tableBuilder = m::mock();

$this->translator = m::mock(TranslationHelperService::class);

$sm = $this->getServiceManager();
$sm->setService('Table', $this->tableBuilder);
$sm->setService('Helper\Translation', $this->translator);
$this->form = m::mock(Form::class);

$fsm = m::mock(FormServiceManager::class)->makePartial();
$fsm->shouldReceive('getServiceLocator')
->andReturn($sm);

$this->form = m::mock(Form::class);
$fsm->setService('Table', $this->tableBuilder);
$fsm->setService('Helper\Translation', $this->translator);
$fsm->allows('getServiceLocator')
->andReturns($this->form);

$lvaVariation = m::mock(Form::class);
$lvaVariation->shouldReceive('alterForm')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Common\Service\Helper\FormHelperService;
use Common\Service\Lva\PeopleLvaService;
use Common\Service\Translator\TranslationLoader;
use Laminas\Form\Form;
use Laminas\I18n\Translator\LoaderPluginManager;
use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\ServiceManager\ServiceManager;
Expand All @@ -18,7 +19,6 @@
use Olcs\FormService\Form\Lva\People\SoleTrader\ApplicationSoleTrader as Sut;
use OlcsTest\FormService\Form\Lva\Traits\ButtonsAlterations;
use Laminas\ServiceManager\ServiceLocatorInterface;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;
use ZfcRbac\Service\AuthorizationService;

class ApplicationSoleTraderTest extends MockeryTestCase
Expand Down Expand Up @@ -49,25 +49,15 @@ class ApplicationSoleTraderTest extends MockeryTestCase
* @var PeopleLvaService|(PeopleLvaService&m\LegacyMockInterface)|(PeopleLvaService&m\MockInterface)|m\LegacyMockInterface|m\MockInterface
*/
private $peopleLvaService;

/**
* Added this method for backwards compatibility
*
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}
public function setUp(): void
{
$this->formHelper = m::mock('\Common\Service\Helper\FormHelperService');

$this->sm = $this->getServiceManager();
$this->form = m::mock(Form::class);

/** @var FormServiceManager fsm */
$this->fsm = m::mock('\Common\FormService\FormServiceManager')->makePartial();
$this->fsm->setServiceLocator($this->sm);
$this->fsm->allows('getServiceLocator')
->andReturns($this->form);

$this->peopleLvaService = m::mock(PeopleLvaService::class);

Expand Down Expand Up @@ -191,9 +181,7 @@ public function testGetFormCantModify()
$this->peopleLvaService->shouldReceive('lockPersonForm')
->once()
->with($form, 'bar');

$this->sm->setService('Lva\People', $this->peopleLvaService);

$this->fsm->setService('Lva\People', $this->peopleLvaService);
$this->sut->getForm($params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Olcs\FormService\Form\Lva\People\SoleTrader\LicenceSoleTrader as Sut;
use Laminas\Form\Form;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;
use ZfcRbac\Service\AuthorizationService;

class LicenceSoleTraderTest extends MockeryTestCase
Expand All @@ -31,28 +30,18 @@ class LicenceSoleTraderTest extends MockeryTestCase
protected $mockLicenceService;
private $peopleLvaService;

/**
* We can access service manager if we need to add a mock for certain applications
*
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}

public function setUp(): void
{
$this->formHelper = m::mock('\Common\Service\Helper\FormHelperService');
$this->form = m::mock(Form::class);

$this->mockLicenceService = m::mock(Form::class);
$this->peopleLvaService = m::mock(PeopleLvaService::class);

$this->sm = $this->getServiceManager();

/** @var FormServiceManager fsm */
$this->fsm = m::mock('\Common\FormService\FormServiceManager')->makePartial();
$this->fsm->setServiceLocator($this->sm);
$this->fsm->allows('getServiceLocator')
->andReturns($this->form);
$this->fsm->setService('lva-licence', $this->mockLicenceService);

$this->sut = new Sut($this->formHelper, m::mock(AuthorizationService::class), $this->peopleLvaService, $this->fsm);
Expand Down Expand Up @@ -170,7 +159,7 @@ public function testGetFormCantModify()
->once()
->with($form, 'bar');

$this->sm->setService('Lva\People', $this->peopleLvaService);
$this->fsm->setService('Lva\People', $this->peopleLvaService);

$this->sut->getForm($params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Olcs\FormService\Form\Lva\People\SoleTrader\VariationSoleTrader as Sut;
use Laminas\Form\Form;
use OlcsTest\TestHelpers\AbstractFormValidationTestCase;
use ZfcRbac\Service\AuthorizationService;

/**
Expand All @@ -38,8 +37,6 @@ public function setUp(): void

$this->mockVariationService = m::mock(Form::class);

$this->sm = $this->getServiceManager();

/** @var FormServiceManager fsm */
$this->fsm = m::mock('\Common\FormService\FormServiceManager')->makePartial();
$this->peopleLvaService = m::mock(PeopleLvaService::class);
Expand All @@ -49,16 +46,6 @@ public function setUp(): void
$this->sut = new Sut($this->formHelper, m::mock(AuthorizationService::class), $this->peopleLvaService, $this->fsm);
}

/**
* Added this method for backwards compatibility
*
* @return \Laminas\ServiceManager\ServiceManager
*/
public function getServiceManager()
{
return AbstractFormValidationTestCase::getRealServiceManager();
}

/**
* @dataProvider noDisqualifyProvider
*/
Expand Down
Loading

0 comments on commit e5bc57a

Please sign in to comment.