我正在使用PHPUnit测试我在控制器中创建的注册API。该功能可以正常工作,但我不知道如何通过PHPUnit实施逻辑来对其进行测试...
我的代码:
namespace Tests\AppBundle\Entity;
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public function testBasic()
{
// here I want to test my API with PHPUnit
}
}
在我的控制器中,我需要实现一个功能:
/**
* @Route("/register", name="register")
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
*/
public function testAction()
{
$this->requirePostParams(['first_name', 'last_name]);
$firstName = $this->data['first_name'];
$lastName = $this->data['last_name'];
$user = $this->get('app')->testIt($firstName, $lastName);
return $this->success($response);
}