Skip to content

Instantly share code, notes, and snippets.

@upsilon
Created March 29, 2012 03:05
Show Gist options
  • Select an option

  • Save upsilon/2232833 to your computer and use it in GitHub Desktop.

Select an option

Save upsilon/2232833 to your computer and use it in GitHub Desktop.
OpenPNE3.8 JSON APIテストケース
<?php
$app = 'api';
include_once dirname(__FILE__) . '/../../bootstrap/unit.php';
include_once dirname(__FILE__) . '/../../bootstrap/database.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('api', 'test', isset($debug) ? $debug : true);
sfContext::createInstance($configuration);
$numOfTest = 4;
$t = new lime_test($numOfTest, new lime_output_color());
$browser = new opBrowser();
Doctrine::getTable('SnsConfig')->set('enable_jsonapi', true);
$member1ApiKey = Doctrine::getTable('Member')->find(1)->getApiKey();
$browser->get('/activity/search.json');
$t->is($browser->getResponse()->getStatusCode(), 401, 'apiKey not specified');
$browser->get('/activity/search.json', array('apiKey' => ''));
$t->is($browser->getResponse()->getStatusCode(), 401, 'empty apiKey');
$browser->get('/activity/search.json', array('apiKey' => 'aaaaaaaaaa'));
$t->is($browser->getResponse()->getStatusCode(), 401, 'invalid apiKey');
$browser->get('/activity/search.json', array('apiKey' => $member1ApiKey));
$t->is($browser->getResponse()->getStatusCode(), 200, 'valid apiKey');
↑のテストケースを動作させるために必要な修正
diff --git a/test/bootstrap/database.php b/test/bootstrap/database.php
index fb7bd70..e70db70 100644
--- a/test/bootstrap/database.php
+++ b/test/bootstrap/database.php
@@ -1,14 +1,21 @@
<?php
-$_app = 'pc_frontend';
-$_env = 'test';
+if (!isset($app))
+{
+ $app = 'pc_frontend';
+}
+
+if (!isset($env))
+{
+ $env = 'test';
+}
if (!isset($fixture))
{
$fixture = 'common';
}
-$configuration = ProjectConfiguration::getApplicationConfiguration($_app, $_env, true);
+$configuration = ProjectConfiguration::getApplicationConfiguration($app, $env, true);
new sfDatabaseManager($configuration);
$conn = opDoctrineQuery::getMasterConnectionDirect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment