aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/GetLinkIdTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api/controllers/links/GetLinkIdTest.php')
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php18
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index c26411ac..1ec56ef3 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -2,6 +2,7 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use malkusch\lock\mutex\NoMutex;
5use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
6use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
@@ -20,7 +21,7 @@ use Slim\Http\Response;
20 * 21 *
21 * @package Shaarli\Api\Controllers 22 * @package Shaarli\Api\Controllers
22 */ 23 */
23class GetLinkIdTest extends \PHPUnit\Framework\TestCase 24class GetLinkIdTest 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 GetLinkIdTest extends \PHPUnit\Framework\TestCase
55 /** 56 /**
56 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 57 * Before each 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 GetLinkIdTest 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 GetLinkIdTest extends \PHPUnit\Framework\TestCase
74 /** 76 /**
75 * After each test, remove the test datastore. 77 * After each 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 }
@@ -102,7 +104,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
102 $this->assertEquals($id, $data['id']); 104 $this->assertEquals($id, $data['id']);
103 105
104 // Check link elements 106 // Check link elements
105 $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); 107 $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']);
106 $this->assertEquals('WDWyig', $data['shorturl']); 108 $this->assertEquals('WDWyig', $data['shorturl']);
107 $this->assertEquals('Link title: @website', $data['title']); 109 $this->assertEquals('Link title: @website', $data['title']);
108 $this->assertEquals( 110 $this->assertEquals(
@@ -120,12 +122,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
120 122
121 /** 123 /**
122 * Test basic getLink service: get non existent link => ApiLinkNotFoundException. 124 * Test basic getLink service: get non existent link => ApiLinkNotFoundException.
123 *
124 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
125 * @expectedExceptionMessage Link not found
126 */ 125 */
127 public function testGetLink404() 126 public function testGetLink404()
128 { 127 {
128 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
129 $this->expectExceptionMessage('Link not found');
130
129 $env = Environment::mock([ 131 $env = Environment::mock([
130 'REQUEST_METHOD' => 'GET', 132 'REQUEST_METHOD' => 'GET',
131 ]); 133 ]);