InterNations\Component\HttpMock\MockBuilder::when PHP Method

when() public method

public when ( ) : Expectation
return Expectation
    public function when()
    {
        $this->expectations[] = new Expectation($this, $this->matcherFactory, $this->extractorFactory, $this->limiter);
        $this->any();
        return end($this->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\MockBuilder::when