vendredi 29 avril 2016

How to unit test a Slim controller

I have a controller for Slim like this. How would you unit test it? Or shouldn't I unit test controllers?

class Products
{
    protected $ci;
    public function __construct(Container $ci)
    {
        $this->ci = $ci;
    }

    public function get($request, $response)
    {
        try {
            $sku = $request->getAttribute('id');
            $product = $this->ci->get('productModel');
             return $response->withJson($product->get(Auth::$ACCOUNTID, $sku));
         } catch (NotFoundException $e) {
            return $response->withJson(["message" => $e->getMessage()], 404);
         }
    }
}

Aucun commentaire:

Enregistrer un commentaire