Skip to content

Commit 75a6ab1

Browse files
testing
1 parent b29b915 commit 75a6ab1

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

src/Api/Site/Handler/TestHandler.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@
1818
use SELN\App\Application\Domain\Repository\UserRepository;
1919
use SELN\App\Application\Infrastructure\Flusher;
2020
use SELN\App\Application\Service\PasswordService;
21+
use SELN\App\Core\Authentication\JWTService;
22+
use SELN\App\Core\Authentication\PassportTrait;
2123
use SELN\App\Core\HTTP\Request\RequestSchema;
2224
use SELN\App\Core\HTTP\RequestValidator\RequestValidatorException;
25+
use SELN\App\Core\Service\Mail\MailService;
2326

2427
class TestHandler implements RequestHandlerInterface
2528
{
29+
use PassportTrait;
2630

2731
public function __construct(
2832
private Flusher $flusher,
2933
private UserRepository $userRepository,
3034
private PasswordService $passwordService,
31-
private RequestSchema $requestSchema
35+
private RequestSchema $requestSchema,
36+
private JWTService $service,
37+
private MailService $mail
3238
)
3339
{
3440
}
@@ -41,8 +47,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4147
/** @var TestSchema $schema */
4248
$schema = $this->requestSchema->getRequestProperty(TestSchema::class, $request);
4349

50+
$userId = $this->checkAuth($request);
51+
4452
$user = new User(
45-
Uuid::uuid4()->toString(),
53+
$id = Uuid::uuid4()->toString(),
4654
$schema->name,
4755
$schema->email,
4856
$schema->phone,
@@ -52,6 +60,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
5260
$this->userRepository->create($user);
5361
$this->flusher->flush();
5462

55-
return new JsonResponse("Successful", 201);
63+
$this->mail->send($user->email, ['body' => 'message'], 'test.html.twig');
64+
return new JsonResponse($userId, 201);
5665
}
5766
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Author: SyntaxErrorLineNULL.
4+
*/
5+
6+
declare(strict_types=1);
7+
8+
namespace SELN\App\Test\UnitTest\Core\Request;
9+
10+
use Codeception\Test\Unit;
11+
use Laminas\Diactoros\ResponseFactory;
12+
use Laminas\Diactoros\ServerRequest;
13+
use Laminas\Diactoros\ServerRequestFactory;
14+
use Psr\Http\Server\RequestHandlerInterface;
15+
use SELN\App\Core\HTTP\Request\RequestSchema;
16+
use SELN\App\Core\HTTP\RequestValidator\RequestValidator;
17+
use SELN\App\Test\UnitTest\Core\UnitTemplate;
18+
19+
class RequestSchemaTest extends Unit
20+
{
21+
public function testSuccess(): void
22+
{
23+
$mock = $this->createMock(RequestValidator::class);
24+
$requestSchema = new RequestSchema($mock);
25+
26+
$request = (new ServerRequest())
27+
->withHeader('Content-Type', 'application/json')
28+
->withParsedBody([
29+
'name' => 'Alex',
30+
'email' => 'test@gmail.com'
31+
]);
32+
33+
var_dump($request->getBody()->getContents());
34+
35+
$body = $requestSchema->getRequestProperty(TestSchema::class, $request);
36+
37+
$this->assertEquals('Alex', $body->name);
38+
}
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Author: SyntaxErrorLineNULL.
4+
*/
5+
6+
declare(strict_types=1);
7+
8+
namespace SELN\App\Test\UnitTest\Core\Request;
9+
10+
class TestSchema
11+
{
12+
public string $name;
13+
public string $email;
14+
}

0 commit comments

Comments
 (0)