|
4 | 4 |
|
5 | 5 | use bdk\Table\Element; |
6 | 6 | use bdk\PhpUnitPolyfill\AssertionTrait; |
| 7 | +use ErrorNotice; |
| 8 | +use InvalidArgumentException; |
7 | 9 | use PHPUnit\Framework\TestCase; |
| 10 | +use RuntimeException; |
| 11 | +use TypeError; |
8 | 12 |
|
9 | 13 | /** |
10 | 14 | * PHPUnit tests for bdk\Table\Element |
@@ -302,11 +306,10 @@ public function testSetChildren() |
302 | 306 | */ |
303 | 307 | public function testSetChildrenInvalid() |
304 | 308 | { |
305 | | - $this->expectException('TypeError'); |
306 | | - // $this->expectExceptionMessage('Children must be instances of'); |
307 | | - |
308 | | - $parent = new Element('div'); |
309 | | - $parent->setChildren(['not an Element object']); |
| 309 | + self::assertExceptionOrTypeError(function () { |
| 310 | + $parent = new Element('div'); |
| 311 | + $parent->setChildren(['not an Element object']); |
| 312 | + }); |
310 | 313 | } |
311 | 314 |
|
312 | 315 | /** |
@@ -883,4 +886,24 @@ public function testGetHtmlPrioritizesChildren() |
883 | 886 | $html = $parent->getHtml(); |
884 | 887 | self::assertStringContainsString('<span>Child</span>', $html); |
885 | 888 | } |
| 889 | + |
| 890 | + protected static function assertExceptionOrTypeError($callable) |
| 891 | + { |
| 892 | + try { |
| 893 | + $callable(); |
| 894 | + } catch (ErrorNotice $e) { |
| 895 | + self::assertSame('A non well formed numeric value encountered', $e->getMessage()); |
| 896 | + return; |
| 897 | + } catch (RuntimeException $e) { |
| 898 | + self::assertSame('A non well formed numeric value encountered', $e->getMessage()); |
| 899 | + return; |
| 900 | + } catch (InvalidArgumentException $e) { |
| 901 | + self::assertTrue(true); |
| 902 | + return; |
| 903 | + } catch (TypeError $e) { |
| 904 | + self::assertSame(\get_class($e), 'TypeError'); |
| 905 | + return; |
| 906 | + } |
| 907 | + throw new AssertionFailedError('Exception not thrown'); |
| 908 | + } |
886 | 909 | } |
0 commit comments