|
| 1 | +// Jest Snapshot v1, https://goo.gl/fbAQLP |
| 2 | + |
| 3 | +exports[`enum.php 1`] = ` |
| 4 | +====================================options===================================== |
| 5 | +parsers: ["php"] |
| 6 | +printWidth: 80 |
| 7 | + | printWidth |
| 8 | +=====================================input====================================== |
| 9 | +<?php |
| 10 | +
|
| 11 | +interface Colorful |
| 12 | +{ |
| 13 | + public function color(): string; |
| 14 | +} |
| 15 | +
|
| 16 | +trait Rectangle |
| 17 | +{ |
| 18 | + public function shape(): string { |
| 19 | + return "Rectangle"; |
| 20 | + } |
| 21 | +} |
| 22 | +
|
| 23 | +enum Suit implements Colorful |
| 24 | +{ |
| 25 | + use Rectangle; // https://www.php.net/manual/en/language.enumerations.traits.php |
| 26 | +
|
| 27 | + case Hearts; |
| 28 | + case Diamonds; |
| 29 | + case Clubs; |
| 30 | + case Spades; |
| 31 | +
|
| 32 | + public const Favorite = self::Clubs; |
| 33 | +
|
| 34 | + // Fulfills the interface contract. |
| 35 | + public function color(): string |
| 36 | + { |
| 37 | + return match($this) { |
| 38 | + Suit::Hearts, |
| 39 | + Suit::Diamonds => 'Red', |
| 40 | + Suit::Clubs, |
| 41 | + Suit::Spades => 'Black', |
| 42 | + }; |
| 43 | + } |
| 44 | +
|
| 45 | + // Not part of an interface; that's fine. |
| 46 | + public function shape(): string |
| 47 | + { |
| 48 | + return "Rectangle"; |
| 49 | + } |
| 50 | +
|
| 51 | + public static function staticMethod(){ |
| 52 | + return self::Clubs; |
| 53 | + } |
| 54 | +} |
| 55 | +
|
| 56 | +function paint(Colorful $c) { } |
| 57 | +
|
| 58 | +paint(Suit::Clubs); // Works |
| 59 | +
|
| 60 | +print Suit::Diamonds->shape(); // prints "Rectangle" |
| 61 | +
|
| 62 | +
|
| 63 | +class Foo |
| 64 | +{ |
| 65 | + const Bar = Suit::Hearts; // https://www.php.net/manual/en/language.enumerations.expressions.php |
| 66 | +} |
| 67 | +
|
| 68 | +
|
| 69 | +enum BackedSuit: string |
| 70 | +{ |
| 71 | + case Spades = 5; |
| 72 | +} |
| 73 | +=====================================output===================================== |
| 74 | +<?php |
| 75 | +
|
| 76 | +interface Colorful |
| 77 | +{ |
| 78 | + public function color(): string; |
| 79 | +} |
| 80 | +
|
| 81 | +trait Rectangle |
| 82 | +{ |
| 83 | + public function shape(): string |
| 84 | + { |
| 85 | + return "Rectangle"; |
| 86 | + } |
| 87 | +} |
| 88 | +
|
| 89 | +enum Suit implements Colorful |
| 90 | +{ |
| 91 | + use Rectangle; // https://www.php.net/manual/en/language.enumerations.traits.php |
| 92 | +
|
| 93 | + case Hearts; |
| 94 | + case Diamonds; |
| 95 | + case Clubs; |
| 96 | + case Spades; |
| 97 | +
|
| 98 | + public const Favorite = self::Clubs; |
| 99 | +
|
| 100 | + // Fulfills the interface contract. |
| 101 | + public function color(): string |
| 102 | + { |
| 103 | + return match ($this) { |
| 104 | + Suit::Hearts, Suit::Diamonds => "Red", |
| 105 | + Suit::Clubs, Suit::Spades => "Black" |
| 106 | + }; |
| 107 | + } |
| 108 | +
|
| 109 | + // Not part of an interface; that's fine. |
| 110 | + public function shape(): string |
| 111 | + { |
| 112 | + return "Rectangle"; |
| 113 | + } |
| 114 | +
|
| 115 | + public static function staticMethod() |
| 116 | + { |
| 117 | + return self::Clubs; |
| 118 | + } |
| 119 | +} |
| 120 | +
|
| 121 | +function paint(Colorful $c) |
| 122 | +{ |
| 123 | +} |
| 124 | +
|
| 125 | +paint(Suit::Clubs); // Works |
| 126 | +
|
| 127 | +print Suit::Diamonds->shape(); // prints "Rectangle" |
| 128 | +
|
| 129 | +class Foo |
| 130 | +{ |
| 131 | + const Bar = Suit::Hearts; // https://www.php.net/manual/en/language.enumerations.expressions.php |
| 132 | +} |
| 133 | +
|
| 134 | +enum BackedSuit: string |
| 135 | +{ |
| 136 | + case Spades = 5; |
| 137 | +} |
| 138 | +
|
| 139 | +================================================================================ |
| 140 | +`; |
0 commit comments