protected function setupMock($method, $path, $body = null, array $headers = [], $response) { $options = ['headers' => $headers]; if (!empty($body)) { $options[is_array($body) ? 'json' : 'body'] = $body; } if (is_string($response)) { $response = $this->getFixture($response); } $this->client->request($method, $path, $options)->shouldBeCalled()->willReturn($response); }
/** * @test */ public function itReceivesAInvalidCard() { $invalidResponse = ' <div class="alert alert-danger" role="alert"> De relatie <strong>invalidcard</strong> heeft geen (geldig) lidmaatschap. </div>'; $crawler = new Crawler(); $crawler->addContent($invalidResponse); $card = new Card('invalidcard'); $this->client->request('POST', 'https://mijn.nabv.nl/portal/controle', ['relation_number' => $card->toString()])->willReturn($crawler); $this->assertFalse($this->cardValidator->isValidCard(new Card('invalidcard'))); }
protected function setUp() { $typeName = Cache::TYPE_NAME; $this->type = $this->prophesize('\\Elastica\\Type'); $this->type->request(Argument::any(), Argument::cetera())->willReturn(true); $this->type->getName()->willReturn($typeName); $this->index = $this->prophesize('\\Elastica\\Index'); $this->index->getType($typeName)->willReturn($this->type->reveal()); $this->index->exists()->willReturn(true); $nsDoc = new Document('DoctrineNamespaceCacheKey[]', [Cache::VALUE_FIELD => serialize($this->namespaceId)]); $this->type->getIndex()->willReturn($this->index->reveal()); $this->type->getDocument("DoctrineNamespaceCacheKey[]")->willReturn($nsDoc); $this->client = $this->prophesize('\\Elastica\\Client'); $this->client->getIndex($this->indexName)->willReturn($this->index->reveal()); $this->cache = new Cache($this->client->reveal(), ['index' => $this->indexName]); }
/** * @test * @expectedException \Shlinkio\Shlink\Core\Exception\InvalidUrlException */ public function exceptionIsThrownWhenUrlDoesNotExist() { $this->httpClient->request(Argument::cetera())->willThrow(new ClientException('', $this->prophesize(Request::class)->reveal())); $this->urlShortener->urlToShortCode(new Uri('http://foobar.com/12345/hello?foo=bar')); }
/** * @test */ public function responseIsWrapped() { $this->guzzle->request('GET', 'foo')->willReturn(new Response())->shouldBeCalledTimes(1); $this->client->get('foo'); }