Scalr\Tests\Functional\Api\V2\SpecSchema\SpecManager::getDefinitions PHP Method

getDefinitions() public method

Get Object definition
public getDefinitions ( string $filter = null ) : array
$filter string optional The pattern to filter for object definition in specification if the name of the object matched the filter this object will not be included in return result
return array
    public function getDefinitions($filter = null)
    {
        $definitions = $this->getPath('definitions');
        if (!is_null($filter)) {
            $definitions = array_filter($definitions, function ($k) use($filter) {
                return !preg_match($filter, $k);
            }, ARRAY_FILTER_USE_KEY);
        }
        foreach ($definitions as $name => $definition) {
            $definitions[$name] = $this->resolveReferences($definition, null, $name);
        }
        return $definitions;
    }

Usage Example

Example #1
0
 /**
  * Check readOnly vs required Object properties
  *
  * @test
  * @dataProvider specksProvider
  *
  * @param string $version api version
  * @param string $provider specifications type
  */
 public function testSpecks($version, $provider)
 {
     $specs = new SpecManager($version, $provider);
     $definitions = $specs->getDefinitions('#^Api.*|Response$#');
     $this->assertNotEmpty($definitions);
     /* @var  $definition ObjectEntity */
     foreach ($definitions as $name => $definition) {
         $intersectProp = array_intersect($definition->required, $definition->readOnly);
         $this->assertEmpty($intersectProp, sprintf('The property %s is mutually exclusive. should be required or read-only. Object %s in %s spec', implode(', ', $intersectProp), $name, $provider));
         //discriminator must be in the required property list
         if (!empty($definition->discriminator)) {
             $this->assertTrue(in_array($definition->discriminator, $definition->required), sprintf('Property discriminator must be required Object %s in %s spec', $name, $provider));
         }
     }
 }