|
7 | 7 | abstract class BaseTest extends TestCase |
8 | 8 | { |
9 | 9 | /** |
10 | | - * Make sure expectException always exists, even on PHPUnit 4 |
11 | 10 | * @param string $exception |
12 | 11 | * @param string|null $message |
13 | 12 | */ |
14 | | - public function expectException($exception, $message = null) |
| 13 | + public function expectExceptionGuzzle($exception, $message = null) |
15 | 14 | { |
16 | 15 | if (method_exists($this, 'setExpectedException')) { |
17 | 16 | $this->setExpectedException($exception, $message); |
18 | 17 | } else { |
19 | | - parent::expectException($exception); |
| 18 | + $this->expectException($exception); |
20 | 19 | if (null !== $message) { |
21 | 20 | $this->expectExceptionMessage($message); |
22 | 21 | } |
23 | 22 | } |
24 | 23 | } |
| 24 | + |
| 25 | + public function expectWarningGuzzle() |
| 26 | + { |
| 27 | + if (method_exists($this, 'expectWarning')) { |
| 28 | + $this->expectWarning(); |
| 29 | + } elseif (class_exists('PHPUnit\Framework\Error\Warning')) { |
| 30 | + $this->expectExceptionGuzzle('PHPUnit\Framework\Error\Warning'); |
| 31 | + } else { |
| 32 | + $this->expectExceptionGuzzle('PHPUnit_Framework_Error_Warning'); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @param string $type |
| 38 | + * @param mixed $input |
| 39 | + */ |
| 40 | + public function assertInternalTypeGuzzle($type, $input) |
| 41 | + { |
| 42 | + switch ($type) { |
| 43 | + case 'array': |
| 44 | + if (method_exists($this, 'assertIsArray')) { |
| 45 | + $this->assertIsArray($input); |
| 46 | + } else { |
| 47 | + $this->assertInternalType('array', $input); |
| 48 | + } |
| 49 | + break; |
| 50 | + case 'bool': |
| 51 | + case 'boolean': |
| 52 | + if (method_exists($this, 'assertIsBool')) { |
| 53 | + $this->assertIsBool($input); |
| 54 | + } else { |
| 55 | + $this->assertInternalType('bool', $input); |
| 56 | + } |
| 57 | + break; |
| 58 | + case 'double': |
| 59 | + case 'float': |
| 60 | + case 'real': |
| 61 | + if (method_exists($this, 'assertIsFloat')) { |
| 62 | + $this->assertIsFloat($input); |
| 63 | + } else { |
| 64 | + $this->assertInternalType('float', $input); |
| 65 | + } |
| 66 | + break; |
| 67 | + case 'int': |
| 68 | + case 'integer': |
| 69 | + if (method_exists($this, 'assertIsInt')) { |
| 70 | + $this->assertIsInt($input); |
| 71 | + } else { |
| 72 | + $this->assertInternalType('int', $input); |
| 73 | + } |
| 74 | + break; |
| 75 | + case 'numeric': |
| 76 | + if (method_exists($this, 'assertIsNumeric')) { |
| 77 | + $this->assertIsNumeric($input); |
| 78 | + } else { |
| 79 | + $this->assertInternalType('numeric', $input); |
| 80 | + } |
| 81 | + break; |
| 82 | + case 'object': |
| 83 | + if (method_exists($this, 'assertIsObject')) { |
| 84 | + $this->assertIsObject($input); |
| 85 | + } else { |
| 86 | + $this->assertInternalType('object', $input); |
| 87 | + } |
| 88 | + break; |
| 89 | + case 'resource': |
| 90 | + if (method_exists($this, 'assertIsResource')) { |
| 91 | + $this->assertIsResource($input); |
| 92 | + } else { |
| 93 | + $this->assertInternalType('resource', $input); |
| 94 | + } |
| 95 | + break; |
| 96 | + case 'string': |
| 97 | + if (method_exists($this, 'assertIsString')) { |
| 98 | + $this->assertIsString($input); |
| 99 | + } else { |
| 100 | + $this->assertInternalType('string', $input); |
| 101 | + } |
| 102 | + break; |
| 103 | + case 'scalar': |
| 104 | + if (method_exists($this, 'assertIsScalar')) { |
| 105 | + $this->assertIsScalar($input); |
| 106 | + } else { |
| 107 | + $this->assertInternalType('scalar', $input); |
| 108 | + } |
| 109 | + break; |
| 110 | + case 'callable': |
| 111 | + if (method_exists($this, 'assertIsCallable')) { |
| 112 | + $this->assertIsCallable($input); |
| 113 | + } else { |
| 114 | + $this->assertInternalType('callable', $input); |
| 115 | + } |
| 116 | + break; |
| 117 | + case 'iterable': |
| 118 | + if (method_exists($this, 'assertIsIterable')) { |
| 119 | + $this->assertIsIterable($input); |
| 120 | + } else { |
| 121 | + $this->assertInternalType('iterable', $input); |
| 122 | + } |
| 123 | + break; |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * @param string $needle |
| 129 | + * @param string $haystack |
| 130 | + */ |
| 131 | + public function assertStringContainsStringGuzzle($needle, $haystack) |
| 132 | + { |
| 133 | + if (method_exists($this, 'assertStringContainsString')) { |
| 134 | + $this->assertStringContainsString($needle, $haystack); |
| 135 | + } else { |
| 136 | + $this->assertContains($needle, $haystack); |
| 137 | + } |
| 138 | + } |
25 | 139 | } |
0 commit comments