|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright MacFJA |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 9 | + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 10 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | + * permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
| 14 | + * Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 17 | + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 18 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +namespace Tests\MacFJA\RediSearch\Helper; |
| 23 | + |
| 24 | +use InvalidArgumentException; |
| 25 | +use MacFJA\RediSearch\Helper\DataHelper; |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | +use RuntimeException; |
| 28 | +use stdClass; |
| 29 | + |
| 30 | +/** |
| 31 | + * @coversDefaultClass \MacFJA\RediSearch\Helper\DataHelper |
| 32 | + */ |
| 33 | +class DataHelperTest extends TestCase |
| 34 | +{ |
| 35 | + /** |
| 36 | + * @covers ::assert |
| 37 | + */ |
| 38 | + public function testAssertTrue(): void |
| 39 | + { |
| 40 | + DataHelper::assert(true); |
| 41 | + $this->expectNotToPerformAssertions(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @covers ::assert |
| 46 | + */ |
| 47 | + public function testAssertFalse(): void |
| 48 | + { |
| 49 | + $this->expectException(RuntimeException::class); |
| 50 | + $this->expectExceptionMessage('The assertion of Tests\MacFJA\RediSearch\Helper\DataHelperTest::testAssertFalse at line '); |
| 51 | + |
| 52 | + DataHelper::assert(false); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @covers ::assert |
| 57 | + */ |
| 58 | + public function testAssertFalseCustomException1(): void |
| 59 | + { |
| 60 | + $this->expectException(InvalidArgumentException::class); |
| 61 | + |
| 62 | + DataHelper::assert(false, InvalidArgumentException::class); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @covers ::assert |
| 67 | + */ |
| 68 | + public function testAssertFalseCustomException2(): void |
| 69 | + { |
| 70 | + $exception = new InvalidArgumentException('not valid'); |
| 71 | + $this->expectException(InvalidArgumentException::class); |
| 72 | + $this->expectExceptionMessage('not valid'); |
| 73 | + |
| 74 | + DataHelper::assert(false, $exception); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @covers ::assert |
| 79 | + */ |
| 80 | + public function testAssertFalseWrongCustomException(): void |
| 81 | + { |
| 82 | + $this->expectException(RuntimeException::class); |
| 83 | + |
| 84 | + DataHelper::assert(false, stdClass::class); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @covers ::assert |
| 89 | + */ |
| 90 | + public function testAssertEmbed1(): void |
| 91 | + { |
| 92 | + $runner = function () { |
| 93 | + $this->expectException(RuntimeException::class); |
| 94 | + $this->expectExceptionMessage('The assertion of Tests\MacFJA\RediSearch\Helper\DataHelperTest::Tests\MacFJA\RediSearch\Helper\{closure} at line '); |
| 95 | + DataHelper::assert(false); |
| 96 | + }; |
| 97 | + $runner(); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @covers ::assert |
| 102 | + */ |
| 103 | + public function testAssertEmbed2(): void |
| 104 | + { |
| 105 | + $runner = function () { |
| 106 | + $this->expectException(RuntimeException::class); |
| 107 | + $this->expectExceptionMessage('The assertion of Tests\MacFJA\RediSearch\Helper\DataHelperTest::testAssertEmbed2 at line '); |
| 108 | + DataHelper::assert(false, null, 2); |
| 109 | + }; |
| 110 | + $runner(); |
| 111 | + } |
| 112 | +} |
0 commit comments