]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/api/controllers/tags/GetTagsTest.php
Compatibility with PHPUnit 9
[github/shaarli/Shaarli.git] / tests / api / controllers / tags / GetTagsTest.php
index 3fab31b0f462a3ee335b9429240e65919a745e68..3459fdfae361deb737f9e40786e6102a367d223b 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 namespace Shaarli\Api\Controllers;
 
+use Shaarli\Bookmark\BookmarkFileService;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
-
+use Shaarli\History;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -15,7 +17,7 @@ use Slim\Http\Response;
  *
  * @package Shaarli\Api\Controllers
  */
-class GetTagsTest extends \PHPUnit_Framework_TestCase
+class GetTagsTest extends \Shaarli\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -38,9 +40,9 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
     protected $container;
 
     /**
-     * @var \LinkDB instance.
+     * @var BookmarkFileService instance.
      */
-    protected $linkDB;
+    protected $bookmarkService;
 
     /**
      * @var Tags controller instance.
@@ -53,18 +55,21 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
     const NB_FIELDS_TAG = 2;
 
     /**
-     * Before every test, instantiate a new Api with its config, plugins and links.
+     * Before every test, instantiate a new Api with its config, plugins and bookmarks.
      */
-    public function setUp()
+    protected function setUp(): void
     {
         $this->conf = new ConfigManager('tests/utils/config/configJson');
+        $this->conf->set('resource.datastore', self::$testDatastore);
         $this->refDB = new \ReferenceLinkDB();
         $this->refDB->write(self::$testDatastore);
+        $history = new History('sandbox/history.php');
+
+        $this->bookmarkService = new BookmarkFileService($this->conf, $history, true);
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
-        $this->linkDB = new \LinkDB(self::$testDatastore, true, false);
-        $this->container['db'] = $this->linkDB;
+        $this->container['db'] = $this->bookmarkService;
         $this->container['history'] = null;
 
         $this->controller = new Tags($this->container);
@@ -73,7 +78,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
     /**
      * After every test, remove the test datastore.
      */
-    public function tearDown()
+    protected function tearDown(): void
     {
         @unlink(self::$testDatastore);
     }
@@ -83,7 +88,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetTagsAll()
     {
-        $tags = $this->linkDB->linksCountPerTag();
+        $tags = $this->bookmarkService->bookmarksCountPerTag();
         $env = Environment::mock([
             'REQUEST_METHOD' => 'GET',
         ]);
@@ -136,7 +141,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetTagsLimitAll()
     {
-        $tags = $this->linkDB->linksCountPerTag();
+        $tags = $this->bookmarkService->bookmarksCountPerTag();
         $env = Environment::mock([
             'REQUEST_METHOD' => 'GET',
             'QUERY_STRING' => 'limit=all'
@@ -170,7 +175,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetTagsVisibilityPrivate()
     {
-        $tags = $this->linkDB->linksCountPerTag([], 'private');
+        $tags = $this->bookmarkService->bookmarksCountPerTag([], 'private');
         $env = Environment::mock([
             'REQUEST_METHOD' => 'GET',
             'QUERY_STRING' => 'visibility=private'
@@ -190,7 +195,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetTagsVisibilityPublic()
     {
-        $tags = $this->linkDB->linksCountPerTag([], 'public');
+        $tags = $this->bookmarkService->bookmarksCountPerTag([], 'public');
         $env = Environment::mock(
             [
                 'REQUEST_METHOD' => 'GET',