|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace AssertEmptyIsDiscouragedFixTest; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Assert; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +final class UserDefinedObject |
| 9 | +{ |
| 10 | + |
| 11 | +} |
| 12 | + |
| 13 | +/** @final */ |
| 14 | +class PhpDocFinalObject |
| 15 | +{ |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +class UserDefinedCountable implements \Countable |
| 20 | +{ |
| 21 | + |
| 22 | + public function count(): int |
| 23 | + { |
| 24 | + return 0; |
| 25 | + } |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | +class OpenParent |
| 30 | +{ |
| 31 | + |
| 32 | +} |
| 33 | + |
| 34 | +interface Thing |
| 35 | +{ |
| 36 | + |
| 37 | +} |
| 38 | + |
| 39 | +class ThingImplementation implements Thing, \Countable |
| 40 | +{ |
| 41 | + |
| 42 | + public function count(): int |
| 43 | + { |
| 44 | + return 0; |
| 45 | + } |
| 46 | + |
| 47 | +} |
| 48 | + |
| 49 | +final class FinalEmptyIterator extends \EmptyIterator |
| 50 | +{ |
| 51 | + |
| 52 | +} |
| 53 | + |
| 54 | +final class FinalCountable implements \Countable |
| 55 | +{ |
| 56 | + |
| 57 | + public function count(): int |
| 58 | + { |
| 59 | + return 0; |
| 60 | + } |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +final class AssertEmptyTest extends TestCase |
| 65 | +{ |
| 66 | + |
| 67 | + /** |
| 68 | + * @param non-falsy-string $nonFalsyString |
| 69 | + * @param non-falsy-string $otherNonFalsyString |
| 70 | + * @param int $phpDocInteger |
| 71 | + * @param string|int $union |
| 72 | + */ |
| 73 | + public function test( |
| 74 | + array $arguments, |
| 75 | + bool $boolean, |
| 76 | + array $array, |
| 77 | + int $integer, |
| 78 | + float $float, |
| 79 | + string $string, |
| 80 | + $union, |
| 81 | + string $nonFalsyString, |
| 82 | + string $otherNonFalsyString, |
| 83 | + ?\stdClass $nullableObject, |
| 84 | + ?object $otherNullableObject, |
| 85 | + ?\SimpleXMLElement $nullableSimpleXml, |
| 86 | + ?UserDefinedObject $nullableUserDefinedObject, |
| 87 | + ?UserDefinedObject $otherNullableUserDefinedObject, |
| 88 | + ?PhpDocFinalObject $nullablePhpDocFinalObject, |
| 89 | + ?UserDefinedCountable $nullableCountable, |
| 90 | + ?OpenParent $nullableOpenParent, |
| 91 | + ?Thing $nullableThing, |
| 92 | + ?FinalEmptyIterator $nullableEmptyIterator, |
| 93 | + ?FinalCountable $nullableFinalCountable, |
| 94 | + $phpDocInteger, |
| 95 | + $mixed |
| 96 | + ): void |
| 97 | + { |
| 98 | + $this->assertEmpty(...$arguments); |
| 99 | + $this->assertEmpty($boolean); |
| 100 | + $this->assertNotEmpty($boolean); |
| 101 | + $this->assertEmpty($array, 'message'); |
| 102 | + $this->assertNotEmpty($array); |
| 103 | + $this->assertEmpty($integer); |
| 104 | + $this->assertNotEmpty($integer); |
| 105 | + Assert::assertEmpty($float); |
| 106 | + Assert::assertNotEmpty($float); |
| 107 | + $this->assertEmpty($nonFalsyString); |
| 108 | + $this->assertNotEmpty($otherNonFalsyString); |
| 109 | + $this->assertEmpty($string); |
| 110 | + $this->assertNotEmpty($string); |
| 111 | + $this->assertEmpty($union); |
| 112 | + $this->assertNotEmpty($union); |
| 113 | + $this->assertEmpty($nullableObject); |
| 114 | + $this->assertNotEmpty($otherNullableObject); |
| 115 | + $this->assertEmpty($nullableSimpleXml); |
| 116 | + $this->assertEmpty($nullableUserDefinedObject); |
| 117 | + $this->assertNotEmpty($otherNullableUserDefinedObject); |
| 118 | + $this->assertEmpty($nullablePhpDocFinalObject); |
| 119 | + $this->assertNotEmpty($nullablePhpDocFinalObject); |
| 120 | + $this->assertEmpty($nullableCountable); |
| 121 | + $this->assertNotEmpty($nullableCountable); |
| 122 | + $this->assertEmpty($nullableOpenParent); |
| 123 | + $this->assertNotEmpty($nullableOpenParent); |
| 124 | + $this->assertEmpty($nullableThing); |
| 125 | + $this->assertNotEmpty($nullableThing); |
| 126 | + $this->assertEmpty($nullableEmptyIterator); |
| 127 | + $this->assertNotEmpty($nullableEmptyIterator); |
| 128 | + $this->assertEmpty($nullableFinalCountable); |
| 129 | + $this->assertNotEmpty($nullableFinalCountable); |
| 130 | + $this->assertNotEmpty($phpDocInteger); |
| 131 | + $this->assertEmpty($mixed); |
| 132 | + } |
| 133 | + |
| 134 | + public function testNativeNonFalsyString(string $value): void |
| 135 | + { |
| 136 | + if ($value === '' || $value === '0') { |
| 137 | + return; |
| 138 | + } |
| 139 | + |
| 140 | + $this->assertNotEmpty($value); |
| 141 | + } |
| 142 | + |
| 143 | +} |
0 commit comments