Skip to content

Commit

Permalink
Merge branch 'master' into remove-price
Browse files Browse the repository at this point in the history
  • Loading branch information
trecouvr committed Sep 13, 2013
2 parents dfa4bea + bad8dcf commit 0aa1bbf
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"slim/slim": "2.2.*",
"slim/slim": "2.3.*",
"slim/extras": "*",
"ginger/client": "2.*",
"zendframework/zendframework": "2.*",
Expand Down
2 changes: 1 addition & 1 deletion src/Payutc/Bom/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static function getRank($fun_id, $obj_id, $start, $end, $top, $sort_by) {
public static function getPurchasesForUser($usr_id, $time_limit=null)
{
$qb = Dbal::createQueryBuilder();
$qb->select('pur_id', 'obj_id', 'pur_price')
$qb->select('pur_id', 'obj_id', 'pur_price', 'pur_qte', 'pur_date')
->from('t_purchase_pur', 'pur')
->Where('usr_id_buyer = :usr_id')
->andWhere('pur_removed = 0')
Expand Down
4 changes: 2 additions & 2 deletions src/Payutc/Bom/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ public function isCotisant() {
*
* @return array $return
*/
public function getLastPurchase() {
public function getLastPurchases() {
return Purchase::getPurchasesForUser($this->getId(), 60*15);
}

/**
* Initialiser ginger, éventuellement avec une URL perso
*
Expand Down
11 changes: 7 additions & 4 deletions src/Payutc/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ public static function initLog()

public static function isInit()
{
$environment = \Slim\Environment::getInstance();
return isset($environment['slim.log']);
$app = \Slim\Slim::getInstance();
if ($app === null) {
return false;
}
return $app->getLog() != NULL;
}

public static function getInstance()
{
static::initLog();
$environment = \Slim\Environment::getInstance();
return $environment['slim.log'];
$app = \Slim\Slim::getInstance();
return $app->getLog();
}

public static function __callstatic($name, $args)
Expand Down
2 changes: 1 addition & 1 deletion src/Payutc/Service/POSS2.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function getBuyerInfo($badge_id) {
"firstname"=>$buyer->getFirstname(),
"lastname"=>$buyer->getLastname(),
"solde"=>$buyer->getCredit(),
"last_purchase"=>$buyer->getLastPurchase()
"last_purchase"=>$buyer->getLastPurchases()
));
} else {
Log::warn("getBuyerInfo() : No Seller loaded");
Expand Down
2 changes: 1 addition & 1 deletion src/Payutc/Service/POSS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getBuyerInfo($badge_id) {
"firstname"=>$buyer->getFirstname(),
"lastname"=>$buyer->getLastname(),
"solde"=>$buyer->getCredit(),
"last_purchases"=>$buyer->getLastPurchase()
"last_purchases"=>$buyer->getLastPurchases()
);
}

Expand Down
32 changes: 24 additions & 8 deletions tests/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
class MyWriter
{
protected $logs;
protected $level_to_string = array(
\Slim\Log::EMERGENCY => "emergency",
\Slim\Log::ALERT => "alert",
\Slim\Log::CRITICAL => "critical",
\Slim\Log::ERROR => "error",
\Slim\Log::WARN => "warn",
\Slim\Log::NOTICE => "notice",
\Slim\Log::INFO => "info",
\Slim\Log::DEBUG => "debug"
);

public function write($m, $level)
{
$this->logs .= "[$level] $m\n";
$this->logs .= "[".$this->level_to_string[$level]."] $m\n";
}

public function clean()
Expand All @@ -31,6 +41,12 @@ class LogTest extends PHPUnit_Framework_TestCase

public function __construct()
{
global $_CONFIG;
global $_SERVER;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

Config::initFromArray($_CONFIG);

$log = Log::getInstance();
$log->setWriter(new MyWriter());
$log->setLevel(\Slim\Log::DEBUG);
Expand Down Expand Up @@ -71,7 +87,7 @@ public function testGetWriter()
public function testLogDebug()
{
Log::debug("coucou");
$this->assertEquals("[4] coucou\n", Log::getWriter()->getLogs());
$this->assertEquals("[debug] coucou\n", Log::getWriter()->getLogs());
}

/**
Expand All @@ -81,7 +97,7 @@ public function testLogDebug()
public function testLogInfo()
{
Log::info("coucou");
$this->assertEquals("[3] coucou\n", Log::getWriter()->getLogs());
$this->assertEquals("[info] coucou\n", Log::getWriter()->getLogs());
}

/**
Expand All @@ -91,7 +107,7 @@ public function testLogInfo()
public function testLogWarn()
{
Log::warn("coucou");
$this->assertEquals("[2] coucou\n", Log::getWriter()->getLogs());
$this->assertEquals("[warn] coucou\n", Log::getWriter()->getLogs());
}

/**
Expand All @@ -101,17 +117,17 @@ public function testLogWarn()
public function testLogError()
{
Log::error("coucou");
$this->assertEquals("[1] coucou\n", Log::getWriter()->getLogs());
$this->assertEquals("[error] coucou\n", Log::getWriter()->getLogs());
}

/**
* @depends testGetInstance
* @depends testGetWriter
*/
public function testLogFatal()
public function testLogCritical()
{
Log::fatal("coucou");
$this->assertEquals("[0] coucou\n", Log::getWriter()->getLogs());
Log::critical("coucou");
$this->assertEquals("[critical] coucou\n", Log::getWriter()->getLogs());
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Payutc/Service/Poss3RodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testTransactionWithoutEnoughCredit()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand Down
6 changes: 3 additions & 3 deletions tests/Payutc/Service/Poss3RwdbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testTransaction()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand All @@ -55,7 +55,7 @@ public function testTransaction()
$this->assertEquals(200, $r->code);
$u = new User("trecouvr");
$this->assertEquals($solde-280, $u->getCredit());
$purchases = $u->getLastPurchase();
$purchases = $u->getLastPurchases();
sort_by_key($purchases, 'pur_id');
$this->assertEquals($nb_purchase+3, count($purchases));
$purchases = array_slice($purchases, count($purchases)-3);
Expand All @@ -74,7 +74,7 @@ public function testCancel()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand Down
11 changes: 11 additions & 0 deletions tests/PurchaseRodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function testGetRank() {
$this->assertEquals($waited,$r);

}

public function testGetPurchasesForUser() {
$purchases = Purchase::getPurchasesForUser(9447);
$this->assertTrue(count($purchases) > 0);
$pur = $purchases[0];
$this->assertArrayHasKey('pur_id', $pur);
$this->assertArrayHasKey('obj_id', $pur);
$this->assertArrayHasKey('pur_price', $pur);
$this->assertArrayHasKey('pur_qte', $pur);
$this->assertArrayHasKey('pur_date', $pur);
}
}


0 comments on commit 0aa1bbf

Please sign in to comment.