2013-11-03 13 views
8

Ciao sto usando phpunit per il test e Symfony \ Bundle \ FrameworkBundle \ Test \ WebTestCase per il test delle unità. Finora non c'erano problemi, ma ora iniziamo a usare https e i miei test non funzionano più. Comincio a ottenere il codice di risposta 301 per ogni mia richiesta nei miei test. La mia domanda è come dire a Symfony \ Component \ HttpKernel \ Client di effettuare richieste a https: //lhosthost.com/uri anziché http: //lhosthost.com/uri?Come eseguire richieste https nel test funzionale symfony2?

EDIT

Nel sito di symfony http://symfony.com/doc/current/book/testing.html mostrano come configurare i parametri del server e non v'è una pace codice come

$client->request(
'GET', 
'/demo/hello/Fabien', 
array(), 
array(), 
array(
    'CONTENT_TYPE'   => 'application/json', 
    'HTTP_REFERER'   => '/foo/bar', 
    'HTTP_X-Requested-With' => 'XMLHttpRequest', 
) 
); 

ho cercato di dare elemento HTTPS come indicato nel http://php.net/manual/en/reserved.variables.server.php cambiato il mio codice come

$client->request('GET', 
     '/'.$version.'/agencies/'.$agencyId, 
     array(), 
     array(), 
     array('HTTPS' => 'on') 
     ); 

Tuttavia, è ancora non funziona?

+0

hai provato $ client-> richiesta ('GET', 'https: // localhost/uri'); ? – ziollek

+0

Vuole una richiesta ** https ** non una richiesta ** http **. – ferdynator

+2

Il terzo argomento di $ this-> createClient() è un array di server. Cosa succede se imposti l'elemento "https"? –

risposta

12

Grazie a @WouterJ ho cambiato la mia creazione client da:

static::createClient(); 

a:

static::createClient(array(),array('HTTPS' => true)); 

è risolto il mio problema. Si scopre che non posso fornire i parametri HTTP_HOST e HTTPS in client -> richiesta. Dovrebbe essere determinato durante la creazione del cliente.

+4

Una possibile soluzione alternativa sta chiamando '$ client-> setServerParameter ('HTTPS', true);' su un oggetto client già istanziato –