Markdown

[PHPUnit] request a post by crawler

class EntidadeControllerTest extends WebTestCase
{
    public function testCreate()
    {

        $dados = array(
            'nome' => 'Entidade TESTE 01',
            'ativo' => 0,
            '_token' => $this->csrfDefaultToken
        );

        $crawler = $this->client->request(
            'POST',
            '/admin/entidades',
            array(),
            array(),
            array(
               'CONTENT_TYPE'          => 'application/json',
               'HTTP_X-Requested-With' => 'XMLHttpRequest'
            ),
            json_encode(array('cartorio_servico_entidade'=>$dados))
        );

        $this->assertEquals(201, $this->client->getResponse()->getStatusCode());
    }
}
--- https://stackoverflow.com/questions/20025222/how-to-test-restful-json-create-entity-action

留言