Better accept header handling and lots more test coverage
parent
56d6ac12c8
commit
5e3f011cfa
@ -1,26 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Sleepy - a REST framework
|
||||
*
|
||||
*
|
||||
* A PHP Rest Framework valuing convention over configuration,
|
||||
* but aiming to be as flexible as possible
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @package Sleepy
|
||||
*/
|
||||
|
||||
return [
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Map mime types to type classes
|
||||
// --------------------------------------------------------------------------
|
||||
'application/json' => 'JSON',
|
||||
'text/yaml' => 'YAML',
|
||||
'application/yaml' => 'YAML',
|
||||
'text/html' => 'HTML',
|
||||
'application/xhtml+xml' => 'HTML',
|
||||
'*/*' => 'HTML'
|
||||
];
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Sleepy - a REST framework
|
||||
*
|
||||
*
|
||||
* A PHP Rest Framework valuing convention over configuration,
|
||||
* but aiming to be as flexible as possible
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @package Sleepy
|
||||
*/
|
||||
|
||||
return [
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Map mime types to type classes
|
||||
// --------------------------------------------------------------------------
|
||||
'application/json' => 'JSON',
|
||||
'text/yaml' => 'YAML',
|
||||
'application/yaml' => 'YAML',
|
||||
'text/html' => 'HTML',
|
||||
'text/xml' => 'XML',
|
||||
'application/xml' => 'XML',
|
||||
|
||||
// Default mime type for cases without an explicit accept header match
|
||||
'*/*' => 'text/html'
|
||||
];
|
||||
|
||||
// End of config/type_class_map.php
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Sleepy\Core\Config;
|
||||
|
||||
class ConfigTest extends Sleepy_Testcase {
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->config = new MockConfig();
|
||||
$this->config->setData([
|
||||
'foo' => [
|
||||
'bar' => 'baz',
|
||||
'x' => '-y',
|
||||
'p !=' => 'np'
|
||||
],
|
||||
'apple' => [1,3,5,7,9]
|
||||
]);
|
||||
}
|
||||
|
||||
public function dataGet()
|
||||
{
|
||||
return [
|
||||
'single value' => [
|
||||
'file' => 'foo',
|
||||
'key' => 'x',
|
||||
'expected' => '-y'
|
||||
],
|
||||
'whole array' => [
|
||||
'file' => 'apple',
|
||||
'key' => NULL,
|
||||
'expected' => [1,3,5,7,9]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGet
|
||||
*/
|
||||
public function testGet($file, $key, $expected)
|
||||
{
|
||||
$res = $this->config->get($file, $key);
|
||||
$this->assertEquals($expected, $res);
|
||||
}
|
||||
|
||||
|
||||
public function testBadGet()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->config->get('bleucheese');
|
||||
}
|
||||
catch (\InvalidArgumentException $e)
|
||||
{
|
||||
$this->assertTrue(TRUE, "Proper exception was caught");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End of ConfigTest.php
|
Reference in New Issue