Skip to content

Add Backed Enum test case when implementing an interface #7593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Zend/tests/enum/backed-implements-multiple.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
Backed Enum with multiple implementing interfaces
--FILE--
<?php

interface Colorful {
public function color(): string;
}

interface Shaped {
public function shape(): string;
}

interface ExtendedShaped extends Shaped {
}

enum Suit: string implements Colorful, ExtendedShaped {
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';

public function color(): string {
return match ($this) {
self::Hearts, self::Diamonds => 'Red',
self::Clubs, self::Spades => 'Black',
};
}

public function shape(): string {
return match ($this) {
self::Hearts => 'heart',
self::Diamonds => 'diamond',
self::Clubs => 'club',
self::Spades => 'spade',
};
}
}

echo Suit::Hearts->color() . "\n";
echo Suit::Hearts->shape() . "\n";
echo Suit::Diamonds->color() . "\n";
echo Suit::Diamonds->shape() . "\n";
echo Suit::Clubs->color() . "\n";
echo Suit::Clubs->shape() . "\n";
echo Suit::Spades->color() . "\n";
echo Suit::Spades->shape() . "\n";

?>
--EXPECT--
Red
heart
Red
diamond
Black
club
Black
spade
34 changes: 34 additions & 0 deletions Zend/tests/enum/backed-implements.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Backed Enum implements
--FILE--
<?php

interface Colorful {
public function color(): string;
}

enum Suit: string implements Colorful {
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';

public function color(): string {
return match ($this) {
self::Hearts, self::Diamonds => 'Red',
self::Clubs, self::Spades => 'Black',
};
}
}

echo Suit::Hearts->color() . "\n";
echo Suit::Diamonds->color() . "\n";
echo Suit::Clubs->color() . "\n";
echo Suit::Spades->color() . "\n";

?>
--EXPECT--
Red
Red
Black
Black