Skip to content

Commit

Permalink
Merge pull request #99 from maurobonfietti/1.8.0
Browse files Browse the repository at this point in the history
Version 1.8.0
  • Loading branch information
maurobonfietti authored Jun 27, 2020
2 parents 7280a80 + acf382a commit 204a75d
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 70 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ I implemented this API in [this project](https://github.com/maurobonfietti/rest-

## :gear: QUICK INSTALL:

### Pre Requisite:
### Requirements:

- Git.
- Composer.
- PHP 7.3 / 7.4.
- PHP 7.3+.
- MySQL/MariaDB.
- Redis (Optional).
- or Docker.


### With Composer:
Expand Down
5 changes: 3 additions & 2 deletions README_SPANISH.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ Implementé esta API en [este proyecto](https://github.com/maurobonfietti/rest-a

## :gear: INSTALACIÓN RÁPIDA:

### Pre Requisitos:
### Requerimientos:

- Git.
- Composer.
- PHP 7.3 / 7.4.
- PHP 7.3+.
- MySQL/MariaDB.
- Redis (Opcional).
- O simplemente Docker.


### Usando Composer:
Expand Down
24 changes: 12 additions & 12 deletions src/App/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
$app->group('/api/v1', function () use ($app): void {
$app->group('/tasks', function () use ($app): void {
$app->get('', Task\GetAll::class);
$app->get('/[{id}]', Task\GetOne::class);
$app->get('/search/[{query}]', Task\Search::class);
$app->post('', Task\Create::class);
$app->put('/[{id}]', Task\Update::class);
$app->delete('/[{id}]', Task\Delete::class);
$app->get('/search/[{query}]', Task\Search::class);
$app->get('/{id}', Task\GetOne::class);
$app->put('/{id}', Task\Update::class);
$app->delete('/{id}', Task\Delete::class);
})->add(new Auth());

$app->group('/users', function () use ($app): void {
$app->get('', User\GetAll::class)->add(new Auth());
$app->get('/[{id}]', User\GetOne::class)->add(new Auth());
$app->get('/search/[{query}]', User\Search::class)->add(new Auth());
$app->post('', User\Create::class);
$app->put('/[{id}]', User\Update::class)->add(new Auth());
$app->delete('/[{id}]', User\Delete::class)->add(new Auth());
$app->get('/search/[{query}]', User\Search::class)->add(new Auth());
$app->get('/{id}', User\GetOne::class)->add(new Auth());
$app->put('/{id}', User\Update::class)->add(new Auth());
$app->delete('/{id}', User\Delete::class)->add(new Auth());
});

$app->group('/notes', function () use ($app): void {
$app->get('', Note\GetAll::class);
$app->get('/[{id}]', Note\GetOne::class);
$app->get('/search/[{query}]', Note\Search::class);
$app->post('', Note\Create::class);
$app->put('/[{id}]', Note\Update::class);
$app->delete('/[{id}]', Note\Delete::class);
$app->get('/search/[{query}]', Note\Search::class);
$app->get('/{id}', Note\GetOne::class);
$app->put('/{id}', Note\Update::class);
$app->delete('/{id}', Note\Delete::class);
});
});
6 changes: 6 additions & 0 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace App\Controller;

use Slim\Container;
use Slim\Http\Response;

abstract class BaseController
{
protected $container;

public function __construct(Container $container)
{
$this->container = $container;
}

protected function jsonResponse(
Response $response,
string $status,
Expand Down
8 changes: 1 addition & 7 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

namespace App\Controller;

use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;

final class DefaultController extends BaseController
{
public const API_VERSION = '1.7.0';

public function __construct(Container $container)
{
$this->container = $container;
}
public const API_VERSION = '1.8.0';

public function getHelp(Request $request, Response $response): Response
{
Expand Down
6 changes: 0 additions & 6 deletions src/Controller/Note/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@

use App\Controller\BaseController;
use App\Service\Note\NoteService;
use Slim\Container;

abstract class Base extends BaseController
{
public function __construct(Container $container)
{
$this->container = $container;
}

protected function getNoteService(): NoteService
{
return $this->container->get('note_service');
Expand Down
6 changes: 0 additions & 6 deletions src/Controller/Task/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@

use App\Controller\BaseController;
use App\Service\Task\TaskService;
use Slim\Container;

abstract class Base extends BaseController
{
public function __construct(Container $container)
{
$this->container = $container;
}

protected function getTaskService(): TaskService
{
return $this->container->get('task_service');
Expand Down
6 changes: 0 additions & 6 deletions src/Controller/User/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
use App\Controller\BaseController;
use App\Exception\User;
use App\Service\User\UserService;
use Slim\Container;

abstract class Base extends BaseController
{
public function __construct(Container $container)
{
$this->container = $container;
}

protected function getUserService(): UserService
{
return $this->container->get('user_service');
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Note/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(

protected static function validateNoteName(string $name): string
{
if (! v::length(2, 50)->validate($name)) {
if (! v::length(1, 50)->validate($name)) {
throw new Note('The name of the note is invalid.', 400);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/Task/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getTaskRepository(): TaskRepository

protected static function validateTaskName(string $name): string
{
if (! v::length(2, 100)->validate($name)) {
if (! v::length(1, 100)->validate($name)) {
throw new Task('Invalid name.', 400);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/User/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(

protected static function validateUserName(string $name): string
{
if (! v::alnum()->length(2, 100)->validate($name)) {
if (! v::alnum()->length(1, 100)->validate($name)) {
throw new User('Invalid name.', 400);
}

Expand Down
8 changes: 6 additions & 2 deletions tests/integration/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class BaseTestCase extends \PHPUnit\Framework\TestCase
{
public static $jwt = '';

public function runApp(string $requestMethod, string $requestUri, array $requestData = null): ResponseInterface
{
public function runApp(
string $requestMethod,
string $requestUri,
array $requestData = null
): ResponseInterface {

$environment = Environment::mock(
[
'REQUEST_METHOD' => $requestMethod,
Expand Down
40 changes: 22 additions & 18 deletions tests/integration/DefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ public function testApiHelp(): void
{
$response = $this->runApp('GET', '/');

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

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type'));
$this->assertStringContainsString('status', (string) $response->getBody());
$this->assertStringContainsString('success', (string) $response->getBody());
$this->assertStringContainsString('version', (string) $response->getBody());
$this->assertStringContainsString('time', (string) $response->getBody());
$this->assertStringContainsString('endpoints', (string) $response->getBody());
$this->assertStringContainsString('help', (string) $response->getBody());
$this->assertStringNotContainsString('error', (string) $response->getBody());
$this->assertStringNotContainsString('Failed', (string) $response->getBody());
$this->assertStringContainsString('status', $result);
$this->assertStringContainsString('success', $result);
$this->assertStringContainsString('version', $result);
$this->assertStringContainsString('time', $result);
$this->assertStringContainsString('endpoints', $result);
$this->assertStringContainsString('help', $result);
$this->assertStringNotContainsString('error', $result);
$this->assertStringNotContainsString('Failed', $result);
}

/**
Expand All @@ -32,17 +34,19 @@ public function testStatus(): void
{
$response = $this->runApp('GET', '/status');

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

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type'));
$this->assertStringContainsString('status', (string) $response->getBody());
$this->assertStringContainsString('success', (string) $response->getBody());
$this->assertStringContainsString('message', (string) $response->getBody());
$this->assertStringContainsString('stats', (string) $response->getBody());
$this->assertStringContainsString('MySQL', (string) $response->getBody());
$this->assertStringContainsString('Redis', (string) $response->getBody());
$this->assertStringContainsString('version', (string) $response->getBody());
$this->assertStringContainsString('time', (string) $response->getBody());
$this->assertStringNotContainsString('error', (string) $response->getBody());
$this->assertStringNotContainsString('Failed', (string) $response->getBody());
$this->assertStringContainsString('status', $result);
$this->assertStringContainsString('success', $result);
$this->assertStringContainsString('message', $result);
$this->assertStringContainsString('stats', $result);
$this->assertStringContainsString('MySQL', $result);
$this->assertStringContainsString('Redis', $result);
$this->assertStringContainsString('version', $result);
$this->assertStringContainsString('time', $result);
$this->assertStringNotContainsString('error', $result);
$this->assertStringNotContainsString('Failed', $result);
}
}
2 changes: 1 addition & 1 deletion tests/integration/NoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testCreateNoteWithInvalidName(): void
{
$response = $this->runApp(
'POST', '/api/v1/notes',
['name' => 'z']
['name' => '']
);

$result = (string) $response->getBody();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function testCreateTaskWithOutTaskName(): void
public function testCreateTaskWithInvalidTaskName(): void
{
$response = $this->runApp(
'POST', '/api/v1/tasks', ['name' => 'z', 'status' => 1]
'POST', '/api/v1/tasks', ['name' => '', 'status' => 1]
);

$result = (string) $response->getBody();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function testUpdateUserWithInvalidData(): void
{
$response = $this->runApp(
'PUT', '/api/v1/users/' . self::$id,
['name' => 'z', 'email' => 'email-incorrecto...']
['name' => '', 'email' => 'email-incorrecto...']
);

$result = (string) $response->getBody();
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/Service/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class UserServiceTest extends BaseTestCase
{
/**
* @var int
*/
private static $id;

private function getDatabase(): \PDO
Expand Down

0 comments on commit 204a75d

Please sign in to comment.