Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1504 from tarlepp/chore(tests)/refactor-missing-t…
…ests Chore(tests) - Added more integrationd tests
- Loading branch information
Showing
18 changed files
with
834 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/Integration/Controller/v1/Profile/GroupsControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/** | ||
* /tests/Integration/Controller/v1/Profile/GroupsControllerTest.php | ||
* | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
|
||
namespace App\Tests\Integration\Controller\v1\Profile; | ||
|
||
use App\Controller\v1\Profile\GroupsController; | ||
use App\Entity\User; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Class GroupsControllerTest | ||
* | ||
* @package App\Tests\Integration\Controller\v1\Profile | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
class GroupsControllerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @throws Throwable | ||
* | ||
* @testdox Test that `__invoke(User $loggedInUser)` method calls expected service methods | ||
*/ | ||
public function testThatInvokeMethodCallsExpectedMethods(): void | ||
{ | ||
$user = new User(); | ||
|
||
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); | ||
|
||
$serializer | ||
->expects(self::once()) | ||
->method('serialize') | ||
->with( | ||
$user->getUserGroups()->toArray(), | ||
'json', | ||
[ | ||
'groups' => 'set.UserProfileGroups', | ||
], | ||
) | ||
->willReturn('{}'); | ||
|
||
(new GroupsController($serializer))($user); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/Integration/Controller/v1/Profile/IndexControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/** | ||
* /tests/Integration/Controller/v1/Profile/IndexControllerTest.php | ||
* | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
|
||
namespace App\Tests\Integration\Controller\v1\Profile; | ||
|
||
use App\Controller\v1\Profile\IndexController; | ||
use App\Entity\User; | ||
use App\Security\RolesService; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Class IndexControllerTest | ||
* | ||
* @package App\Tests\Integration\Controller\v1\Profile | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
class IndexControllerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @throws Throwable | ||
* | ||
* @testdox Test that `__invoke(User $loggedInUser)` method calls expected service methods | ||
*/ | ||
public function testThatInvokeMethodCallsExpectedMethods(): void | ||
{ | ||
$user = new User(); | ||
|
||
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); | ||
|
||
$rolesService = $this->getMockBuilder(RolesService::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$serializer | ||
->expects(self::once()) | ||
->method('serialize') | ||
->with( | ||
$user, | ||
'json', | ||
[ | ||
'groups' => 'set.UserProfile', | ||
], | ||
) | ||
->willReturn('{"roles": ["foo", "bar"]}'); | ||
|
||
$rolesService | ||
->expects(self::once()) | ||
->method('getInheritedRoles') | ||
->with(['foo', 'bar']) | ||
->willReturn(['foo', 'bar']); | ||
|
||
(new IndexController($serializer, $rolesService))($user); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
tests/Integration/Controller/v1/Profile/ProfileControllerTest.php
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
tests/Integration/Controller/v1/Profile/RolesControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/** | ||
* /tests/Integration/Controller/v1/Profile/RolesControllerTest.php | ||
* | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
|
||
namespace App\Tests\Integration\Controller\v1\Profile; | ||
|
||
use App\Controller\v1\Profile\RolesController; | ||
use App\Entity\User; | ||
use App\Security\RolesService; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Throwable; | ||
|
||
/** | ||
* Class RolesControllerTest | ||
* | ||
* @package App\Tests\Integration\Controller\v1\Profile | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
class RolesControllerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @throws Throwable | ||
* | ||
* @testdox Test that `__invoke(User $loggedInUser)` method calls expected service methods | ||
*/ | ||
public function testThatInvokeMethodCallsExpectedMethods(): void | ||
{ | ||
$user = new User(); | ||
|
||
$rolesService = $this->getMockBuilder(RolesService::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$rolesService | ||
->expects(self::once()) | ||
->method('getInheritedRoles') | ||
->with($user->getRoles()) | ||
->willReturn([]); | ||
|
||
(new RolesController($rolesService))->__invoke($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/Integration/Controller/v1/Role/InheritedRolesControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/** | ||
* /tests/Integration/Controller/v1/Role/InheritedRolesControllerTest.php | ||
* | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
|
||
namespace App\Tests\Integration\Controller\v1\Role; | ||
|
||
use App\Controller\v1\Role\InheritedRolesController; | ||
use App\Entity\Role; | ||
use App\Security\RolesService; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
/** | ||
* Class InheritedRolesControllerTest | ||
* | ||
* @package App\Tests\Integration\Controller\v1\Role | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
class InheritedRolesControllerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @testdox Test that `__invoke($role)` method calls expected service methods | ||
*/ | ||
public function testThatInvokeMethodCallsExpectedMethods(): void | ||
{ | ||
$rolesService = $this->getMockBuilder(RolesService::class)->disableOriginalConstructor()->getMock(); | ||
$role = new Role('Test'); | ||
|
||
$rolesService | ||
->expects(self::once()) | ||
->method('getInheritedRoles') | ||
->with([$role->getId()]) | ||
->willReturn([$role]); | ||
|
||
(new InheritedRolesController($rolesService))($role); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/Integration/Controller/v1/User/AttachUserGroupControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/** | ||
* /tests/Integration/Controller/v1/User/AttachUserGroupControllerTest.php | ||
* | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
|
||
namespace App\Tests\Integration\Controller\v1\User; | ||
|
||
use App\Controller\v1\User\AttachUserGroupController; | ||
use App\Entity\Role; | ||
use App\Entity\User; | ||
use App\Entity\UserGroup; | ||
use App\Resource\UserGroupResource; | ||
use App\Resource\UserResource; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Class AttachUserGroupControllerTest | ||
* | ||
* @package App\Tests\Integration\Controller\v1\User | ||
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> | ||
*/ | ||
class AttachUserGroupControllerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @throws Throwable | ||
* | ||
* @testdox Test that `__invoke($user, $userGroup)` method calls expected service methods | ||
*/ | ||
public function testThatInvokeMethodCallsExpectedMethods(): void | ||
{ | ||
$userResource = $this->getMockBuilder(UserResource::class)->disableOriginalConstructor()->getMock(); | ||
$userGroupResource = $this->getMockBuilder(UserGroupResource::class)->disableOriginalConstructor()->getMock(); | ||
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); | ||
|
||
$user = new User(); | ||
$userGroup = (new UserGroup())->setRole(new Role('role')); | ||
|
||
$userResource | ||
->expects(self::once()) | ||
->method('save') | ||
->with($user, false) | ||
->willReturn($user); | ||
|
||
$userGroupResource | ||
->expects(self::once()) | ||
->method('save') | ||
->with($userGroup, true, true) | ||
->willReturn($userGroup); | ||
|
||
$serializer | ||
->expects(self::once()) | ||
->method('serialize') | ||
->willReturn('[]'); | ||
|
||
(new AttachUserGroupController($userResource, $userGroupResource, $serializer))($user, $userGroup); | ||
|
||
self::assertTrue( | ||
$user->getUserGroups()->contains($userGroup), | ||
'User entity does not have expected user group', | ||
); | ||
|
||
self::assertTrue( | ||
$userGroup->getUsers()->contains($user), | ||
'UserGroup entity does not have expected user', | ||
); | ||
} | ||
} |
Oops, something went wrong.