CamelCase and more tests.
This commit is contained in:
parent
ba4ead8bf5
commit
120823e83c
@ -4,7 +4,7 @@ namespace Frs;
|
|||||||
|
|
||||||
class FieldDefinition
|
class FieldDefinition
|
||||||
{
|
{
|
||||||
private $field_data = array();
|
private $fieldData = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type Type of FieldDefinition (hotel, car, etc.)
|
* @param string $type Type of FieldDefinition (hotel, car, etc.)
|
||||||
@ -12,28 +12,28 @@ class FieldDefinition
|
|||||||
*/
|
*/
|
||||||
public function __construct($type)
|
public function __construct($type)
|
||||||
{
|
{
|
||||||
$definition_file = 'definitions/' . $type . '.json';
|
$definitionFile = 'definitions/' . $type . '.json';
|
||||||
if (!file_exists($definition_file)) {
|
if (!file_exists($definitionFile)) {
|
||||||
throw new \Exception('File ' . $definition_file . ' not found!');
|
throw new \Exception('File ' . $definitionFile . ' not found!');
|
||||||
}
|
}
|
||||||
$field_data_json = file_get_contents($definition_file);
|
$fieldDataJson = file_get_contents($definitionFile);
|
||||||
$this->field_data = json_decode($field_data_json, true);
|
$this->fieldData = json_decode($fieldDataJson, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFieldData()
|
public function getFieldData()
|
||||||
{
|
{
|
||||||
return $this->field_data;
|
return $this->fieldData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroups()
|
public function getGroups()
|
||||||
{
|
{
|
||||||
$by_group = array();
|
$byGroup = array();
|
||||||
foreach ($this->field_data['groups'] as $id=>$group) {
|
foreach ($this->fieldData['groups'] as $id=>$group) {
|
||||||
$by_group[$group] = array(
|
$byGroup[$group] = array(
|
||||||
'group_name' => $group,
|
'group_name' => $group,
|
||||||
'fields' => array(),
|
'fields' => array(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $by_group;
|
return $byGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,32 @@
|
|||||||
|
|
||||||
namespace Frs\Tests;
|
namespace Frs\Tests;
|
||||||
|
|
||||||
|
use \Frs\FieldDefinition;
|
||||||
#use \PHPUnit\Framework\TestCase;
|
#use \PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testTrue()
|
public function testLoading()
|
||||||
{
|
{
|
||||||
$this->assertTrue(true);
|
$fdo = new FieldDefinition('hotel');
|
||||||
|
$fd = $fdo->getFieldData();
|
||||||
|
$this->assertArraySubset(array('groups'=>array(), 'fields'=>array()), $fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Exception
|
||||||
|
* @expectedExceptionMessage File definitions/doesnotexist.json not found!
|
||||||
|
*/
|
||||||
|
public function testLoadingFailure()
|
||||||
|
{
|
||||||
|
$fdo = new FieldDefinition('doesnotexist');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGroups()
|
||||||
|
{
|
||||||
|
$fdo = new FieldDefinition('hotel');
|
||||||
|
$byGroup = $fdo->getGroups();
|
||||||
|
$this->assertArrayHasKey('Hotel Information', $byGroup);
|
||||||
|
$this->assertArrayHasKey('Metadata', $byGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user