public function testCreateExpectation()
 {
     $builder = $this->builder->when()->pathIs('/foo')->methodIs($this->matches->regex('/POST/'))->callback(static function (Request $request) {
         error_log('CLOSURE MATCHER: ' . $request->getMethod() . ' ' . $request->getPathInfo());
         return true;
     })->then()->statusCode(401)->body('response body')->header('X-Foo', 'Bar')->end();
     $this->assertSame($this->builder, $builder);
     $expectations = $this->builder->flushExpectations();
     $this->assertCount(1, $expectations);
     /** @var Expectation $expectation */
     $expectation = current($expectations);
     $request = new TestRequest();
     $request->setMethod('POST');
     $request->setRequestUri('/foo');
     $run = 0;
     $oldValue = ini_set('error_log', '/dev/null');
     foreach ($expectation->getMatcherClosures() as $closure) {
         $this->assertTrue($closure($request));
         $unserializedClosure = unserialize(serialize($closure));
         $this->assertTrue($unserializedClosure($request));
         $run++;
     }
     ini_set('error_log', $oldValue);
     $this->assertSame(3, $run);
     $expectation->getResponse()->setDate(new DateTime('2012-11-10 09:08:07', new DateTimeZone('UTC')));
     $response = "HTTP/1.0 401 Unauthorized\r\nCache-Control: no-cache\r\nDate:          Sat, 10 Nov 2012 09:08:07 GMT\r\nX-Foo:         Bar\r\n\r\nresponse body";
     $this->assertSame($response, (string) $expectation->getResponse());
     $this->server->setUp($expectations);
     $client = $this->server->getClient();
     $this->assertSame('response body', (string) $client->post('/foo')->send()->getBody());
     $this->assertContains('CLOSURE MATCHER: POST /foo', $this->server->getErrorOutput());
 }
 private function createComplexResponse()
 {
     $recordedRequest = new TestRequest();
     $recordedRequest->setMethod('POST');
     $recordedRequest->setRequestUri('/foo');
     $recordedRequest->setContent('RECOREDED=1');
     $recordedRequest->headers->set('Php-Auth-User', 'ignored');
     $recordedRequest->headers->set('Php-Auth-Pw', 'ignored');
     $recordedRequest->headers->set('User-Agent', 'ignored');
     return new Response('200', ['Content-Type' => 'text/plain; charset=UTF-8'], serialize(['server' => ['HTTP_HOST' => 'host', 'HTTP_PORT' => 1234, 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'password', 'HTTP_USER_AGENT' => 'CUSTOM UA'], 'request' => (string) $recordedRequest]));
 }