Skip to content

Commit a2fcae8

Browse files
committed
Add keyString static method to fetch as string
1 parent 75f0443 commit a2fcae8

File tree

7 files changed

+49
-2
lines changed

7 files changed

+49
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
build
23
vendor
34

45
.DS_Store

CHANGELOG-1.x.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.1.0] - 2020-08-31
10+
### Added
11+
- `keyString` static method to fetch as string, glued by comma by default
12+
913
## [1.0.1] - 2020-08-30
1014
### Fixed
1115
- Make `BaseEnum::$cache` protected as it was left public.
@@ -14,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1418
### Added
1519
- Array and illuminate collection implementations
1620

17-
[Unreleased]: https://github.com/ekvedaras/php-enum/compare/v1.0.1...HEAD
21+
[Unreleased]: https://github.com/ekvedaras/php-enum/compare/v1.1.0...HEAD
22+
[1.1.0]: https://github.com/ekvedaras/php-enum/compare/v1.0.1...v1.1.0
1823
[1.0.1]: https://github.com/ekvedaras/php-enum/compare/v1.0.0...v1.0.1
1924
[1.0.0]: https://github.com/ekvedaras/php-enum/releases/tag/v1.0.0

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"illuminate/support": "*"
4141
},
4242
"scripts": {
43-
"test": "phpunit"
43+
"test": "phpunit",
44+
"cover": "phpunit --coverage-html=build"
4445
},
4546
"config": {
4647
"sort-packages": true

src/BaseEnum.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ abstract public static function options();
9494
*/
9595
abstract public static function keys();
9696

97+
/**
98+
* @param string $glue
99+
* @return string
100+
*/
101+
abstract public static function keyString(string $glue = ',');
102+
97103
/**
98104
* Get enum options with full data as JSON
99105
*

src/Illuminate/Collection/Enum.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ public static function keys()
4040
{
4141
return static::enum()->keys();
4242
}
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public static function keyString(string $glue = ',')
48+
{
49+
return static::keys()->implode($glue);
50+
}
4351
}

src/Storage/ArrayAccessibleStorage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public static function keys()
6464
return array_keys(static::enum());
6565
}
6666

67+
/**
68+
* @inheritDoc
69+
*/
70+
public static function keyString(string $glue = ',')
71+
{
72+
return implode($glue, static::keys());
73+
}
74+
6775
/**
6876
* @inheritDoc
6977
*/

tests/BaseEnumTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ public function it_fetches_option_list(string $enum)
8686
}
8787
}
8888

89+
/**
90+
* @test
91+
* @dataProvider enums
92+
* @param BaseEnum|PaymentStatusOptions|string $enum
93+
*/
94+
public function it_fetches_key_list(string $enum)
95+
{
96+
$list = $enum::keys();
97+
$listString = $enum::keyString($glue = ';');
98+
99+
$this->assertCount(count(self::PAYMENT_STATUS_IDS), $list);
100+
101+
foreach (self::PAYMENT_STATUS_IDS as $key => $id) {
102+
$this->assertContains($id, $list);
103+
$this->assertStringContainsString((string)$id, $listString);
104+
}
105+
}
106+
89107
/**
90108
* @test
91109
* @dataProvider enums

0 commit comments

Comments
 (0)