Skip to content

Instantly share code, notes, and snippets.

@peterlafferty
Created October 25, 2017 20:18
Show Gist options
  • Select an option

  • Save peterlafferty/3d31994b60af61987e70bf3418b235ec to your computer and use it in GitHub Desktop.

Select an option

Save peterlafferty/3d31994b60af61987e70bf3418b235ec to your computer and use it in GitHub Desktop.
basic silex controller for TDD
<?php
namespace pl\tddcontroller;
use Symfony\Component\HttpFoundation\JsonResponse;
class TddController
{
/** @var string */
private $charset;
public function __construct(string $charset)
{
$this->charset = $charset;
}
public function get(int $id): JsonResponse
{
return new JsonResponse($id . $this->charset);
}
public function getAll(array $query): JsonResponse
{
$value = 'value1';
if (isset($query['returnsecondvalue']) && $query['returnsecondvalue'] === "true") {
$value = 'value2';
}
return new JsonResponse($value . $this->charset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment