예제 #1
0
    public function testInsulatedRequests()
    {
        if (!class_exists('Symfony\Component\Process\Process')) {
            $this->markTestSkipped('The "Process" component is not available');
        }

        $client = new TestClient();
        $client->insulate();
        $client->setNextScript("new Symfony\Component\BrowserKit\Response('foobar')");
        $client->request('GET', 'http://www.example.com/foo/foobar');

        $this->assertEquals('foobar', $client->getResponse()->getContent(), '->insulate() process the request in a forked process');

        $client->setNextScript("new Symfony\Component\BrowserKit\Response('foobar)");

        try {
            $client->request('GET', 'http://www.example.com/foo/foobar');
            $this->fail('->request() throws a \RuntimeException if the script has an error');
        } catch (\Exception $e) {
            $this->assertInstanceof('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error');
        }
    }
예제 #2
0
 public function testSetServerParameterInRequest()
 {
     $client = new TestClient();
     $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
     $this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
     $client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array('HTTP_HOST' => 'testhost', 'HTTP_USER_AGENT' => 'testua', 'HTTPS' => false, 'NEW_SERVER_KEY' => 'new-server-key-value'));
     $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
     $this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
     $this->assertEquals('http://testhost/https/www.example.com', $client->getRequest()->getUri());
     $server = $client->getRequest()->getServer();
     $this->assertArrayHasKey('HTTP_USER_AGENT', $server);
     $this->assertEquals('testua', $server['HTTP_USER_AGENT']);
     $this->assertArrayHasKey('HTTP_HOST', $server);
     $this->assertEquals('testhost', $server['HTTP_HOST']);
     $this->assertArrayHasKey('NEW_SERVER_KEY', $server);
     $this->assertEquals('new-server-key-value', $server['NEW_SERVER_KEY']);
     $this->assertArrayHasKey('HTTPS', $server);
     $this->assertFalse($server['HTTPS']);
 }
예제 #3
0
 public function testInternalRequest()
 {
     $client = new TestClient();
     $client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array('HTTP_HOST' => 'testhost', 'HTTP_USER_AGENT' => 'testua', 'HTTPS' => false, 'NEW_SERVER_KEY' => 'new-server-key-value'));
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Request', $client->getInternalRequest());
 }