Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created July 18, 2012 08:19
Show Gist options
  • Save k-holy/3135009 to your computer and use it in GitHub Desktop.
Save k-holy/3135009 to your computer and use it in GitHub Desktop.
BEAR.Sundayはじめてのリソース
<?php
namespace sandbox\Resource\App\First;
use BEAR\Resource\AbstractObject;
/**
* Greeting resource
*/
class Greeting extends AbstractObject
{
/**
* Get
*
* @param string $name
*
* @return string
*
*/
public function onGet($name)
{
return "Hello, {$name}";
}
}
<?php
namespace sandbox\Resource\App\First;
use BEAR\Resource\AbstractObject;
/**
* Greeting resource
*/
class Greeting extends AbstractObject
{
/**
* Get
*
* @param string $name
*
* @return string
*
*/
public function onGet($name)
{
$this->body = "Hello, {$name}";
return $this;
}
}
<?php
namespace sandbox\tests\Resource\App\Blog;
use sandbox\App;
use BEAR\Resource\Annotation\Post;
class GreetingTest extends \PHPUnit_Framework_TestCase
{
/**
* Resource client
*
* @var BEAR\Resource\Resourcce
*/
private $resource;
protected function setUp()
{
parent::setUp();
$app = App::factory(App::RUN_MODE_TEST, true);
$this->resource = $app->resource;
}
/**
* resource
*
* @test
*/
public function resource()
{
// resource request
$resource = $this->resource->get->uri('app://self/first/greeting')->withQuery(['name' => 'BEAR'])->eager->request();
$this->assertSame(200, $resource->code);
return $resource;
}
/**
* Type ?
*
* @depends resource
* @test
*/
public function type($resource)
{
$this->assertInternalType('string', $resource->body);
}
/**
* Renderable ?
*
* @depends resource
* test
*/
public function render($resource)
{
$html = (string) $resource;
$this->assertInternalType('string', $html);
}
/**
* @depends resource
* @test
*/
public function body($resource)
{
$this->assertSame('Hello, BEAR', $resource->body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment