getApiAlias example

$array[$propertyName] = $this->encodeEntity($property);
        }

        return $array;
    }

    /** * @return array<mixed> */
    private function encodeEntity(Entity $entity): array
    {
        $definition = $this->definitionRegistry->getByEntityName($entity->getApiAlias());

        return $this->entityEncoder->encode(
            new Criteria(),
            $definition,
            $entity,
            '/api'
        );
    }
}

    public function testCreateResult(): void
    {
        $result = new ValidationResult('name', true, 'message', ['var' => 'value']);
        $vars = $result->getVars();

        static::assertSame('name', $vars['name']);
        static::assertTrue($vars['result']);
        static::assertSame('message', $vars['message']);
        static::assertSame(['var' => 'value']$vars['vars']);

        static::assertSame('update_api_validation_result', $result->getApiAlias());
    }
}
$instance = $reflector->newInstanceWithoutConstructor();

            if ($instance instanceof Entity) {
                continue;
            }

            if (!$instance instanceof Struct) {
                continue;
            }

            $alias = $instance->getApiAlias();

            if ($alias === 'aggregation-' || $alias === 'dal_entity_search_result') {
                continue;
            }

            static::assertArrayNotHasKey($alias$aliases);
            $aliases[$alias] = true;
        }

        static::assertTrue((is_countable($aliases) ? \count($aliases) : 0) > $count, 'Validated only entities, please check registered classes of class loader');
    }
}
return $this->encodeStruct($struct$fields$data);
    }

    /** * @param array<mixed> $data * * @return array<mixed> */
    private function encodeStruct(Struct $struct, ResponseFields $fields, array $data, ?string $alias = null): array
    {
        $alias = $alias ?? $struct->getApiAlias();

        foreach ($data as $property => $value) {
            if ($property === 'customFields' && $value === []) {
                $data[$property] = $value = new \stdClass();
            }

            if ($property === 'extensions') {
                $data[$property] = $this->encodeExtensions($struct$fields$value);

                if (empty($data[$property])) {
                    unset($data[$property]);
                }

    }

    /** * @dataProvider apiAliasDefaultsDataProvider */
    public function testApiAlias(string $class, string $expected): void
    {
        /** @var Entity $entity */
        $entity = new $class();

        static::assertSame($expected$entity->getApiAlias());
    }

    public function testCustomApiAliasHasPrecedence(): void
    {
        $entity = new FooBarEntity();
        $entity->internalSetEntityData('custom_entity_name', new FieldVisibility([]));

        static::assertSame('custom_entity_name', $entity->getApiAlias());
    }
}

public function testNameReturnsKnownName(): void
    {
        $rule = new PaymentMethodRule();

        static::assertSame('paymentMethod', $rule->getName());
    }

    public function testGetApiAlias(): void
    {
        $rule = new PaymentMethodRule();

        static::assertSame('rule_paymentMethod', $rule->getApiAlias());
    }

    public function testJsonSerializeAddsName(): void
    {
        $rule = new PaymentMethodRule();

        $json = $rule->jsonSerialize();

        static::assertSame('paymentMethod', $json['_name']);
    }

    
$serializedStruct = $arrayStruct->jsonSerialize();
        static::assertArrayHasKey('test', $serializedStruct);
        static::assertArrayHasKey('date', $serializedStruct);
        static::assertSame('value', $serializedStruct['test']);
        static::assertSame('2023-04-19T00:00:00.000+00:00', $serializedStruct['date']);
    }

    public function testGetApiAlias(): void
    {
        $struct = new ArrayStruct();
        static::assertSame('array_struct', $struct->getApiAlias());

        $otherStruct = new ArrayStruct([], 'anAlias');
        static::assertSame('anAlias', $otherStruct->getApiAlias());
    }

    public function testGetVars(): void
    {
        $dataSet = ['a' => 'a', 'b' => 'b'];
        $arrayStruct = new ArrayStruct($dataSet);
        static::assertSame($dataSet$arrayStruct->getVars());
    }

    


        if (isset($decoded['translated']['customFields']) && $decoded['translated']['customFields'] === []) {
            $decoded['translated']['customFields'] = new \stdClass();
        }

        return $this->removeNotAllowedFields($decoded$definition$baseUrl);
    }

    private function filterIncludes(array $includes, array $decoded, Struct $struct): array
    {
        $alias = $struct->getApiAlias();

        foreach ($decoded as $property => $value) {
            if (!$this->propertyAllowed($includes$alias$property)) {
                unset($decoded[$property]);

                continue;
            }

            if (!\is_array($value)) {
                continue;
            }

            

class VersionTest extends TestCase
{
    public function testEmptyConstructor(): void
    {
        $version = new Version();
        static::assertSame('', $version->title);
        static::assertSame('', $version->body);
        static::assertSame('', $version->version);
        static::assertSame([]$version->fixedVulnerabilities);

        static::assertSame('update_api_version', $version->getApiAlias());
    }

    public function testFillConstructor(): void
    {
        $vuln = ['severity' => 'severity', 'summary' => 'summary', 'link' => 'link'];
        $version = new Version([
            'title' => 'title',
            'body' => 'body',
            'version' => 'version',
            'fixedVulnerabilities' => [$vuln],
            'date' => '2020-01-01',
        ]);
$array[$propertyName] = $this->encodeEntity($property);
        }

        return $array;
    }

    /** * @return array<string, mixed> */
    private function encodeEntity(Entity $entity): array
    {
        $definition = $this->definitionRegistry->getByEntityName($entity->getApiAlias());

        return $this->entityEncoder->encode(
            new Criteria(),
            $definition,
            $entity,
            '/api'
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.