ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry Class Reference

Bookkeeping about the mock classes that have been generated into the running process. More...

+ Collaboration diagram for ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry:

Static Public Member Functions

static isGenerated (string $generated_fqcn)
 
static register (string $generated_fqcn, array $return_types, AbstractLightMockBuilder $builder)
 
static returnTypeFor (string $generated_fqcn, string $method)
 
static defaultValueFor (object $mock, string $method)
 Entry point for the generated mocks themselves, see {. More...
 

Static Private Attributes

static array $return_types = []
 
static array $builders = []
 

Detailed Description

Bookkeeping about the mock classes that have been generated into the running process.

The state has to be process-wide: a generated class is declared in the global scope, so declaring it a second time - from whatever builder instance - is a fatal error. The registry also hands the generated mocks back to the builder that created them, so that nested mocks are built the same way the outer one was.

Definition at line 35 of file GeneratedMockRegistry.php.

Member Function Documentation

◆ defaultValueFor()

static ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::defaultValueFor ( object  $mock,
string  $method 
)
static

Entry point for the generated mocks themselves, see {.

See also
MockObjectBehavior}.

Definition at line 76 of file GeneratedMockRegistry.php.

76 : mixed
77 {
78 $builder = self::$builders[$mock::class] ?? null;
79
80 if ($builder === null) {
81 // not a generated mock - nothing to derive a value from
82 return null;
83 }
84
85 return $builder->defaultValueFor($mock, $method);
86 }

Referenced by ILIAS\Component\Dependencies\Mocks\__mockInvoke(), ILIAS\Component\Tests\Dependencies\LightMockBuilderTest\testDefaultValueForKnownMethodMatchesDirectInvocation(), and ILIAS\Component\Tests\Dependencies\LightMockBuilderTest\testDefaultValueForUnknownMethodReturnsNull().

+ Here is the caller graph for this function:

◆ isGenerated()

static ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::isGenerated ( string  $generated_fqcn)
static
Parameters
class-string$generated_fqcn

Definition at line 46 of file GeneratedMockRegistry.php.

46 : bool
47 {
48 return isset(self::$builders[$generated_fqcn]);
49 }

Referenced by ILIAS\Component\Dependencies\Mocks\AbstractLightMockBuilder\createNormal().

+ Here is the caller graph for this function:

◆ register()

static ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::register ( string  $generated_fqcn,
array  $return_types,
AbstractLightMockBuilder  $builder 
)
static
Parameters
class-string$generated_fqcn
array<string,array<string,mixed>>$return_types method name => normalized return type

Definition at line 55 of file GeneratedMockRegistry.php.

59 : void {
60 self::$return_types[$generated_fqcn] = $return_types;
61 self::$builders[$generated_fqcn] = $builder;
62 }

References ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry\$return_types.

Referenced by ILIAS\Component\Dependencies\Mocks\AbstractLightMockBuilder\createNormal().

+ Here is the caller graph for this function:

◆ returnTypeFor()

static ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::returnTypeFor ( string  $generated_fqcn,
string  $method 
)
static
Returns
array<string, mixed>|null null if the class was not generated here, or if it has no such method

Definition at line 68 of file GeneratedMockRegistry.php.

68 : ?array
69 {
70 return self::$return_types[$generated_fqcn][$method] ?? null;
71 }

Referenced by ILIAS\Component\Dependencies\Mocks\AbstractLightMockBuilder\defaultValueFor().

+ Here is the caller graph for this function:

Field Documentation

◆ $builders

array ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::$builders = []
staticprivate

Definition at line 41 of file GeneratedMockRegistry.php.

◆ $return_types

array ILIAS\Component\Dependencies\Mocks\GeneratedMockRegistry::$return_types = []
staticprivate

The documentation for this class was generated from the following file: