public function testCreateTwoExpectationsAfterEachOther()
 {
     $this->builder->when()->pathIs('/post-resource-1')->methodIs('POST')->then()->statusCode(200)->body('POST 1')->end();
     $this->server->setUp($this->builder->flushExpectations());
     $this->builder->when()->pathIs('/post-resource-2')->methodIs($this->matches->regex('/POST/'))->then()->statusCode(200)->body('POST 2')->end();
     $this->server->setUp($this->builder->flushExpectations());
     $this->assertSame('POST 1', (string) $this->server->getClient()->post('/post-resource-1')->send()->getBody());
     $this->assertSame('POST 2', (string) $this->server->getClient()->post('/post-resource-2')->send()->getBody());
     $this->assertSame('POST 1', (string) $this->server->getClient()->post('/post-resource-1')->send()->getBody());
     $this->assertSame('POST 2', (string) $this->server->getClient()->post('/post-resource-2')->send()->getBody());
 }
 /**
  * Gets the mocked HTTP server.
  *
  * Initializes the server if it was not used before.
  * By default it responds to any POST requests to /invalidate with 200 OK,
  * additional behavior can be added in further steps.
  *
  * @return Server
  *   The mocked HTTP server.
  */
 protected function getServer()
 {
     if (!$this->server) {
         $this->server = new Server($this->mockServerPort, 'localhost');
         $this->server->start();
         // Accept any POSTS.
         $mock = new MockBuilder(new MatcherFactory(), new ExtractorFactory());
         $mock->when()->pathIs('/invalidate')->methodIs('POST')->then()->statusCode(200);
         $this->server->setUp($mock->flushExpectations());
     }
     return $this->server;
 }
 /**
  * Sets up specific responses for 'news' on the mocked Integration server.
  *
  * @When the central Integration server publishes the following news with id :arg1:
  */
 public function theIntegrationServerBackendPublishesTheFollowingNews($arg1, TableNode $table)
 {
     $data = $table->getHash();
     $translations = [];
     foreach ($data as $row) {
         $translations[$row['language']] = ['title' => $row['title'], 'body' => $row['body']];
     }
     $languages = array_keys($translations);
     $default_language = reset($languages);
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $news = ['_id' => $arg1, 'created' => $date->format('Y-m-d H:i:s'), 'updated' => $date->format('Y-m-d H:i:s'), 'languages' => $languages, 'default_language' => $default_language, 'fields' => ['title' => [], 'body' => []]];
     foreach ($translations as $language => $translation) {
         $news['fields']['title'][$language] = [$translation['title']];
         $news['fields']['body'][$language] = [$translation['body']];
     }
     $list = json_encode(['rows' => [['id' => $arg1]]]);
     $mock = new MockBuilder(new MatcherFactory(), new ExtractorFactory());
     $mock->when()->pathIs('/docs/types/news')->methodIs('GET')->then()->statusCode(200)->body($list);
     $mock->when()->methodIs('GET')->pathIs('/docs/types/news/' . $arg1)->then()->statusCode(200)->body(json_encode($news));
     $this->getServer()->setUp($mock->flushExpectations());
 }