|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AlibabaCloud\Client\Tests\Unit\Filter; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use AlibabaCloud\Client\Filter\HttpFilter; |
| 7 | +use AlibabaCloud\Client\Exception\ClientException; |
| 8 | + |
| 9 | +class HttpFilterTest extends TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @dataProvider contentType |
| 13 | + * |
| 14 | + * @param $expected |
| 15 | + * @param $contentType |
| 16 | + * @param $exceptionMessage |
| 17 | + */ |
| 18 | + public function testContentType($expected, $contentType, $exceptionMessage) |
| 19 | + { |
| 20 | + try { |
| 21 | + self::assertEquals($expected, HttpFilter::contentType($contentType)); |
| 22 | + } catch (ClientException $exception) { |
| 23 | + self::assertEquals($exceptionMessage, $exception->getMessage()); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @return array |
| 29 | + */ |
| 30 | + public function contentType() |
| 31 | + { |
| 32 | + return [ |
| 33 | + [ |
| 34 | + '', |
| 35 | + '', |
| 36 | + 'Content-Type cannot be empty', |
| 37 | + ], |
| 38 | + [ |
| 39 | + 1, |
| 40 | + 1, |
| 41 | + 'Content-Type must be a string', |
| 42 | + ], |
| 43 | + [ |
| 44 | + 'a', |
| 45 | + 'a', |
| 46 | + 'a', |
| 47 | + ], |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + /** |
| 53 | + * @dataProvider accept |
| 54 | + * |
| 55 | + * @param $expected |
| 56 | + * @param $contentType |
| 57 | + * @param $exceptionMessage |
| 58 | + */ |
| 59 | + public function testAccept($expected, $contentType, $exceptionMessage) |
| 60 | + { |
| 61 | + try { |
| 62 | + self::assertEquals($expected, HttpFilter::accept($contentType)); |
| 63 | + } catch (ClientException $exception) { |
| 64 | + self::assertEquals($exceptionMessage, $exception->getMessage()); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + /** |
| 70 | + * @return array |
| 71 | + */ |
| 72 | + public function accept() |
| 73 | + { |
| 74 | + return [ |
| 75 | + [ |
| 76 | + '', |
| 77 | + '', |
| 78 | + 'Accept cannot be empty', |
| 79 | + ], |
| 80 | + [ |
| 81 | + 1, |
| 82 | + 1, |
| 83 | + 'Accept must be a string', |
| 84 | + ], |
| 85 | + [ |
| 86 | + 'a', |
| 87 | + 'a', |
| 88 | + 'a', |
| 89 | + ], |
| 90 | + ]; |
| 91 | + } |
| 92 | +} |
0 commit comments