aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/GetLinksTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api/controllers/links/GetLinksTest.php')
-rw-r--r--tests/api/controllers/links/GetLinksTest.php14
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index 4e2d55ac..b1c46ee2 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -1,6 +1,7 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use malkusch\lock\mutex\NoMutex;
4use Shaarli\Bookmark\Bookmark; 5use Shaarli\Bookmark\Bookmark;
5use Shaarli\Bookmark\BookmarkFileService; 6use Shaarli\Bookmark\BookmarkFileService;
6use Shaarli\Bookmark\LinkDB; 7use Shaarli\Bookmark\LinkDB;
@@ -20,7 +21,7 @@ use Slim\Http\Response;
20 * 21 *
21 * @package Shaarli\Api\Controllers 22 * @package Shaarli\Api\Controllers
22 */ 23 */
23class GetLinksTest extends \PHPUnit\Framework\TestCase 24class GetLinksTest extends \Shaarli\TestCase
24{ 25{
25 /** 26 /**
26 * @var string datastore to test write operations 27 * @var string datastore to test write operations
@@ -55,8 +56,9 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
55 /** 56 /**
56 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 57 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
57 */ 58 */
58 public function setUp() 59 protected function setUp(): void
59 { 60 {
61 $mutex = new NoMutex();
60 $this->conf = new ConfigManager('tests/utils/config/configJson'); 62 $this->conf = new ConfigManager('tests/utils/config/configJson');
61 $this->conf->set('resource.datastore', self::$testDatastore); 63 $this->conf->set('resource.datastore', self::$testDatastore);
62 $this->refDB = new \ReferenceLinkDB(); 64 $this->refDB = new \ReferenceLinkDB();
@@ -65,7 +67,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
65 67
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'] = new BookmarkFileService($this->conf, $history, true); 70 $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
69 $this->container['history'] = null; 71 $this->container['history'] = null;
70 72
71 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
@@ -74,7 +76,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
74 /** 76 /**
75 * After every test, remove the test datastore. 77 * After every test, remove the test datastore.
76 */ 78 */
77 public function tearDown() 79 protected function tearDown(): void
78 { 80 {
79 @unlink(self::$testDatastore); 81 @unlink(self::$testDatastore);
80 } 82 }
@@ -109,7 +111,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
109 111
110 // Check first element fields 112 // Check first element fields
111 $first = $data[2]; 113 $first = $data[2];
112 $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); 114 $this->assertEquals('http://domain.tld/shaare/WDWyig', $first['url']);
113 $this->assertEquals('WDWyig', $first['shorturl']); 115 $this->assertEquals('WDWyig', $first['shorturl']);
114 $this->assertEquals('Link title: @website', $first['title']); 116 $this->assertEquals('Link title: @website', $first['title']);
115 $this->assertEquals( 117 $this->assertEquals(
@@ -396,7 +398,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
396 $response = $this->controller->getLinks($request, new Response()); 398 $response = $this->controller->getLinks($request, new Response());
397 $this->assertEquals(200, $response->getStatusCode()); 399 $this->assertEquals(200, $response->getStatusCode());
398 $data = json_decode((string) $response->getBody(), true); 400 $data = json_decode((string) $response->getBody(), true);
399 $this->assertEquals(4, count($data)); 401 $this->assertEquals(5, count($data));
400 $this->assertEquals(6, $data[0]['id']); 402 $this->assertEquals(6, $data[0]['id']);
401 403
402 // wildcard: placeholder at the middle 404 // wildcard: placeholder at the middle