Skip to content
Permalink
Browse files

Merge pull request #106 from tarlepp/tests/coverage

Tests/Coverage improvements
  • Loading branch information...
tarlepp committed Jul 11, 2019
2 parents d9d1473 + 21a1202 commit 4d7accbcac8781318a38ea040f31b31333cac8ae
@@ -106,6 +106,24 @@ public function testThatSupportsReturnsTrueWithProperUser(): void
static::assertTrue($resolver->supports(Request::create('/'), $metadata));
}
/**
* @throws Throwable
*/
public function testThatResolveThrowsAnExceptionIfTokenIsNotPresent(): void
{
$this->expectException(MissingTokenException::class);
$this->expectExceptionMessage('JWT Token not found');
/**
* @var MockObject|UserResource $userResource
*/
$userResource = $this->getMockBuilder(UserResource::class)->disableOriginalConstructor()->getMock();
(new UserValueResolver(new TokenStorage(), $userResource))
->resolve(new Request(), new ArgumentMetadata('foo', null, false, false, null))
->current();
}
/**
* @throws Throwable
*/
@@ -9,6 +9,9 @@
namespace App\Tests\Integration\DTO\ApiKey;
use App\DTO\ApiKey\ApiKeyPatch;
use App\Entity\ApiKey;
use App\Entity\Role;
use App\Entity\UserGroup;
use App\Tests\Integration\DTO\DtoTestCase;
/**
@@ -20,4 +23,26 @@
class ApiKeyPatchTest extends DtoTestCase
{
protected $dtoClass = ApiKeyPatch::class;
public function testThatUserGroupsAreExpected(): void
{
$userGroup1 = (new UserGroup())
->setName('Group 1')
->setRole(new Role('Role 1'));
$userGroup2 = (new UserGroup())
->setName('Group 2')
->setRole(new Role('Role 2'));
$user = (new ApiKey())
->setDescription('description')
->addUserGroup($userGroup1);
$dto = (new ApiKeyPatch())->load($user)
->setUserGroups([$userGroup2]);
$updatedApiKey = $dto->update($user);
static::assertCount(2, $updatedApiKey->getUserGroups());
}
}
@@ -9,6 +9,9 @@
namespace App\Tests\Integration\DTO\ApiKey;
use App\DTO\ApiKey\ApiKeyUpdate;
use App\Entity\ApiKey;
use App\Entity\Role;
use App\Entity\UserGroup;
use App\Tests\Integration\DTO\DtoTestCase;
/**
@@ -20,4 +23,26 @@
class ApiKeyUpdateTest extends DtoTestCase
{
protected $dtoClass = ApiKeyUpdate::class;
public function testThatUserGroupsAreExpected(): void
{
$userGroup1 = (new UserGroup())
->setName('Group 1')
->setRole(new Role('Role 1'));
$userGroup2 = (new UserGroup())
->setName('Group 2')
->setRole(new Role('Role 2'));
$user = (new ApiKey())
->setDescription('description')
->addUserGroup($userGroup1);
$dto = (new ApiKeyUpdate())->load($user)
->setUserGroups([$userGroup2]);
$updatedApiKey = $dto->update($user);
static::assertCount(1, $updatedApiKey->getUserGroups());
}
}
@@ -9,6 +9,9 @@
namespace App\Tests\Integration\DTO\User;
use App\DTO\User\UserPatch;
use App\Entity\Role;
use App\Entity\User;
use App\Entity\UserGroup;
use App\Tests\Integration\DTO\DtoTestCase;
/**
@@ -20,4 +23,26 @@
class UserPatchTest extends DtoTestCase
{
protected $dtoClass = UserPatch::class;
public function testThatUserGroupsAreExpected(): void
{
$userGroup1 = (new UserGroup())
->setName('Group 1')
->setRole(new Role('Role 1'));
$userGroup2 = (new UserGroup())
->setName('Group 2')
->setRole(new Role('Role 2'));
$user = (new User())
->setUsername('username')
->addUserGroup($userGroup1);
$dto = (new UserPatch())->load($user)
->setUserGroups([$userGroup2]);
$updatedUser = $dto->update($user);
static::assertCount(2, $updatedUser->getUserGroups());
}
}
@@ -9,6 +9,9 @@
namespace App\Tests\Integration\DTO\User;
use App\DTO\User\UserUpdate;
use App\Entity\Role;
use App\Entity\User;
use App\Entity\UserGroup;
use App\Tests\Integration\DTO\DtoTestCase;
/**
@@ -20,4 +23,26 @@
class UserUpdateTest extends DtoTestCase
{
protected $dtoClass = UserUpdate::class;
public function testThatUserGroupsAreExpected(): void
{
$userGroup1 = (new UserGroup())
->setName('Group 1')
->setRole(new Role('Role 1'));
$userGroup2 = (new UserGroup())
->setName('Group 2')
->setRole(new Role('Role 2'));
$user = (new User())
->setUsername('username')
->addUserGroup($userGroup1);
$dto = (new UserUpdate())->load($user)
->setUserGroups([$userGroup2]);
$updatedUser = $dto->update($user);
static::assertCount(1, $updatedUser->getUserGroups());
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types = 1);
/**
* /tests/Unit/Entity/DateDimensionTest.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
namespace App\Tests\Unit\Entity;
use App\Entity\DateDimension;
use DateTime;
use DateTimeZone;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Throwable;
/**
* Class DateDimensionTest
*
* @package App\Tests\Unit\Entity
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
class DateDimensionTest extends KernelTestCase
{
/**
* @throws Throwable
*/
public function testThatGetCreatedAtReturnsExpected(): void
{
$dateTime = new DateTime('now', new DateTimeZone('UTC'));
$dateTime->setTime(10, 10, 10);
$entity = new DateDimension($dateTime);
static::assertSame($dateTime->format('u'), $entity->getCreatedAt()->format('u'));
}
}
@@ -0,0 +1,57 @@
<?php
declare(strict_types = 1);
/**
* /tests/Unit/Entity/LogLoginTest.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
namespace App\Tests\Unit\Entity;
use App\Doctrine\DBAL\Types\EnumLogLoginType;
use App\Entity\LogLogin;
use DateTime;
use DateTimeZone;
use DeviceDetector\DeviceDetector;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Throwable;
/**
* Class LogLoginTest
*
* @package App\Tests\Unit\Entity
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
class LogLoginTest extends KernelTestCase
{
/**
* @dataProvider dataProviderTestThatGetCreatedAtReturnsExpected
*
* @param string $type
* @param Request $request
* @param DeviceDetector $deviceDetector
*
* @throws Throwable
*/
public function testThatGetCreatedAtReturnsExpected(
string $type,
Request $request,
DeviceDetector $deviceDetector
): void {
$entity = new LogLogin($type, $request, $deviceDetector);
static::assertEqualsWithDelta(new DateTime('now', new DateTimeZone('utc')), $entity->getCreatedAt(), 0.1);
}
/**
* @return Generator
*/
public function dataProviderTestThatGetCreatedAtReturnsExpected(): Generator
{
yield [EnumLogLoginType::TYPE_SUCCESS, new Request(), new DeviceDetector('')];
yield [EnumLogLoginType::TYPE_FAILURE, new Request(), new DeviceDetector('')];
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types = 1);
/**
* /tests/Unit/Entity/LogRequestTest.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
namespace App\Tests\Unit\Entity;
use App\Entity\LogRequest;
use DateTime;
use DateTimeZone;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Throwable;
/**
* Class LogRequestTest
*
* @package App\Tests\Unit\Entity
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
class LogRequestTest extends KernelTestCase
{
/**
* @throws Throwable
*/
public function testThatGetCreatedAtReturnsExpected(): void
{
$entity = new LogRequest();
static::assertEqualsWithDelta(new DateTime('now', new DateTimeZone('utc')), $entity->getCreatedAt(), 0.1);
}
}

0 comments on commit 4d7accb

Please sign in to comment.
You can’t perform that action at this time.