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
9
n/a
0 / 0
 runFakerTest
n/a
0 / 0
n/a
0 / 0
9
1<?php
2namespace Apie\Fixtures\TestHelpers;
3
4use Apie\Core\Utils\EntityUtils;
5use Apie\Core\Utils\ValueObjectUtils;
6use Apie\Faker\ApieObjectFaker;
7use Faker\Factory;
8use Faker\Generator;
9
10/** @codeCoverageIgnore */
11trait 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        $unchangedInterval = $interval === 1000;
20        $testCase ??= function () {
21        };
22        if (!$generator) {
23            $generator = Factory::create();
24            $generator->addProvider(ApieObjectFaker::createWithDefaultFakers($generator));
25        }
26        if ($unchangedInterval && EntityUtils::isEntity($classToTest) || ValueObjectUtils::isCompositeValueObject($classToTest)) {
27            $interval = 100;
28        }
29        if ($unchangedInterval && preg_match('/File$/', $classToTest)) {
30            $interval = 10;
31        }
32        for ($i = 0; $i < $interval; $i++) {
33            $result = $generator->fakeClass($classToTest);
34            $this->assertInstanceOf($classToTest, $result);
35            $testCase($result, $generator);
36        }
37    }
38}