Skip to content

Commit

Permalink
Merge pull request #132 from maurobonfietti/2.10.0
Browse files Browse the repository at this point in the history
Version 2.10.0
  • Loading branch information
maurobonfietti authored Jan 31, 2021
2 parents b9debbd + 74802ae commit f92ee5b
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 55 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ $ composer test
> phpunit
PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

....................................................... 55 / 55 (100%)
........................................................ 56 / 56 (100%)

Time: 00:00.194, Memory: 16.00 MB
Time: 00:00.277, Memory: 16.00 MB

OK (55 tests, 340 assertions)
OK (56 tests, 343 assertions)
```


Expand Down
6 changes: 3 additions & 3 deletions README_SPANISH.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ $ composer test
> phpunit
PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

....................................................... 55 / 55 (100%)
........................................................ 56 / 56 (100%)

Time: 00:00.194, Memory: 16.00 MB
Time: 00:00.277, Memory: 16.00 MB

OK (55 tests, 340 assertions)
OK (56 tests, 343 assertions)
```


Expand Down
21 changes: 13 additions & 8 deletions extras/bin/restart-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
require __DIR__ . '/../../src/App/App.php';

try {
$db = $container->get('settings')['db'];
$host = $db['host'];
$name = $db['name'];
$user = $db['user'];
$pass = $db['pass'];
$port = $db['port'];

$pdo = new PDO("mysql:host=${host};port=$port;charset=utf8", $user, $pass);
$database = $container->get('settings')['db'];
$host = $database['host'];
$name = $database['name'];
$user = $database['user'];
$pass = $database['pass'];
$port = $database['port'];

$dsn = sprintf(
'mysql:host=%s;port=%s;charset=utf8',
getenv('DB_HOST'),
getenv('DB_PORT')
);
$pdo = new PDO($dsn, getenv('DB_USER'), getenv('DB_PASS'));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec("DROP DATABASE IF EXISTS ${name}");
Expand Down
14 changes: 7 additions & 7 deletions src/App/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Psr\Container\ContainerInterface;

$container['db'] = static function (ContainerInterface $container): PDO {
$db = $container->get('settings')['db'];
$database = $container->get('settings')['db'];
$dsn = sprintf(
'mysql:host=%s;dbname=%s;port=%s;charset=utf8',
$db['host'],
$db['name'],
$db['port']
$database['host'],
$database['name'],
$database['port']
);
$pdo = new PDO($dsn, $db['user'], $db['pass']);
$pdo = new PDO($dsn, $database['user'], $database['pass']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Expand All @@ -30,8 +30,8 @@
return new RedisService(new \Predis\Client($redis['url']));
};

$container['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
$container['notFoundHandler'] = static function () {
return static function ($request, $response): void {
throw new \Exception('Route Not Found.', 404);
};
};
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class DefaultController extends BaseController
{
private const API_VERSION = '2.9.0';
private const API_VERSION = '2.10.0';

public function getHelp(Request $request, Response $response): Response
{
Expand Down
9 changes: 5 additions & 4 deletions src/Entity/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

namespace App\Entity;

use App\Traits\ArrayOrJsonResponse;

final class Note
{
use ArrayOrJsonResponse;

private int $id;

private string $name;

private ?string $description;

public function toJson(): object
{
return json_decode((string) json_encode(get_object_vars($this)), false);
}

public function getId(): int
{
return $this->id;
Expand Down
9 changes: 5 additions & 4 deletions src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

namespace App\Entity;

use App\Traits\ArrayOrJsonResponse;

final class Task
{
use ArrayOrJsonResponse;

private int $id;

private string $name;
Expand All @@ -20,6 +16,11 @@ final class Task

private int $userId;

public function toJson(): object
{
return json_decode((string) json_encode(get_object_vars($this)), false);
}

public function getId(): int
{
return $this->id;
Expand Down
9 changes: 5 additions & 4 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

namespace App\Entity;

use App\Traits\ArrayOrJsonResponse;

final class User
{
use ArrayOrJsonResponse;

private int $id;

private string $name;
Expand All @@ -18,6 +14,11 @@ final class User

private string $password;

public function toJson(): object
{
return json_decode((string) json_encode(get_object_vars($this)), false);
}

public function getId(): int
{
return $this->id;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Note/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function create(array $input): object
}
$mynote = new Note();
$mynote->updateName(self::validateNoteName($data->name));
$desc = isset($data->description) ? $data->description : null;
$desc = $data->description ?? null;
$mynote->updateDescription($desc);
/** @var Note $note */
$note = $this->noteRepository->createNote($mynote);
Expand Down
2 changes: 1 addition & 1 deletion src/Service/RedisService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Service;

use \Predis\Client;
use Predis\Client;

final class RedisService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Task/TaskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function create(array $input): object
}
$mytask = new Task();
$mytask->updateName(self::validateTaskName($data->name));
$desc = isset($data->description) ? $data->description : null;
$desc = $data->description ?? null;
$mytask->updateDescription($desc);
$status = 0;
if (isset($data->status)) {
Expand Down
18 changes: 0 additions & 18 deletions src/Traits/ArrayOrJsonResponse.php

This file was deleted.

14 changes: 14 additions & 0 deletions tests/integration/DefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@ public function testStatus(): void
$this->assertStringNotContainsString('error', $result);
$this->assertStringNotContainsString('Failed', $result);
}

/**
* Test Route Not Found.
*/
public function testRouteNotFound(): void
{
$response = $this->runApp('GET', '/route-not-found');

$result = (string) $response->getBody();

$this->assertEquals(404, $response->getStatusCode());
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type'));
$this->assertStringContainsString('error', $result);
}
}

0 comments on commit f92ee5b

Please sign in to comment.