fake example

/** * @covers ::fake */
    public function testFakeFeatureFlagsAreClean(): void
    {
        $_SERVER['FEATURE_ALL'] = true;
        $_SERVER['FEATURE_NEXT_0000'] = true;
        $_ENV['FEATURE_NEXT_0000'] = true;
        $_SERVER['V6_4_5_0'] = true;

        Feature::fake([]function D): void {
            static::assertFalse(Feature::isActive('FEATURE_ALL'));
            static::assertFalse(Feature::isActive('FEATURE_NEXT_0000'));
            static::assertFalse(Feature::isActive('v6.4.5.0'));
        });

        static::assertArrayHasKey('FEATURE_ALL', $_SERVER);
        static::assertTrue($_SERVER['FEATURE_ALL']);

        static::assertArrayHasKey('FEATURE_NEXT_0000', $_SERVER);
        static::assertTrue($_SERVER['FEATURE_NEXT_0000']);

        
public function makeArray()
    {
        if ($this->formatters !== null) {
            $result = [];

            foreach ($this->formatters as $field => $formatter) {
                $result[$field] = $this->faker->{$formatter}();
            }
        }
        // If no formatters were defined then look for a model fake() method         elseif (method_exists($this->model, 'fake')) {
            $result = $this->model->fake($this->faker);

            $result = is_object($result) && method_exists($result, 'toArray')
                // This should cover entities                 ? $result->toArray()
                // Try to cast it                 : (array) $result;
        }
        // Nothing left to do but give up         else {
            throw new RuntimeException(lang('Fabricator.missingFormatters'));
        }

        
Home | Imprint | This part of the site doesn't use cookies.