-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ruebot/issue-10
Implement copyResource -- Address #10.
- Loading branch information
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use Islandora\Chullo\Chullo; | ||
|
||
class CopyResourceTest extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* @covers Islandora\Fedora\Chullo::copyResource | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testReturnsUriOn201() { | ||
$mock = new MockHandler([ | ||
new Response(201, ['Location' => "http://localhost:8080/fcrepo/rest/SOME_URI"]), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); | ||
$client = new Chullo($guzzle); | ||
|
||
$result = $client->copyResource("",""); | ||
$this->assertSame($result, "http://localhost:8080/fcrepo/rest/SOME_URI"); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Fedora\Chullo::copyResource | ||
* @uses GuzzleHttp\Client | ||
* @expectedException GuzzleHttp\Exception\ClientException | ||
*/ | ||
public function testThrowsExceptionOn404() { | ||
$mock = new MockHandler([ | ||
new Response(404), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); | ||
$client = new Chullo($guzzle); | ||
|
||
$result = $client->copyResource("",""); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Fedora\Chullo::copyResource | ||
* @uses GuzzleHttp\Client | ||
* @expectedException GuzzleHttp\Exception\ClientException | ||
*/ | ||
public function testThrowsExceptionOn409() { | ||
$mock = new MockHandler([ | ||
new Response(409), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); | ||
$client = new Chullo($guzzle); | ||
|
||
$result = $client->copyResource("",""); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Fedora\Chullo::copyResource | ||
* @uses GuzzleHttp\Client | ||
* @expectedException GuzzleHttp\Exception\ServerException | ||
*/ | ||
public function testThrowsExceptionOn502() { | ||
$mock = new MockHandler([ | ||
new Response(502), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); | ||
$client = new Chullo($guzzle); | ||
|
||
$result = $client->copyResource("",""); | ||
} | ||
} |