Skip to content
Permalink
Browse files

Merge pull request #5 from jacobemerick/use-datetime

Use datetime
  • Loading branch information...
jacobemerick committed Aug 21, 2016
2 parents f97a9c1 + 469aa01 commit badf5f5bec6342f47c151d91cb18ffee3a6971ea
Showing with 117 additions and 15 deletions.
  1. +20 −3 bootstrap.php
  2. +4 −1 src/Controller/Comment.php
  3. +4 −3 src/Model/Comment.php
  4. +74 −1 tests/unit/Controller/CommentTest.php
  5. +15 −7 tests/unit/Model/CommentTest.php
@@ -66,9 +66,12 @@
'name' => 'default'
],
[
'pushHandler' => (new Monolog\Handler\StreamHandler(
__DIR__ . '/logs/default.log',
Monolog\Logger::DEBUG
'pushHandler' => $di->lazyNew(
'Monolog\Handler\StreamHandler',
[
'stream' => __DIR__ . '/logs/default.log',
'level' => Monolog\Logger::DEBUG,
]
))
]
));
@@ -82,6 +85,20 @@
]
));
// global time object
$di->set('datetime', $di->lazyNew(
'DateTime',
[
'time' => 'now',
'timezone' => $di->lazyNew(
'DateTimezone',
[
'timezone' => 'America/Phoenix',
]
),
]
));
// set up swagger
$handle = fopen(__DIR__ . '/swagger.json', 'r');
$swagger = '';
@@ -126,6 +126,9 @@ public function createComment(Request $req, Response $res)
$replyTo = (int) $body['reply_to'];
}
$dateTime = $this->container
->get('datetime');
$commentId = $this->container
->get('commentModel')
->create(
@@ -137,7 +140,7 @@ public function createComment(Request $req, Response $res)
$body['url'],
(int) $body['should_notify'],
$shouldDisplay,
time()
$dateTime
);
$comment = $this->container
->get('commentModel')
@@ -3,6 +3,7 @@
namespace Jacobemerick\CommentService\Model;
use Aura\Sql\ExtendedPdo;
use DateTimeInterface;
class Comment
{
@@ -27,7 +28,7 @@ public function __construct(ExtendedPdo $extendedPdo)
* @param string $url
* @param integer $notify
* @param integer $display
* @param integer $createTime
* @param DateTimeInterface $createTime
* @return integer
*/
public function create(
@@ -39,7 +40,7 @@ public function create(
$url,
$notify,
$display,
$createTime
DateTimeInterface $createTime
) {
$query = "
INSERT INTO
@@ -57,7 +58,7 @@ public function create(
'url' => $url,
'notify' => $notify,
'display' => $display,
'create_time' => date('Y-m-d H:i:s', $createTime),
'create_time' => $createTime->format('Y-m-d H:i:s'),
];
$this->extendedPdo->perform($query, $bindings);
Oops, something went wrong.

0 comments on commit badf5f5

Please sign in to comment.
You can’t perform that action at this time.