lundi 15 août 2016

How to pass some line code when write test?

I'm new in php testing, now I have a problem that need your help. I want to write test for below function:

public function deleteDocument(User $user, $documentId)
{
    $document = $this->checkDocumentOwner($user, $documentId);
    if (!$document instanceof Document) {
        return $document;
    }

    // Delete file in S3
    $results = $this->loader->delete($document->getName());

    if ($results) {
        $this->manager->getRepository('ApiBundle:Document')
                ->deleteEntity($documentId);
    }


    return new JsonResponse([
        'status' => true,
        'message' => 'Successful remove document: ' .
        $documentId . ' by ' . $user->getEmail()
    ]);
}

Actually, I don't follow TDD method because I had this function first, and then I write test for it. But I DON'T WANT TO REALLY DELETE THE FILE ON S3 SERVER, so how do I write the test? I heard about Mockery, but have no idea for this case. Can you give me some advice, please?

Aucun commentaire:

Enregistrer un commentaire