InterNations\Component\HttpMock\Server::setUp PHP Method

setUp() public method

public setUp ( array $expectations )
$expectations array
    public function setUp(array $expectations)
    {
        /** @var Expectation $expectation */
        foreach ($expectations as $expectation) {
            $response = $this->getClient()->post('/_expectation', null, ['matcher' => serialize($expectation->getMatcherClosures()), 'limiter' => serialize($expectation->getLimiter()), 'response' => serialize($expectation->getResponse())])->send();
            if ($response->getStatusCode() !== 201) {
                throw new RuntimeException('Could not set up expectations');
            }
        }
    }

Usage Example

 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());
 }
All Usage Examples Of InterNations\Component\HttpMock\Server::setUp