Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

start-local:
php -S localhost:8090 apps/mooc/backend/public/index.php

test-aceptacion:
./vendor/bin/behat -p mooc_backend
4 changes: 4 additions & 0 deletions apps/mooc/backend/config/routes/lovely-health-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lovely-health-check_get:
path: /lovely-health-check
controller: CodelyTv\Apps\Mooc\Backend\Controller\LovelyHealthCheck\LovelyHealthCheckGetController
methods: [GET]
1 change: 1 addition & 0 deletions apps/mooc/backend/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ services:
resource: '../../../../tests/src'

CodelyTv\Shared\Domain\RandomNumberGenerator: '@CodelyTv\Tests\Shared\Infrastructure\ConstantRandomNumberGenerator'
CodelyTv\Shared\Domain\ClockInterface: '@CodelyTv\Tests\Shared\Infrastructure\Clock\StaticDatetimeClockGenerator'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace CodelyTv\Apps\Mooc\Backend\Controller\LovelyHealthCheck;

use CodelyTv\Shared\Domain\ClockInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class LovelyHealthCheckGetController
{
private const MESSAGE_OK = 'Todo va fino %s';
private $clock;

public function __construct(ClockInterface $clock)
{
$this->clock = $clock;
}

public function __invoke(Request $request): Response
{
$name = $request->query->get('name');

return new JsonResponse(
[
'mooc-backend' => 'ok',
'message' => sprintf(self::MESSAGE_OK, $name),
'datetime' => $this->clock->getDateTime()
]
);
}
}
8 changes: 8 additions & 0 deletions src/Shared/Domain/ClockInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CodelyTv\Shared\Domain;

interface ClockInterface
{
public function getDateTime(): string;
}
20 changes: 20 additions & 0 deletions src/Shared/Infrastructure/ClockGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CodelyTv\Shared\Infrastructure;

use CodelyTv\Shared\Domain\ClockInterface;

final class ClockGenerator implements ClockInterface
{
private $time;

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

public function getDateTime(): string
{
return date('Y-m-d H:i:s', $this->time);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Api status
In order to know the server is up and running
As a lovely health check
I want to check the api status

Scenario: Check the api status
Given I send a GET request to "/lovely-health-check?name=Pepe"
Then the response content should be:
"""
{
"mooc-backend": "ok",
"message": "Todo va fino Pepe",
"datetime": "2020-01-01 00:00:00"
}
"""
8 changes: 7 additions & 1 deletion tests/apps/mooc/backend/mooc_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ mooc_backend:
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiRequestContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiResponseContext

lovely_health_check:
paths: [ tests/apps/mooc/backend/features/lovely_health_check ]
contexts:
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiRequestContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiResponseContext

courses:
paths: [ tests/apps/mooc/backend/features/courses ]
contexts:
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiRequestContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiResponseContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiResponseContext
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace CodelyTv\Tests\Shared\Infrastructure\Clock;

use CodelyTv\Shared\Domain\ClockInterface;

class StaticDatetimeClockGenerator implements ClockInterface
{
public function getDateTime(): string
{
return '2020-01-01 00:00:00';
}
}