diff options
Diffstat (limited to 'tests/api/controllers/tags/DeleteTagTest.php')
-rw-r--r-- | tests/api/controllers/tags/DeleteTagTest.php | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index c6748872..37f07229 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use malkusch\lock\mutex\NoMutex; | ||
6 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Bookmark\LinkDB; | 8 | use Shaarli\Bookmark\LinkDB; |
8 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
@@ -12,7 +13,7 @@ use Slim\Http\Environment; | |||
12 | use Slim\Http\Request; | 13 | use Slim\Http\Request; |
13 | use Slim\Http\Response; | 14 | use Slim\Http\Response; |
14 | 15 | ||
15 | class DeleteTagTest extends \PHPUnit\Framework\TestCase | 16 | class DeleteTagTest extends \Shaarli\TestCase |
16 | { | 17 | { |
17 | /** | 18 | /** |
18 | * @var string datastore to test write operations | 19 | * @var string datastore to test write operations |
@@ -54,11 +55,15 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
54 | */ | 55 | */ |
55 | protected $controller; | 56 | protected $controller; |
56 | 57 | ||
58 | /** @var NoMutex */ | ||
59 | protected $mutex; | ||
60 | |||
57 | /** | 61 | /** |
58 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. | 62 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
59 | */ | 63 | */ |
60 | public function setUp() | 64 | protected function setUp(): void |
61 | { | 65 | { |
66 | $this->mutex = new NoMutex(); | ||
62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 67 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
63 | $this->conf->set('resource.datastore', self::$testDatastore); | 68 | $this->conf->set('resource.datastore', self::$testDatastore); |
64 | $this->refDB = new \ReferenceLinkDB(); | 69 | $this->refDB = new \ReferenceLinkDB(); |
@@ -66,7 +71,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
66 | $refHistory = new \ReferenceHistory(); | 71 | $refHistory = new \ReferenceHistory(); |
67 | $refHistory->write(self::$testHistory); | 72 | $refHistory->write(self::$testHistory); |
68 | $this->history = new History(self::$testHistory); | 73 | $this->history = new History(self::$testHistory); |
69 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
70 | 75 | ||
71 | $this->container = new Container(); | 76 | $this->container = new Container(); |
72 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
@@ -79,7 +84,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
79 | /** | 84 | /** |
80 | * After each test, remove the test datastore. | 85 | * After each test, remove the test datastore. |
81 | */ | 86 | */ |
82 | public function tearDown() | 87 | protected function tearDown(): void |
83 | { | 88 | { |
84 | @unlink(self::$testDatastore); | 89 | @unlink(self::$testDatastore); |
85 | @unlink(self::$testHistory); | 90 | @unlink(self::$testHistory); |
@@ -102,7 +107,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
102 | $this->assertEquals(204, $response->getStatusCode()); | 107 | $this->assertEquals(204, $response->getStatusCode()); |
103 | $this->assertEmpty((string) $response->getBody()); | 108 | $this->assertEmpty((string) $response->getBody()); |
104 | 109 | ||
105 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 110 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
106 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 111 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
107 | $this->assertFalse(isset($tags[$tagName])); | 112 | $this->assertFalse(isset($tags[$tagName])); |
108 | 113 | ||
@@ -136,7 +141,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
136 | $this->assertEquals(204, $response->getStatusCode()); | 141 | $this->assertEquals(204, $response->getStatusCode()); |
137 | $this->assertEmpty((string) $response->getBody()); | 142 | $this->assertEmpty((string) $response->getBody()); |
138 | 143 | ||
139 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 144 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
140 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 145 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
141 | $this->assertFalse(isset($tags[$tagName])); | 146 | $this->assertFalse(isset($tags[$tagName])); |
142 | $this->assertTrue($tags[strtolower($tagName)] > 0); | 147 | $this->assertTrue($tags[strtolower($tagName)] > 0); |
@@ -150,12 +155,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
150 | 155 | ||
151 | /** | 156 | /** |
152 | * Test DELETE tag endpoint: reach not existing tag. | 157 | * Test DELETE tag endpoint: reach not existing tag. |
153 | * | ||
154 | * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException | ||
155 | * @expectedExceptionMessage Tag not found | ||
156 | */ | 158 | */ |
157 | public function testDeleteLink404() | 159 | public function testDeleteLink404() |
158 | { | 160 | { |
161 | $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); | ||
162 | $this->expectExceptionMessage('Tag not found'); | ||
163 | |||
159 | $tagName = 'nopenope'; | 164 | $tagName = 'nopenope'; |
160 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 165 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
161 | $this->assertFalse(isset($tags[$tagName])); | 166 | $this->assertFalse(isset($tags[$tagName])); |