|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\chobie\Jira\Api\Client; |
| 4 | + |
| 5 | + |
| 6 | +use chobie\Jira\Api\Authentication\Anonymous; |
| 7 | +use chobie\Jira\Api\Client\ClientInterface; |
| 8 | + |
| 9 | +abstract class AbstractClientTestCase extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + |
| 12 | + /** |
| 13 | + * Client. |
| 14 | + * |
| 15 | + * @var ClientInterface |
| 16 | + */ |
| 17 | + protected $client; |
| 18 | + |
| 19 | + protected function setUp() |
| 20 | + { |
| 21 | + parent::setUp(); |
| 22 | + |
| 23 | + if ( empty($_SERVER['REPO_URL']) ) { |
| 24 | + $this->markTestSkipped('The "REPO_URL" environment variable not set.'); |
| 25 | + } |
| 26 | + |
| 27 | + $this->client = $this->createClient(); |
| 28 | + } |
| 29 | + |
| 30 | + public function testGetRequestDataAsArray() |
| 31 | + { |
| 32 | + $query_params = array('param1' => 'value1', 'param2' => 'value2'); |
| 33 | + $trace_result = $this->traceRequest('GET', $query_params); |
| 34 | + |
| 35 | + $this->assertEquals($query_params, $trace_result['_GET']); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @expectedException \InvalidArgumentException |
| 40 | + * @expectedExceptionMessage Data must be an array. |
| 41 | + */ |
| 42 | + public function testGetRequestDataAsString() |
| 43 | + { |
| 44 | + $this->traceRequest('GET', 'param1=value1¶m2=value2'); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Traces a request. |
| 49 | + * |
| 50 | + * @param string $method Request method. |
| 51 | + * @param array $data Request data. |
| 52 | + * @param boolean $is_file This is a file upload request. |
| 53 | + * @param boolean $debug Debug this request. |
| 54 | + * |
| 55 | + * @return array |
| 56 | + */ |
| 57 | + protected function traceRequest($method, $data = array(), $is_file = false, $debug = false) |
| 58 | + { |
| 59 | + $result = $this->client->sendRequest( |
| 60 | + $method, |
| 61 | + '/tests/debug_response.php', |
| 62 | + $data, |
| 63 | + rtrim($_SERVER['REPO_URL'], '/'), |
| 64 | + new Anonymous(), |
| 65 | + $is_file, |
| 66 | + $debug |
| 67 | + ); |
| 68 | + |
| 69 | + return unserialize($result); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Creates client. |
| 74 | + * |
| 75 | + * @return ClientInterface |
| 76 | + */ |
| 77 | + abstract protected function createClient(); |
| 78 | + |
| 79 | +} |
0 commit comments