|
| 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\Filter\ApiFilter; |
| 8 | +use AlibabaCloud\Client\Exception\ClientException; |
| 9 | + |
| 10 | +class ApiFilterTest extends TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @dataProvider endpointSuffix |
| 14 | + * |
| 15 | + * @param $expected |
| 16 | + * @param $contentType |
| 17 | + * @param $exceptionMessage |
| 18 | + */ |
| 19 | + public function testEndpointSuffix($expected, $contentType, $exceptionMessage) |
| 20 | + { |
| 21 | + try { |
| 22 | + self::assertEquals($expected, ApiFilter::endpointSuffix($contentType)); |
| 23 | + } catch (ClientException $exception) { |
| 24 | + self::assertEquals($exceptionMessage, $exception->getMessage()); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @return array |
| 30 | + */ |
| 31 | + public function endpointSuffix() |
| 32 | + { |
| 33 | + return [ |
| 34 | + [ |
| 35 | + 1, |
| 36 | + 1, |
| 37 | + 'Endpoint Suffix must be a string', |
| 38 | + ], |
| 39 | + [ |
| 40 | + '', |
| 41 | + '', |
| 42 | + 'Endpoint Suffix cannot be empty', |
| 43 | + ], |
| 44 | + [ |
| 45 | + 'EndpointSuffix中文', |
| 46 | + 'EndpointSuffix中文', |
| 47 | + 'Invalid Endpoint Suffix', |
| 48 | + ], |
| 49 | + [ |
| 50 | + 'suffix', |
| 51 | + 'suffix', |
| 52 | + '', |
| 53 | + ] |
| 54 | + ]; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @dataProvider network |
| 59 | + * |
| 60 | + * @param $expected |
| 61 | + * @param $contentType |
| 62 | + * @param $exceptionMessage |
| 63 | + */ |
| 64 | + public function testNetwork($expected, $contentType, $exceptionMessage){ |
| 65 | + try { |
| 66 | + self::assertEquals($expected, ApiFilter::network($contentType)); |
| 67 | + } catch (ClientException $exception) { |
| 68 | + self::assertEquals($exceptionMessage, $exception->getMessage()); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @return array |
| 74 | + */ |
| 75 | + public function network(){ |
| 76 | + return [ |
| 77 | + [ |
| 78 | + 1, |
| 79 | + 1, |
| 80 | + 'Network Suffix must be a string', |
| 81 | + ], |
| 82 | + [ |
| 83 | + '', |
| 84 | + '', |
| 85 | + 'Network Suffix cannot be empty', |
| 86 | + ], |
| 87 | + [ |
| 88 | + 'Network中文', |
| 89 | + 'Network中文', |
| 90 | + 'Invalid Network Suffix', |
| 91 | + ], |
| 92 | + [ |
| 93 | + 'share', |
| 94 | + 'share', |
| 95 | + '', |
| 96 | + ] |
| 97 | + ]; |
| 98 | + } |
| 99 | +} |
0 commit comments