-
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.
Continue add unit tests for service.
- Loading branch information
1 parent
00d7238
commit 342f742
Showing
8 changed files
with
440 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
classDiagram | ||
class NoTitle { | ||
} |
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,10 @@ | ||
--- | ||
title: User | ||
--- | ||
classDiagram | ||
class UserInterface { | ||
<<Interface>> | ||
+getRoles() array | ||
+getUserIdentifier() string | ||
+eraseCredentials() | ||
} |
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
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,78 @@ | ||
<?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\DiagramService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Cache\InvalidArgumentException; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
#[CoversClass(DiagramService::class)] | ||
class DiagramServiceTest extends TestCase | ||
{ | ||
private DiagramService $service; | ||
|
||
protected function setUp(): void | ||
{ | ||
$path = __DIR__ . '/../Data/diagrams'; | ||
$cache = new ArrayAdapter(); | ||
$this->service = new DiagramService($path, $cache); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testCount(): void | ||
{ | ||
$files = $this->service->getFiles(); | ||
self::assertCount(2, $files); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testGetFileFound(): void | ||
{ | ||
$expected = 'user'; | ||
$actual = $this->service->getFile($expected); | ||
self::assertIsArray($actual); | ||
self::assertArrayHasKey('name', $actual); | ||
self::assertArrayHasKey('title', $actual); | ||
self::assertArrayHasKey('content', $actual); | ||
self::assertSame($expected, $actual['name']); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testGetFileNotFound(): void | ||
{ | ||
$actual = $this->service->getFile('fake_name'); | ||
self::assertNull($actual); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testGetFileNoTitle(): void | ||
{ | ||
$expected = 'no_title'; | ||
$actual = $this->service->getFile($expected); | ||
self::assertIsArray($actual); | ||
self::assertArrayHasKey('name', $actual); | ||
self::assertArrayHasKey('title', $actual); | ||
self::assertArrayHasKey('content', $actual); | ||
self::assertSame($expected, $actual['name']); | ||
} | ||
} |
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,49 @@ | ||
<?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\RecaptchaResponseService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use ReCaptcha\Response; | ||
|
||
#[CoversClass(RecaptchaResponseService::class)] | ||
class RecaptchaResponseServiceTest extends TestCase | ||
{ | ||
public function testFormatSuccess(): void | ||
{ | ||
$response = new Response(true); | ||
$service = new RecaptchaResponseService(); | ||
$actual = $service->format($response); | ||
self::assertStringContainsString('success', $actual); | ||
self::assertStringContainsString('true', $actual); | ||
} | ||
|
||
public function testFormatWithChallenge(): void | ||
{ | ||
$response = new Response(true, challengeTs: '2024-10-02'); | ||
$service = new RecaptchaResponseService(); | ||
$actual = $service->format($response); | ||
self::assertStringContainsString('success', $actual); | ||
self::assertStringContainsString('challengeTs', $actual); | ||
} | ||
|
||
public function testFormatWithErrorCodes(): void | ||
{ | ||
$response = new Response(true, ['Fake Error']); | ||
$service = new RecaptchaResponseService(); | ||
$actual = $service->format($response); | ||
self::assertStringContainsString('error-codes', $actual); | ||
self::assertStringContainsString('Fake Error', $actual); | ||
} | ||
} |
Oops, something went wrong.