Skip to content
Permalink
Browse files

reduced complexity of doTestRequest mock

  • Loading branch information...
mvdbos committed Jan 2, 2016
1 parent 5f29156 commit 02e675f949fa3546d1413d3b1fceaa4dcf0da7aa
Showing with 17 additions and 17 deletions.
  1. +17 −17 tests/VDB/Spider/Tests/SpiderTest.php
@@ -74,6 +74,11 @@ class SpiderTest extends TestCase
protected $hrefF;
protected $hrefG;
/**
* @var array An associative array, containing a map of $this->linkX to $this->responseX.
*/
protected $linkToResponseMap = [];
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
@@ -140,6 +145,14 @@ protected function setUp()
$htmlG = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceG.html');
$this->responseG = new Response(200, null, $htmlG);
$this->linkToResponseMap[$this->linkA->toString()] = $this->responseA;
$this->linkToResponseMap[$this->linkB->toString()] = $this->responseB;
$this->linkToResponseMap[$this->linkC->toString()] = $this->responseC;
$this->linkToResponseMap[$this->linkD->toString()] = $this->responseD;
$this->linkToResponseMap[$this->linkE->toString()] = $this->responseE;
$this->linkToResponseMap[$this->linkF->toString()] = $this->responseF;
$this->linkToResponseMap[$this->linkG->toString()] = $this->responseG;
$this->requestHandler
->expects($this->any())
->method('request')
@@ -168,24 +181,11 @@ public function doTestRequest()
{
$link = func_get_arg(0);
switch ($link->toString()) {
case $this->linkA->toString():
return $this->getResource($this->linkA, $this->responseA);
case $this->linkB->toString():
return $this->getResource($this->linkB, $this->responseB);
case $this->linkC->toString():
return $this->getResource($this->linkC, $this->responseC);
case $this->linkD->toString():
return $this->getResource($this->linkD, $this->responseD);
case $this->linkE->toString():
return $this->getResource($this->linkE, $this->responseE);
case $this->linkF->toString():
return $this->getResource($this->linkF, $this->responseF);
case $this->linkG->toString():
return $this->getResource($this->linkG, $this->responseG);
default:
throw new \ErrorException('The requested URI was not stubbed: ' . $link->toString());
if (array_key_exists($link->toString(), $this->linkToResponseMap)) {
return $this->getResource($link, $this->linkToResponseMap[$link->toString()]);
}
throw new \ErrorException('The requested URI was not stubbed: ' . $link->toString());
}
/**

0 comments on commit 02e675f

Please sign in to comment.
You can’t perform that action at this time.