Verified Commit ea54ea1f authored by Dave Long's avatar Dave Long
Browse files

test: #3569423 Convert expectation-less test mocks to stubs - User module

By: dcam
By: smustgrave
parent d275b6f1
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ protected function setUp(): void {
    parent::setUp();

    // Add services required for user local tasks.
    $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $entity_type_manager->expects($this->any())
    $entity_type_manager = $this->createStub(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->method('getDefinitions')
      ->willReturn([]);
    $this->container->set('entity_type.manager', $entity_type_manager);
+3 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Access\PermissionAccessCheck;
use PHPUnit\Framework\Attributes\CoversClass;
@@ -88,8 +89,8 @@ public function testAccess($requirements, $access, array $contexts = [], $messag
    if (!empty($message)) {
      $access_result->setReason($message);
    }
    $user = $this->createMock('Drupal\Core\Session\AccountInterface');
    $user->expects($this->any())
    $user = $this->createStub(AccountInterface::class);
    $user
      ->method('hasPermission')
      ->willReturnMap([
        ['allowed', TRUE],
+9 −6
Original line number Diff line number Diff line
@@ -126,14 +126,14 @@ public function testBuildPermissionsYaml(): void {
    );
    $modules = ['module_a', 'module_b', 'module_c'];

    $this->moduleHandler->expects($this->any())
    $this->moduleHandler
      ->method('getModuleList')
      ->willReturn(array_flip($modules));

    $this->callableResolver->expects($this->never())
      ->method('getCallableFromDefinition');

    $module_extension_list = $this->createMock(ModuleExtensionList::class);
    $module_extension_list = $this->createStub(ModuleExtensionList::class);

    $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);

@@ -155,6 +155,9 @@ public function testBuildPermissionsYaml(): void {
   * @legacy-covers ::sortPermissions
   */
  public function testBuildPermissionsSortPerModule(): void {
    $this->callableResolver->expects($this->never())
      ->method('getCallableFromDefinition');

    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
@@ -247,7 +250,7 @@ public function testBuildPermissionsYamlCallback(): void {

    $modules = ['module_a', 'module_b', 'module_c'];

    $this->moduleHandler->expects($this->any())
    $this->moduleHandler
      ->method('getModuleList')
      ->willReturn(array_flip($modules));

@@ -272,7 +275,7 @@ public function testBuildPermissionsYamlCallback(): void {
        ],
      ]);

    $module_extension_list = $this->createMock(ModuleExtensionList::class);
    $module_extension_list = $this->createStub(ModuleExtensionList::class);

    $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);

@@ -308,7 +311,7 @@ public function testPermissionsYamlStaticAndCallback(): void {

    $modules = ['module_a'];

    $this->moduleHandler->expects($this->any())
    $this->moduleHandler
      ->method('getModuleList')
      ->willReturn(array_flip($modules));

@@ -317,7 +320,7 @@ public function testPermissionsYamlStaticAndCallback(): void {
      ->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')
      ->willReturn([new TestPermissionCallbacks(), 'titleDescription']);

    $module_extension_list = $this->createMock(ModuleExtensionList::class);
    $module_extension_list = $this->createStub(ModuleExtensionList::class);

    $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);

+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ public function testExecuteAddExistingRole(): void {
      ->method('addRole')
      ->willReturn($this->account);

    $this->account->expects($this->any())
    $this->account
      ->method('hasRole')
      ->with($this->equalTo('test_role_1'))
      ->willReturn(TRUE);
@@ -42,7 +42,7 @@ public function testExecuteAddNonExistingRole(): void {
      ->method('addRole')
      ->willReturn($this->account);

    $this->account->expects($this->any())
    $this->account
      ->method('hasRole')
      ->with($this->equalTo('test_role_1'))
      ->willReturn(FALSE);
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ public function testExecuteRemoveExistingRole(): void {
      ->method('removeRole')
      ->willReturn($this->account);

    $this->account->expects($this->any())
    $this->account
      ->method('hasRole')
      ->with($this->equalTo('test_role_1'))
      ->willReturn(TRUE);
@@ -42,7 +42,7 @@ public function testExecuteRemoveNonExistingRole(): void {
      ->method('removeRole')
      ->willReturn($this->account);

    $this->account->expects($this->any())
    $this->account
      ->method('hasRole')
      ->with($this->equalTo('test_role_1'))
      ->willReturn(FALSE);
Loading