Created
July 18, 2012 08:19
-
-
Save k-holy/3135009 to your computer and use it in GitHub Desktop.
BEAR.Sundayはじめてのリソース
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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}"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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