Skip to content

Commit

Permalink
Removed querybuilder [SLE-197]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Apr 1, 2024
1 parent 595f756 commit 20cfdbb
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 131 deletions.
3 changes: 2 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
filter:
paths: [ "src/*" ]
excluded_paths: [ "vendor/*", "tests/*", "resources/", "public/" ]
excluded_paths: [ "vendor/*", "tests/*", "resources/", "public/", "src/Infrastructure/Console/**",
"src/Application/ErrorHandler/**", ]

checks:
php:
Expand Down
2 changes: 1 addition & 1 deletion public/frontend/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<title>Example Frontend for Slim API Starter</title>
<title>Slim API Starter - frontend</title>
</head>
<body>
<h1>Frontend for Slim API Starter</h1>
Expand Down
13 changes: 8 additions & 5 deletions src/Domain/User/Repository/UserCreatorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Domain\User\Repository;

use App\Infrastructure\Factory\QueryFactory;
use Cake\Database\Connection;

final readonly class UserCreatorRepository
{
public function __construct(
private QueryFactory $queryFactory,
) {
public function __construct(private Connection $connection)
{
}

/**
Expand All @@ -21,6 +20,10 @@ public function __construct(
public function insertUser(array $userValues): int
{
// Insert user into database
return (int)$this->queryFactory->insertQueryWithData($userValues)->into('user')->execute()->lastInsertId();
return (int)$this->connection->insertQuery()
->insert(array_keys($userValues))
->values($userValues)
->into('user')
->execute()->lastInsertId();
}
}
8 changes: 4 additions & 4 deletions src/Domain/User/Repository/UserFinderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace App\Domain\User\Repository;

use App\Domain\User\Data\UserData;
use App\Infrastructure\Factory\QueryFactory;
use App\Infrastructure\Utility\Hydrator;
use Cake\Database\Connection;

final readonly class UserFinderRepository
{
public function __construct(
private QueryFactory $queryFactory,
private Hydrator $hydrator
private Connection $connection,
private Hydrator $hydrator,
) {
}

Expand All @@ -21,7 +21,7 @@ public function __construct(
*/
public function findAllUsers(): array
{
$query = $this->queryFactory->selectQuery()->select([
$query = $this->connection->selectQuery()->select([
'id',
'first_name',
'last_name',
Expand Down
120 changes: 0 additions & 120 deletions src/Infrastructure/Factory/QueryFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Test\Integration\ErrorHandler;

use App\Test\Trait\AppTestTrait;
use PHPUnit\Framework\TestCase;
use TestTraits\Trait\HttpTestTrait;

class NonFatalErrorHandlerMiddlewareTest extends TestCase
{
use AppTestTrait;
use HttpTestTrait;

/**
* Test that when a non-fatal error occurs, the NonFatalErrorHandlerMiddleware
* makes an ErrorException. This is to make the app "exception-heavy"
* and display a proper stack trace and error page in development.
* Documentation: https://github.com/samuelgfeller/slim-example-project/wiki/Error-Handling.
*
* @return void
*/
public function testNonFatalErrorHandler(): void
{
// Add a route that triggers a non-fatal error
$this->app->get('/error', function ($request, $response, $args) {
// This will trigger a PHP notice because $undefinedVar is not defined
/** @phpstan-ignore-next-line */
echo $undefinedVar;

return $response;
});

$request = $this->createRequest('GET', '/error');

// Expect that an ErrorException is thrown
$this->expectException(\ErrorException::class);
$this->expectExceptionMessage('Undefined variable $undefinedVar');

// Process the request through the application
$this->app->handle($request);
}
}

0 comments on commit 20cfdbb

Please sign in to comment.