Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| TestWithFaker | n/a |
0 / 0 |
n/a |
0 / 0 |
7 | n/a |
0 / 0 |
|||
| runFakerTest | n/a |
0 / 0 |
n/a |
0 / 0 |
7 | |||||
| 1 | <?php |
| 2 | namespace Apie\Fixtures\TestHelpers; |
| 3 | |
| 4 | use Apie\Core\Utils\EntityUtils; |
| 5 | use Apie\Core\Utils\ValueObjectUtils; |
| 6 | use Apie\Faker\ApieObjectFaker; |
| 7 | use Faker\Factory; |
| 8 | use Faker\Generator; |
| 9 | |
| 10 | /** @codeCoverageIgnore */ |
| 11 | trait TestWithFaker |
| 12 | { |
| 13 | public function runFakerTest(string $classToTest, ?callable $testCase = null, ?Generator $generator = null, int $interval = 1000) |
| 14 | { |
| 15 | if (!class_exists(ApieObjectFaker::class)) { |
| 16 | $this->markTestIncomplete('Faker library not loaded, so skipping test'); |
| 17 | return; |
| 18 | } |
| 19 | $testCase ??= function () { |
| 20 | }; |
| 21 | if (!$generator) { |
| 22 | $generator = Factory::create(); |
| 23 | $generator->addProvider(ApieObjectFaker::createWithDefaultFakers($generator)); |
| 24 | } |
| 25 | if (EntityUtils::isEntity($classToTest) || ValueObjectUtils::isCompositeValueObject($classToTest)) { |
| 26 | $interval = 100; |
| 27 | } |
| 28 | if (preg_match('/File$/', $classToTest)) { |
| 29 | $interval = 10; |
| 30 | } |
| 31 | for ($i = 0; $i < $interval; $i++) { |
| 32 | $result = $generator->fakeClass($classToTest); |
| 33 | $this->assertInstanceOf($classToTest, $result); |
| 34 | $testCase($result, $generator); |
| 35 | } |
| 36 | } |
| 37 | } |