aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/DeleteLinkTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api/controllers/links/DeleteLinkTest.php')
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php19
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 6c2b3698..805c9be3 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -3,6 +3,7 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use malkusch\lock\mutex\NoMutex;
6use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
8use Shaarli\History; 9use Shaarli\History;
@@ -11,7 +12,7 @@ use Slim\Http\Environment;
11use Slim\Http\Request; 12use Slim\Http\Request;
12use Slim\Http\Response; 13use Slim\Http\Response;
13 14
14class DeleteLinkTest extends \PHPUnit\Framework\TestCase 15class DeleteLinkTest extends \Shaarli\TestCase
15{ 16{
16 /** 17 /**
17 * @var string datastore to test write operations 18 * @var string datastore to test write operations
@@ -53,11 +54,15 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
53 */ 54 */
54 protected $controller; 55 protected $controller;
55 56
57 /** @var NoMutex */
58 protected $mutex;
59
56 /** 60 /**
57 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 61 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
58 */ 62 */
59 public function setUp() 63 protected function setUp(): void
60 { 64 {
65 $this->mutex = new NoMutex();
61 $this->conf = new ConfigManager('tests/utils/config/configJson'); 66 $this->conf = new ConfigManager('tests/utils/config/configJson');
62 $this->conf->set('resource.datastore', self::$testDatastore); 67 $this->conf->set('resource.datastore', self::$testDatastore);
63 $this->refDB = new \ReferenceLinkDB(); 68 $this->refDB = new \ReferenceLinkDB();
@@ -65,7 +70,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
65 $refHistory = new \ReferenceHistory(); 70 $refHistory = new \ReferenceHistory();
66 $refHistory->write(self::$testHistory); 71 $refHistory->write(self::$testHistory);
67 $this->history = new History(self::$testHistory); 72 $this->history = new History(self::$testHistory);
68 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 73 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
69 74
70 $this->container = new Container(); 75 $this->container = new Container();
71 $this->container['conf'] = $this->conf; 76 $this->container['conf'] = $this->conf;
@@ -78,7 +83,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
78 /** 83 /**
79 * After each test, remove the test datastore. 84 * After each test, remove the test datastore.
80 */ 85 */
81 public function tearDown() 86 protected function tearDown(): void
82 { 87 {
83 @unlink(self::$testDatastore); 88 @unlink(self::$testDatastore);
84 @unlink(self::$testHistory); 89 @unlink(self::$testHistory);
@@ -100,7 +105,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
100 $this->assertEquals(204, $response->getStatusCode()); 105 $this->assertEquals(204, $response->getStatusCode());
101 $this->assertEmpty((string) $response->getBody()); 106 $this->assertEmpty((string) $response->getBody());
102 107
103 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 108 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
104 $this->assertFalse($this->bookmarkService->exists($id)); 109 $this->assertFalse($this->bookmarkService->exists($id));
105 110
106 $historyEntry = $this->history->getHistory()[0]; 111 $historyEntry = $this->history->getHistory()[0];
@@ -113,11 +118,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
113 118
114 /** 119 /**
115 * Test DELETE link endpoint: reach not existing ID. 120 * Test DELETE link endpoint: reach not existing ID.
116 *
117 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
118 */ 121 */
119 public function testDeleteLink404() 122 public function testDeleteLink404()
120 { 123 {
124 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
125
121 $id = -1; 126 $id = -1;
122 $this->assertFalse($this->bookmarkService->exists($id)); 127 $this->assertFalse($this->bookmarkService->exists($id));
123 $env = Environment::mock([ 128 $env = Environment::mock([