Skip to content

Commit 30cd78a

Browse files
committed
Merge pull request #14 from BlockScore/fix/add_optional_time_limit
Fix optional time_limit access in create of question sets #11
2 parents 5ecb8e3 + c7753de commit 30cd78a

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.2
1+
4.0.3

lib/ApiResource.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ protected function _search()
159159
}
160160

161161
/**
162+
* @param Integer $time_limit seconds before question set expires.
163+
*
162164
* @return QuestionSet The created QuestionSet.
163165
*/
164-
protected function _createQuestionSet()
166+
protected function _createQuestionSet($time_limit)
165167
{
166168
$url = static::classUrl();
167-
$params = array('person_id' => $this->id);
169+
$params = array('person_id' => $this->id, 'time_limit' => $time_limit);
168170
$response = static::_makeRequest('post', $url, $params);
169171
$qs_obj = Util\Util::convertToBlockScoreObject($response);
170172
$this->addExisting($qs_obj);

lib/QuestionSet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ public function __construct($id)
1818
}
1919

2020
/**
21+
* @param Integer $time_limit seconds before question set expires.
22+
*
2123
* @return QuestionSet The created QuestionSet.
2224
*/
23-
public function create()
25+
public function create($time_limit = 0)
2426
{
25-
return self::_createQuestionSet();
27+
return self::_createQuestionSet($time_limit);
2628
}
2729

2830
/**

tests/QuestionSetTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ public function testCreateQuestionSet()
3535
}
3636
}
3737

38+
public function testCreateQuestionSetWithTimeLimit()
39+
{
40+
$person = self::createTestPerson();
41+
$qs = $person->question_sets->create(17);
42+
43+
$this->assertSame($qs->time_limit, 17);
44+
}
45+
46+
public function testTimeLimitExpired()
47+
{
48+
$person = self::createTestPerson();
49+
$qs = $person->question_sets->create(2);
50+
sleep(4);
51+
52+
$retrieved_qs = $person->question_sets->retrieve($qs->id);
53+
$this->assertSame($retrieved_qs->expired, true);
54+
}
55+
3856
public function testAllQuestionSet()
3957
{
4058
$person = self::createTestPerson();

0 commit comments

Comments
 (0)