Skip to content

Commit b028825

Browse files
committed
feat: support for fake helper has been extended
1 parent 6753a50 commit b028825

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

src/LionBundle/Helpers/Bundle/helpers.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Lion\Bundle\Enums\LogTypeEnum;
1010
use Lion\Bundle\Enums\StatusResponseEnum;
1111
use Lion\Bundle\Helpers\Env;
12+
use Lion\Bundle\Helpers\Fake;
1213
use Lion\Files\Store;
1314
use Lion\Request\Request;
1415
use Lion\Security\JWT;
@@ -257,7 +258,7 @@ function jwt(): array|object|string
257258
*/
258259
function fake(string $locale = Factory::DEFAULT_LOCALE): Generator
259260
{
260-
return Factory::create($locale);
261+
return Fake::get($locale);
261262
}
262263
}
263264

@@ -266,11 +267,11 @@ function fake(string $locale = Factory::DEFAULT_LOCALE): Generator
266267
* Gets the value defined for an environment variable
267268
*
268269
* @param string $key [Property name]
269-
* @param mixed|null $default [Default value]
270+
* @param mixed $default [Default value]
270271
*
271272
* @return mixed
272273
*/
273-
function env(string $key, ?mixed $default = null): mixed
274+
function env(string $key, mixed $default = null): mixed
274275
{
275276
return Env::get($key, $default);
276277
}

src/LionBundle/Helpers/Env.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Env
1515
* Gets the value defined for an environment variable
1616
*
1717
* @param string $key [Property name]
18-
* @param mixed|null $default [Default value]
18+
* @param mixed $default [Default value]
1919
*
2020
* @return mixed
2121
*/
22-
public static function get(string $key, ?mixed $default = null): mixed
22+
public static function get(string $key, mixed $default = null): mixed
2323
{
2424
return self::getOption($key, $default);
2525
}
@@ -28,11 +28,11 @@ public static function get(string $key, ?mixed $default = null): mixed
2828
* Gets and transforms the possible value of environment variables
2929
*
3030
* @param string $key [Property name]
31-
* @param mixed|null $default [Default value]
31+
* @param mixed $default [Default value]
3232
*
3333
* @return mixed
3434
*/
35-
private static function getOption(string $key, ?mixed $default): mixed
35+
private static function getOption(string $key, mixed $default): mixed
3636
{
3737
$transform = function(mixed $value): mixed {
3838
switch ($value) {

src/LionBundle/Helpers/Fake.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lion\Bundle\Helpers;
6+
7+
use Faker\Factory;
8+
use Faker\Generator;
9+
10+
/**
11+
* Create Generator objects with a single instance
12+
*
13+
* @package Lion\Bundle\Helpers
14+
*/
15+
class Fake
16+
{
17+
/**
18+
* [Generator class object]
19+
*
20+
* @var Generator|null $generator
21+
*/
22+
private static ?Generator $generator = null;
23+
24+
/**
25+
* Function that generates a Generator object to obtain fake data
26+
*
27+
* @param string $locale [Regional configuration]
28+
*
29+
* @return Generator
30+
*/
31+
public static function get(string $locale = Factory::DEFAULT_LOCALE): Generator
32+
{
33+
if (null === self::$generator) {
34+
self::$generator = Factory::create($locale);
35+
}
36+
37+
return self::$generator;
38+
}
39+
}

tests/Helpers/Bundle/HelpersTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function testIsSuccess(): void
155155
public function testFake(): void
156156
{
157157
$this->assertInstanceOf(Generator::class, fake());
158+
$this->assertSame(fake(), fake());
158159
}
159160

160161
/**

0 commit comments

Comments
 (0)