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

Commit

Permalink
fix: remove real servicemanager from unit tests (#48)
Browse files Browse the repository at this point in the history
* test(refactor): removed servicemanager and refactored accordingly

* test(refactor): removed servicemanager and refactored accordingly

* test(refactor): removed servicemanager and refactored accordingly

* test(refactor): removed servicemanager and refactored accordingly

* test(refactor): removed servicemanager and refactored accordingly

* refactor(tests): separate LoginController initialization from setUp in LoginControllerTest

* refactor(tests): separate SwitchBoardControllerTest initialization from setUp in LoginControllerTest and Remove unnecessary mock container setup in setupSut method

* refactor(tests): separate SessionTimeoutControllerTest initialization from setUp

* refactor(tests): separate ListVehicleController initialization from setUp

---------

Co-authored-by: JoshuaLicense <[email protected]>
  • Loading branch information
sanakhandvsa and JoshuaLicense authored Feb 23, 2024
1 parent a03768e commit e7247ca
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 641 deletions.
40 changes: 15 additions & 25 deletions test/Olcs/src/Controller/Auth/LoginControllerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,16 @@
use Olcs\Auth\Adapter\SelfserveCommandAdapter;
use Olcs\Controller\Auth\LoginController;
use Olcs\Controller\Auth\LoginControllerFactory;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Common\Test\MocksServicesTrait;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class LoginControllerFactoryTest extends MockeryTestCase
class LoginControllerFactoryTest extends TestCase
{
use MocksServicesTrait;

/**
* @var LoginControllerFactory
*/
protected $sut;

public function setUp(): void
{
$this->setUpServiceManager();
}

/**
* @test
*/
Expand All @@ -53,9 +45,21 @@ public function __invoke_ReturnsAnInstanceOfDispatcherWithLoginController()
{
// Setup
$this->setUpSut();
$serviceManager = $this->createMock(\Interop\Container\ContainerInterface::class);
$serviceManager->method('get')->willReturnMap([
[SelfserveCommandAdapter::class, $this->createMock(SelfserveCommandAdapter::class)],
[AuthenticationServiceInterface::class , $this->createMock(AuthenticationServiceInterface::class)],
['Auth\CookieService', $this->createMock(CookieService::class)],
[CurrentUser::class, $this->createMock(CurrentUser::class)],
[FlashMessenger::class, $this->createMock(FlashMessenger::class)],
[FormHelperService::class, $this->createMock(FormHelperService::class)],
[Redirect::class, $this->createMock(Redirect::class)],
[Url::class, $this->createMock(Url::class)],
['ControllerPluginManager', $serviceManager]
]);

// Execute
$result = $this->sut->__invoke($this->serviceManager(), null);
$result = $this->sut->__invoke($serviceManager, null);

// Assert
$this->assertInstanceOf(Dispatcher::class, $result);
Expand All @@ -67,18 +71,4 @@ protected function setUpSut(): void
$this->sut = new LoginControllerFactory();
}

/**
* @param ServiceManager $serviceManager
*/
protected function setUpDefaultServices(ServiceManager $serviceManager)
{
$serviceManager->setService(SelfserveCommandAdapter::class, $this->setUpMockService(SelfserveCommandAdapter::class));
$serviceManager->setService(AuthenticationServiceInterface::class, $this->setUpMockService(AuthenticationServiceInterface::class));
$serviceManager->setService('Auth\CookieService', $this->setUpMockService(CookieService::class));
$serviceManager->setService(CurrentUser::class, $this->setUpMockService(CurrentUser::class));
$serviceManager->setService(FlashMessenger::class, $this->setUpMockService(FlashMessenger::class));
$serviceManager->setService(FormHelperService::class, $this->setUpMockService(FormHelperService::class));
$serviceManager->setService(Redirect::class, $this->setUpMockService(Redirect::class));
$serviceManager->setService(Url::class, $this->setUpMockService(Url::class));
}
}
Loading

0 comments on commit e7247ca

Please sign in to comment.