public function testUpdateOnPostDownload() { $req = new HttpGetRequest('example.com', 'https://example.com/', new IO\NullIO()); $postDownload = new JoinPoint('post-download', $req); $res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 200)); $postDownload->setResponse($res); $auth = new AspectAuth(); $auth->update($postDownload); self::assertFalse($res->needAuth(), 'status 200 is ok'); $res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 401)); $postDownload->setResponse($res); $auth->update($postDownload); self::assertTrue($res->needAuth(), 'status 401 need auth'); $res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 403)); $postDownload->setResponse($res); $auth->update($postDownload); self::assertTrue($res->needAuth(), 'status 403 need auth'); $res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 404)); $postDownload->setResponse($res); $auth->update($postDownload); self::assertTrue($res->needAuth(), 'status 404 need auth'); $res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 407)); $postDownload->setResponse($res); $auth->update($postDownload); self::assertFalse($res->needAuth(), 'status 407 don\'t need auth'); }
public function testAttachAndDetach() { $observer = $this->prophesize('SplObserver'); $joinPoint = new JoinPoint('pre-download', new HttpGetRequest('example.com', 'https://example.com/', new IO\NullIO())); $mock = $observer->reveal(); $joinPoint->attach($mock); $observer->update($joinPoint)->shouldBeCalled(); $joinPoint->notify(); $joinPoint->detach($mock); $observer->update()->shouldNotBeCalled(); $joinPoint->notify(); }
/** * @internal * @param resource<curl> $ch * @param Aspects\HttpGetRequest $request * @return array(int, Aspects\HttpGetResponse) */ public function exec($ch, $request) { $execStatus = curl_exec($ch); $response = new Aspects\HttpGetResponse(curl_errno($ch), curl_error($ch), curl_getinfo($ch)); $this->onPostDownload->setResponse($response); $this->onPostDownload->notify(); if ($response->needAuth()) { $this->promptAuth($request, $response); } return array($execStatus, $response); }
/** * @internal * @param resource $ch * @param Aspects\HttpGetRequest $request * @return array {int, Aspects\HttpGetResponse} */ public function exec($ch, $request) { $this->_lastHeaders = array(); curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'processHeader')); $execStatus = curl_exec($ch); $response = new Aspects\HttpGetResponse(curl_errno($ch), curl_error($ch), curl_getinfo($ch)); $this->onPostDownload->setResponse($response); $this->onPostDownload->notify(); if ($response->needAuth()) { $this->promptAuth($request, $response); } return array($execStatus, $response); }
/** * @return Aspects\JoinPoint */ public static function getPostEvent(Aspects\HttpGetRequest $req) { $post = new Aspects\JoinPoint('post-download', $req); $post->attach(static::getAspectAuth()); return $post; }