. */ declare(strict_types=1); namespace App\Tests; use InvalidArgumentException; use ReflectionClass; class SettingsTestHelper { /** * Creates a new dummy settings object for testing purposes. * It does not contain any embedded objects! * @template T of object * @param string $class * @phpstan-param class-string $class * @return object * @phpstan-return T */ public static function createSettingsDummy(string $class): object { $reflection = new ReflectionClass($class); //Check if it is a settings class (has a Settings attribute) if ($reflection->getAttributes(\Jbtronics\SettingsBundle\Settings\Settings::class) === []) { throw new InvalidArgumentException("The class $class is not a settings class!"); } $object = $reflection->newInstanceWithoutConstructor(); //If the object has some initialization logic, then call it if ($object instanceof \Jbtronics\SettingsBundle\Settings\ResettableSettingsInterface) { $object->resetToDefaultValues(); } return $object; } }