Skip to content

Commit 1478218

Browse files
committed
Updated tests
1 parent 430edd7 commit 1478218

6 files changed

+301
-0
lines changed

tests/AddRatingTestCase.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class AddRatingTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($user_id,$item_id,$rating,$optional);
14+
15+
public function testAddRating() {
16+
17+
//it does not fail with cascadeCreate
18+
$req = $this->createRequest('u_id','i_id',1,['cascadeCreate' => true]);
19+
$resp = $this->client->send($req);
20+
21+
//it does not fail with existing item and user
22+
$req = $this->createRequest('entity_id','entity_id',0);
23+
$resp = $this->client->send($req);
24+
25+
//it fails with nonexisting item id
26+
$req = $this->createRequest('entity_id','nonex_id',-1);
27+
try {
28+
29+
$this->client->send($req);
30+
throw new \Exception('Exception was not thrown');
31+
}
32+
catch(Exc\ResponseException $e)
33+
{
34+
$this->assertEquals(404, $e->status_code);
35+
}
36+
37+
//it fails with nonexisting user id
38+
$req = $this->createRequest('nonex_id','entity_id',0.5);
39+
try {
40+
41+
$this->client->send($req);
42+
throw new \Exception('Exception was not thrown');
43+
}
44+
catch(Exc\ResponseException $e)
45+
{
46+
$this->assertEquals(404, $e->status_code);
47+
}
48+
49+
//it fails with invalid time
50+
$req = $this->createRequest('entity_id','entity_id',0,['timestamp' => -15]);
51+
try {
52+
53+
$this->client->send($req);
54+
throw new \Exception('Exception was not thrown');
55+
}
56+
catch(Exc\ResponseException $e)
57+
{
58+
$this->assertEquals(400, $e->status_code);
59+
}
60+
61+
//it fails with invalid rating
62+
$req = $this->createRequest('entity_id','entity_id',-2);
63+
try {
64+
65+
$this->client->send($req);
66+
throw new \Exception('Exception was not thrown');
67+
}
68+
catch(Exc\ResponseException $e)
69+
{
70+
$this->assertEquals(400, $e->status_code);
71+
}
72+
73+
//it really stores interaction to the system
74+
$req = $this->createRequest('u_id','i_id',0.3,['cascadeCreate' => true,'timestamp' => 5]);
75+
$resp = $this->client->send($req);
76+
try {
77+
78+
$this->client->send($req);
79+
throw new \Exception('Exception was not thrown');
80+
}
81+
catch(Exc\ResponseException $e)
82+
{
83+
$this->assertEquals(409, $e->status_code);
84+
}
85+
86+
}
87+
}
88+
89+
?>

tests/InsertToGroupTestCase.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class InsertToGroupTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($set_id,$type,$entity_id,$optional);
14+
15+
public function testInsertToGroup() {
16+
17+
//it does not fail when inserting existing item into existing set
18+
$req = new AddItem('new_item');
19+
$resp = $this->client->send($req);
20+
$req = $this->createRequest('entity_id','item','new_item');
21+
$resp = $this->client->send($req);
22+
23+
//it does not fail when cascadeCreate is used
24+
$req = $this->createRequest('new_set','item','new_item2',['cascadeCreate' => true]);
25+
$resp = $this->client->send($req);
26+
27+
//it really inserts item to the set
28+
$req = new AddItem('new_item3');
29+
$resp = $this->client->send($req);
30+
$req = $this->createRequest('entity_id','item','new_item3');
31+
$resp = $this->client->send($req);
32+
try {
33+
34+
$this->client->send($req);
35+
throw new \Exception('Exception was not thrown');
36+
}
37+
catch(Exc\ResponseException $e)
38+
{
39+
$this->assertEquals(409, $e->status_code);
40+
}
41+
42+
}
43+
}
44+
45+
?>

tests/InsertToSeriesTestCase.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class InsertToSeriesTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($set_id,$type,$entity_id,$time,$optional);
14+
15+
public function testInsertToSeries() {
16+
17+
//it does not fail when inserting existing item into existing set
18+
$req = new AddItem('new_item');
19+
$resp = $this->client->send($req);
20+
$req = $this->createRequest('entity_id','item','new_item',3);
21+
$resp = $this->client->send($req);
22+
23+
//it does not fail when cascadeCreate is used
24+
$req = $this->createRequest('new_set','item','new_item2',1,['cascadeCreate' => true]);
25+
$resp = $this->client->send($req);
26+
27+
//it really inserts item to the set
28+
$req = new AddItem('new_item3');
29+
$resp = $this->client->send($req);
30+
$req = $this->createRequest('entity_id','item','new_item3',2);
31+
$resp = $this->client->send($req);
32+
try {
33+
34+
$this->client->send($req);
35+
throw new \Exception('Exception was not thrown');
36+
}
37+
catch(Exc\ResponseException $e)
38+
{
39+
$this->assertEquals(409, $e->status_code);
40+
}
41+
42+
}
43+
}
44+
45+
?>

tests/MergeUsersTestCase.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class MergeUsersTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($target,$source,$optional);
14+
15+
public function testMergeUsers() {
16+
17+
//it does not fail with existing users
18+
$req = new AddUser('target');
19+
$resp = $this->client->send($req);
20+
$req = $this->createRequest('target','entity_id');
21+
$resp = $this->client->send($req);
22+
23+
//it fails with nonexisting user
24+
$req = $this->createRequest('nonex_id','entity_id');
25+
try {
26+
27+
$this->client->send($req);
28+
throw new \Exception('Exception was not thrown');
29+
}
30+
catch(Exc\ResponseException $e)
31+
{
32+
$this->assertEquals(404, $e->status_code);
33+
}
34+
35+
}
36+
}
37+
38+
?>

tests/RemoveFromGroupTestCase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class RemoveFromGroupTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($set_id,$type,$entity_id);
14+
15+
public function testRemoveFromGroup() {
16+
17+
//it does not fail when removing item that is contained in the set
18+
$req = $this->createRequest('entity_id','item','entity_id');
19+
$resp = $this->client->send($req);
20+
21+
//it fails when removing item that is not contained in the set
22+
$req = $this->createRequest('entity_id','item','not_contained');
23+
try {
24+
25+
$this->client->send($req);
26+
throw new \Exception('Exception was not thrown');
27+
}
28+
catch(Exc\ResponseException $e)
29+
{
30+
$this->assertEquals(404, $e->status_code);
31+
}
32+
33+
}
34+
}
35+
36+
?>

tests/RemoveFromSeriesTestCase.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
11+
abstract class RemoveFromSeriesTestCase extends RecombeeTestCase {
12+
13+
abstract protected function createRequest($set_id,$type,$entity_id,$time);
14+
15+
public function testRemoveFromSeries() {
16+
17+
//it fails when removing item which have different time
18+
$req = $this->createRequest('entity_id','item','entity_id',0);
19+
try {
20+
21+
$this->client->send($req);
22+
throw new \Exception('Exception was not thrown');
23+
}
24+
catch(Exc\ResponseException $e)
25+
{
26+
$this->assertEquals(404, $e->status_code);
27+
}
28+
29+
//it does not fail when removing item that is contained in the set
30+
$req = $this->createRequest('entity_id','item','entity_id',1);
31+
$resp = $this->client->send($req);
32+
33+
//it fails when removing item that is not contained in the set
34+
$req = $this->createRequest('entity_id','item','not_contained',1);
35+
try {
36+
37+
$this->client->send($req);
38+
throw new \Exception('Exception was not thrown');
39+
}
40+
catch(Exc\ResponseException $e)
41+
{
42+
$this->assertEquals(404, $e->status_code);
43+
}
44+
45+
}
46+
}
47+
48+
?>

0 commit comments

Comments
 (0)