Example #1
0
    /**
     * @dataProvider curlExceptionProvider
     *
     * @param \Exception $exception The exception that curl should throw.
     * @param string     $type      The returned exception class to be expected.
     */
    public function testExceptions(\Exception $exception, $type)
    {
        // the guzzle mock plugin does not allow arbitrary exceptions
        // mockery does not provide all methods of the interface
        $collection = new MultiTransferException();
        $collection->setExceptions(array($exception));
        $client = $this->getMock('\Guzzle\Http\ClientInterface');
        $client->expects($this->any())
            ->method('createRequest')
            ->willReturn(new Request('GET', '/'))
        ;
        $client->expects($this->once())
            ->method('send')
            ->willThrowException($collection)
        ;

        $varnish = new Varnish(array('http://127.0.0.1:123'), 'my_hostname.dev', $client);

        $varnish->ban(array());
        try {
            $varnish->flush();
            $this->fail('Should have aborted with an exception');
        } catch (ExceptionCollection $exceptions) {
            $this->assertCount(1, $exceptions);
            $this->assertInstanceOf($type, $exceptions->getFirst());
        }
    }