aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2019-01-12 23:55:38 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-13 00:04:42 +0100
commitdea72c711ff740b3b829d238fcf85648465143a0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /tests/api/controllers/links
parenta43e7842e44068584302ec1d6349155b571d9c96 (diff)
downloadShaarli-dea72c711ff740b3b829d238fcf85648465143a0.tar.gz
Shaarli-dea72c711ff740b3b829d238fcf85648465143a0.tar.zst
Shaarli-dea72c711ff740b3b829d238fcf85648465143a0.zip
Optimize and cleanup imports
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/api/controllers/links')
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php18
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php3
-rw-r--r--tests/api/controllers/links/GetLinksTest.php10
-rw-r--r--tests/api/controllers/links/PostLinkTest.php9
-rw-r--r--tests/api/controllers/links/PutLinkTest.php11
5 files changed, 27 insertions, 24 deletions
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index adca9a4e..90193e28 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -3,13 +3,15 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
7use Slim\Container; 9use Slim\Container;
8use Slim\Http\Environment; 10use Slim\Http\Environment;
9use Slim\Http\Request; 11use Slim\Http\Request;
10use Slim\Http\Response; 12use Slim\Http\Response;
11 13
12class DeleteLinkTest extends \PHPUnit_Framework_TestCase 14class DeleteLinkTest extends \PHPUnit\Framework\TestCase
13{ 15{
14 /** 16 /**
15 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 34 protected $refDB = null;
33 35
34 /** 36 /**
35 * @var \Shaarli\Bookmark\LinkDB instance. 37 * @var LinkDB instance.
36 */ 38 */
37 protected $linkDB; 39 protected $linkDB;
38 40
39 /** 41 /**
40 * @var \Shaarli\History instance. 42 * @var HistoryController instance.
41 */ 43 */
42 protected $history; 44 protected $history;
43 45
@@ -59,10 +61,10 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
59 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
60 $this->refDB = new \ReferenceLinkDB(); 62 $this->refDB = new \ReferenceLinkDB();
61 $this->refDB->write(self::$testDatastore); 63 $this->refDB->write(self::$testDatastore);
62 $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); 64 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory(); 65 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 66 $refHistory->write(self::$testHistory);
65 $this->history = new \Shaarli\History(self::$testHistory); 67 $this->history = new History(self::$testHistory);
66 $this->container = new Container(); 68 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
68 $this->container['db'] = $this->linkDB; 70 $this->container['db'] = $this->linkDB;
@@ -96,11 +98,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
96 $this->assertEquals(204, $response->getStatusCode()); 98 $this->assertEquals(204, $response->getStatusCode());
97 $this->assertEmpty((string) $response->getBody()); 99 $this->assertEmpty((string) $response->getBody());
98 100
99 $this->linkDB = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); 101 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
100 $this->assertFalse(isset($this->linkDB[$id])); 102 $this->assertFalse(isset($this->linkDB[$id]));
101 103
102 $historyEntry = $this->history->getHistory()[0]; 104 $historyEntry = $this->history->getHistory()[0];
103 $this->assertEquals(\Shaarli\History::DELETED, $historyEntry['event']); 105 $this->assertEquals(History::DELETED, $historyEntry['event']);
104 $this->assertTrue( 106 $this->assertTrue(
105 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 107 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
106 ); 108 );
@@ -110,7 +112,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
110 /** 112 /**
111 * Test DELETE link endpoint: reach not existing ID. 113 * Test DELETE link endpoint: reach not existing ID.
112 * 114 *
113 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException 115 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
114 */ 116 */
115 public function testDeleteLink404() 117 public function testDeleteLink404()
116 { 118 {
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index bf58000b..cb9b7f6a 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -3,7 +3,6 @@
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6
7use Slim\Container; 6use Slim\Container;
8use Slim\Http\Environment; 7use Slim\Http\Environment;
9use Slim\Http\Request; 8use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
18 * 17 *
19 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
20 */ 19 */
21class GetLinkIdTest extends \PHPUnit_Framework_TestCase 20class GetLinkIdTest extends \PHPUnit\Framework\TestCase
22{ 21{
23 /** 22 /**
24 * @var string datastore to test write operations 23 * @var string datastore to test write operations
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index 1008d7b2..711a3152 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 6use Slim\Container;
7use Slim\Http\Environment; 7use Slim\Http\Environment;
8use Slim\Http\Request; 8use Slim\Http\Request;
@@ -17,7 +17,7 @@ use Slim\Http\Response;
17 * 17 *
18 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
19 */ 19 */
20class GetLinksTest extends \PHPUnit_Framework_TestCase 20class GetLinksTest extends \PHPUnit\Framework\TestCase
21{ 21{
22 /** 22 /**
23 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -60,7 +60,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
60 60
61 $this->container = new Container(); 61 $this->container = new Container();
62 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
63 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new LinkDB(self::$testDatastore, true, false);
64 $this->container['history'] = null; 64 $this->container['history'] = null;
65 65
66 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
@@ -114,7 +114,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
114 $this->assertEquals('sTuff', $first['tags'][0]); 114 $this->assertEquals('sTuff', $first['tags'][0]);
115 $this->assertEquals(false, $first['private']); 115 $this->assertEquals(false, $first['private']);
116 $this->assertEquals( 116 $this->assertEquals(
117 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 117 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
118 $first['created'] 118 $first['created']
119 ); 119 );
120 $this->assertEmpty($first['updated']); 120 $this->assertEmpty($first['updated']);
@@ -125,7 +125,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
125 125
126 // Update date 126 // Update date
127 $this->assertEquals( 127 $this->assertEquals(
128 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), 128 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
129 $link['updated'] 129 $link['updated']
130 ); 130 );
131 } 131 }
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index 24e591db..d683a984 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -4,6 +4,7 @@ namespace Shaarli\Api\Controllers;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
@@ -40,7 +41,7 @@ class PostLinkTest extends TestCase
40 protected $refDB = null; 41 protected $refDB = null;
41 42
42 /** 43 /**
43 * @var \Shaarli\History instance. 44 * @var HistoryController instance.
44 */ 45 */
45 protected $history; 46 protected $history;
46 47
@@ -70,12 +71,12 @@ class PostLinkTest extends TestCase
70 71
71 $refHistory = new \ReferenceHistory(); 72 $refHistory = new \ReferenceHistory();
72 $refHistory->write(self::$testHistory); 73 $refHistory->write(self::$testHistory);
73 $this->history = new \Shaarli\History(self::$testHistory); 74 $this->history = new History(self::$testHistory);
74 75
75 $this->container = new Container(); 76 $this->container = new Container();
76 $this->container['conf'] = $this->conf; 77 $this->container['conf'] = $this->conf;
77 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); 78 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
78 $this->container['history'] = new \Shaarli\History(self::$testHistory); 79 $this->container['history'] = new History(self::$testHistory);
79 80
80 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
81 82
@@ -133,7 +134,7 @@ class PostLinkTest extends TestCase
133 $this->assertEquals('', $data['updated']); 134 $this->assertEquals('', $data['updated']);
134 135
135 $historyEntry = $this->history->getHistory()[0]; 136 $historyEntry = $this->history->getHistory()[0];
136 $this->assertEquals(\Shaarli\History::CREATED, $historyEntry['event']); 137 $this->assertEquals(History::CREATED, $historyEntry['event']);
137 $this->assertTrue( 138 $this->assertTrue(
138 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 139 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
139 ); 140 );
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index eb6c7955..cd815b66 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -4,12 +4,13 @@
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
10use Slim\Http\Response; 11use Slim\Http\Response;
11 12
12class PutLinkTest extends \PHPUnit_Framework_TestCase 13class PutLinkTest extends \PHPUnit\Framework\TestCase
13{ 14{
14 /** 15 /**
15 * @var string datastore to test write operations 16 * @var string datastore to test write operations
@@ -32,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 33 protected $refDB = null;
33 34
34 /** 35 /**
35 * @var \Shaarli\History instance. 36 * @var HistoryController instance.
36 */ 37 */
37 protected $history; 38 protected $history;
38 39
@@ -62,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
62 63
63 $refHistory = new \ReferenceHistory(); 64 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 65 $refHistory->write(self::$testHistory);
65 $this->history = new \Shaarli\History(self::$testHistory); 66 $this->history = new History(self::$testHistory);
66 67
67 $this->container = new Container(); 68 $this->container = new Container();
68 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
69 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); 70 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
70 $this->container['history'] = new \Shaarli\History(self::$testHistory); 71 $this->container['history'] = new History(self::$testHistory);
71 72
72 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
73 74
@@ -119,7 +120,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
119 ); 120 );
120 121
121 $historyEntry = $this->history->getHistory()[0]; 122 $historyEntry = $this->history->getHistory()[0];
122 $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']); 123 $this->assertEquals(History::UPDATED, $historyEntry['event']);
123 $this->assertTrue( 124 $this->assertTrue(
124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 125 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
125 ); 126 );