Skip to content

Instantly share code, notes, and snippets.

@DavertMik
Created June 18, 2019 07:11
Show Gist options
  • Save DavertMik/c6ef55b596cd4462ef22d5d0fca49438 to your computer and use it in GitHub Desktop.
Save DavertMik/c6ef55b596cd4462ef22d5d0fca49438 to your computer and use it in GitHub Desktop.
Codeception Raml Helper
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Raml extends \Codeception\Module
{
public function parseSchemaFor($type)
{
$parser = new \Raml\Parser(); // should be started in `_beforeSuite()`
$apiDef = $parser->parse(codecept_root_dir('api.raml'), true); // should be moved to config
$types = $apiDef->getTypes();
$type = $types->getTypeByName($type);
$type->validate(json_decode($this->getModule('REST')->grabResponse()));
if (!$type->isValid()) {
$this->fail(implode(', ', $type->getErrors()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment