/** * @dataProvider methodDataProvider */ public function testMethod($method, $valid) { $request = new Request(); $constraint = $this->equalTo($method); if (!$valid) { $this->setExpectedException('\\Nimbles\\Http\\Client\\Request\\Exception\\InvalidMethod'); $constraint = $this->logicalNot($this->equalTo($method)); } $returnValue = $request->setMethod($method); $this->assertThat($request->getMethod(), $constraint); $this->assertEquals($request, $returnValue); }
/** * Prepare the request by setting the method and ensuring it's of the correct type * @param \Nimbles\Http\Client\Request $request * @param string $method * @throws \Nimbles\Http\Client\Exception */ protected function _prepareRequestInstance($request, $method) { if ($request instanceof Client\Request && null === $request->getMethod()) { $request->setMethod($method); } else { if (is_string($request)) { $requestInstance = new Client\Request(); $request = $requestInstance->setRequestUri($request)->setMethod($method); } } if (!$request instanceof Client\Request) { throw new Client\Exception('Request must be either a \\Nimbles\\Http\\Client\\Request object or a URI string'); } return $request; }