-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
342f742
commit ef013e9
Showing
5 changed files
with
258 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Service; | ||
|
||
use App\Entity\User; | ||
use App\Interfaces\RoleInterface; | ||
use App\Model\Role; | ||
use App\Service\RoleHierarchyService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; | ||
|
||
#[CoversClass(RoleHierarchyService::class)] | ||
class RoleHierarchyServiceTest extends TestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testGetRoleNamesWithHierarchy(): void | ||
{ | ||
$user = new User(); | ||
$hierarchy = $this->createMock(RoleHierarchyInterface::class); | ||
$hierarchy->method('getReachableRoleNames') | ||
->willReturn([RoleInterface::ROLE_ADMIN]); | ||
|
||
$service = new RoleHierarchyService($hierarchy); | ||
$actual = $service->getReachableRoleNames($user); | ||
self::assertCount(1, $actual); | ||
self::assertSame([RoleInterface::ROLE_ADMIN], $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testGetRoleNamesWithNull(): void | ||
{ | ||
$hierarchy = $this->createMock(RoleHierarchyInterface::class); | ||
$service = new RoleHierarchyService($hierarchy); | ||
$actual = $service->getRoleNames(null); | ||
self::assertCount(0, $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testGetRoleNamesWithRole(): void | ||
{ | ||
$role = new Role('Fake'); | ||
$role->setRole(RoleInterface::ROLE_ADMIN); | ||
$hierarchy = $this->createMock(RoleHierarchyInterface::class); | ||
$service = new RoleHierarchyService($hierarchy); | ||
$actual = $service->getRoleNames($role); | ||
self::assertCount(1, $actual); | ||
self::assertSame([RoleInterface::ROLE_ADMIN], $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testGetRoleNamesWithUser(): void | ||
{ | ||
$user = new User(); | ||
$hierarchy = $this->createMock(RoleHierarchyInterface::class); | ||
$service = new RoleHierarchyService($hierarchy); | ||
$actual = $service->getRoleNames($user); | ||
self::assertCount(1, $actual); | ||
self::assertSame([RoleInterface::ROLE_USER], $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testHasRoleWithNull(): void | ||
{ | ||
$hierarchy = $this->createMock(RoleHierarchyInterface::class); | ||
$service = new RoleHierarchyService($hierarchy); | ||
$actual = $service->hasRole(null, RoleInterface::ROLE_USER); | ||
self::assertFalse($actual); | ||
} | ||
} |
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,136 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Service; | ||
|
||
use App\Service\SwissPostService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(SwissPostService::class)] | ||
class SwissPostServiceTest extends TestCase | ||
{ | ||
private string $databaseName; | ||
private SwissPostService $service; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->databaseName = __DIR__ . '/../Data/swiss_test.sqlite'; | ||
$this->service = new SwissPostService($this->databaseName); | ||
} | ||
|
||
public function testCount(): void | ||
{ | ||
$actual = $this->service | ||
->getTablesCount(); | ||
self::assertCount(3, $actual); | ||
self::assertArrayHasKey('state', $actual); | ||
self::assertArrayHasKey('city', $actual); | ||
self::assertArrayHasKey('street', $actual); | ||
self::assertSame(1, $actual['state']); | ||
self::assertSame(1, $actual['city']); | ||
self::assertSame(55, $actual['street']); | ||
} | ||
|
||
public function testFindAllFound(): void | ||
{ | ||
$actual = $this->service | ||
->findAll('1753'); | ||
self::assertCount(25, $actual); | ||
self::assertIsArray($actual[0]); | ||
|
||
$actual = $actual[0]; | ||
self::assertArrayHasKey('street', $actual); | ||
self::assertArrayHasKey('zip', $actual); | ||
self::assertArrayHasKey('city', $actual); | ||
self::assertArrayHasKey('state', $actual); | ||
self::assertArrayHasKey('display', $actual); | ||
} | ||
|
||
public function testFindAllNotFound(): void | ||
{ | ||
$actual = $this->service | ||
->findAll('fake'); | ||
self::assertCount(0, $actual); | ||
} | ||
|
||
public function testFindCityFound(): void | ||
{ | ||
$actual = $this->service | ||
->findCity('matran'); | ||
self::assertCount(1, $actual); | ||
self::assertIsArray($actual[0]); | ||
|
||
$actual = $actual[0]; | ||
self::assertArrayHasKey('name', $actual); | ||
self::assertArrayHasKey('zip', $actual); | ||
self::assertArrayHasKey('state', $actual); | ||
self::assertArrayHasKey('display', $actual); | ||
} | ||
|
||
public function testFindCityNotFound(): void | ||
{ | ||
$actual = $this->service | ||
->findCity('fake'); | ||
self::assertCount(0, $actual); | ||
} | ||
|
||
public function testFindStreetFound(): void | ||
{ | ||
$actual = $this->service | ||
->findStreet('route du bois'); | ||
self::assertCount(1, $actual); | ||
self::assertIsArray($actual[0]); | ||
|
||
$actual = $actual[0]; | ||
self::assertArrayHasKey('street', $actual); | ||
self::assertArrayHasKey('zip', $actual); | ||
self::assertArrayHasKey('city', $actual); | ||
self::assertArrayHasKey('state', $actual); | ||
self::assertArrayHasKey('display', $actual); | ||
} | ||
|
||
public function testFindStreetNotFound(): void | ||
{ | ||
$actual = $this->service | ||
->findStreet('fake'); | ||
self::assertCount(0, $actual); | ||
} | ||
|
||
public function testFindZipFound(): void | ||
{ | ||
$actual = $this->service | ||
->findZip('1753'); | ||
self::assertCount(1, $actual); | ||
self::assertIsArray($actual[0]); | ||
|
||
$actual = $actual[0]; | ||
self::assertArrayHasKey('zip', $actual); | ||
self::assertArrayHasKey('city', $actual); | ||
self::assertArrayHasKey('state', $actual); | ||
self::assertArrayHasKey('display', $actual); | ||
} | ||
|
||
public function testFindZipNotFound(): void | ||
{ | ||
$actual = $this->service | ||
->findZip('fake'); | ||
self::assertCount(0, $actual); | ||
} | ||
|
||
public function testGetDatabaseName(): void | ||
{ | ||
$actual = $this->service | ||
->getDatabaseName(); | ||
self::assertSame($this->databaseName, $actual); | ||
} | ||
} |