Skip to content

Commit

Permalink
Merge pull request #3 from FRoepstorf/add-Ics-support
Browse files Browse the repository at this point in the history
Add ics support
  • Loading branch information
leedwilkins committed Oct 4, 2017
2 parents ede7e65 + 62e43b6 commit c30196f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/build
/vendor
/phpunit.xml
/.idea
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Response/Content/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ abstract class ContentType
const JSON_UTF8 = 'application/json; charset=UTF-8';
const PDF = 'application/pdf';
const PLAIN = 'text/plain';
const ICS = 'text/calendar; charset=utf-8';

/**
* @param $type
Expand All @@ -24,6 +25,8 @@ public static function fromString($type): ContentType
return new PdfContentType();
case self::PLAIN:
return new PlainContentType();
case self::ICS:
return new IcsContentType();
}
throw new UnsupportedContentTypeException(sprintf('Content type %s is not supported', $type));
}
Expand Down
35 changes: 35 additions & 0 deletions src/Response/Content/IcsContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Kartenmacherei\RestFramework\Response\Content;


class IcsContent implements Content
{
/**
* @var string
*/
private $value;

/**
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $value;
}

/**
* @return string
*/
public function asString(): string
{
return $this->value;
}

/**
* @return ContentType
*/
public function getContentType(): ContentType
{
return new IcsContentType();
}
}
14 changes: 14 additions & 0 deletions src/Response/Content/IcsContentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Kartenmacherei\RestFramework\Response\Content;


class IcsContentType extends ContentType
{
/**
* @return string
*/
public function asString(): string
{
return self::ICS;
}
}
6 changes: 6 additions & 0 deletions tests/Unit/Response/Content/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Kartenmacherei\RestFramework\UnitTests\Response\Content;

use Kartenmacherei\RestFramework\Response\Content\ContentType;
use Kartenmacherei\RestFramework\Response\Content\IcsContentType;
use Kartenmacherei\RestFramework\Response\Content\JsonContentType;
use Kartenmacherei\RestFramework\Response\Content\UnsupportedContentTypeException;

Expand All @@ -22,5 +23,10 @@ public function testThrowsExceptionIfContentTypeIsNotSupported()
$this->expectException(UnsupportedContentTypeException::class);
ContentType::fromString('foo');
}
public function testReturnsIcsContentType()
{
$actual = ContentType::fromString(ContentType::ICS);
$this->assertInstanceOf(IcsContentType::class, $actual);
}

}
21 changes: 21 additions & 0 deletions tests/Unit/Response/Content/IcsContentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Kartenmacherei\RestFramework\Response\Content;


use PHPUnit_Framework_TestCase;
/**
* @covers \Kartenmacherei\RestFramework\Response\Content\IcsContent
*/
class IcsContentTest extends PHPUnit_Framework_TestCase
{
public function testGetContentType()
{
$this->assertInstanceOf(IcsContentType::class, (new IcsContent(''))->getContentType());
}

public function testAsString()
{
$content = new IcsContent('Test');
$this->assertSame('Test', $content->asString());
}
}
15 changes: 15 additions & 0 deletions tests/Unit/Response/Content/IcsContentTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Kartenmacherei\RestFramework\Response\Content;

use PHPUnit_Framework_TestCase;

/**
* @covers \Kartenmacherei\RestFramework\Response\Content\IcsContentType
*/
class IcsContentTypeTest extends PHPUnit_Framework_TestCase
{
public function testAsString()
{
$this->assertSame('text/calendar; charset=utf-8', (new IcsContentType())->asString());
}
}

0 comments on commit c30196f

Please sign in to comment.