From e26e2060f5470ce8bf4c5973284bae07b8af170a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 17 Jan 2020 21:34:12 +0100 Subject: Add and update unit test for the new system (Bookmark + Service) See #1307 --- tests/api/controllers/links/GetLinksTest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests/api/controllers/links/GetLinksTest.php') diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 711a3152..4e2d55ac 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -1,8 +1,11 @@ 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->container = new Container(); $this->container['conf'] = $this->conf; - $this->container['db'] = new LinkDB(self::$testDatastore, true, false); + $this->container['db'] = new BookmarkFileService($this->conf, $history, true); $this->container['history'] = null; $this->controller = new Links($this->container); @@ -75,7 +80,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase } /** - * Test basic getLinks service: returns all links. + * Test basic getLinks service: returns all bookmarks. */ public function testGetLinks() { @@ -114,7 +119,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase $this->assertEquals('sTuff', $first['tags'][0]); $this->assertEquals(false, $first['private']); $this->assertEquals( - \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), $first['created'] ); $this->assertEmpty($first['updated']); @@ -125,7 +130,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase // Update date $this->assertEquals( - \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), + \DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), $link['updated'] ); } -- cgit v1.2.3 From f7f08ceec1b218e1525153e8bd3d0199f2fb1c9d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 28 Jul 2020 22:24:41 +0200 Subject: Fix basePath in unit tests reference DB --- tests/api/controllers/links/GetLinksTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/api/controllers/links/GetLinksTest.php') diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 4e2d55ac..d02e6fad 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -109,7 +109,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase // Check first element fields $first = $data[2]; - $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); + $this->assertEquals('http://domain.tld/shaare/WDWyig', $first['url']); $this->assertEquals('WDWyig', $first['shorturl']); $this->assertEquals('Link title: @website', $first['title']); $this->assertEquals( -- cgit v1.2.3 From 8f60e1206e45e67c96a7630d4ff94e72fe875f09 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Sep 2020 15:08:39 +0200 Subject: Comply with PHPUnit V8: setup/teardown functions must return void --- tests/api/controllers/links/GetLinksTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/api/controllers/links/GetLinksTest.php') diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index d02e6fad..01c40c2f 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -55,7 +55,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase /** * 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); @@ -74,7 +74,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } -- cgit v1.2.3 From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/api/controllers/links/GetLinksTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/api/controllers/links/GetLinksTest.php') diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 01c40c2f..ca1bfc63 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -20,7 +20,7 @@ use Slim\Http\Response; * * @package Shaarli\Api\Controllers */ -class GetLinksTest extends \PHPUnit\Framework\TestCase +class GetLinksTest extends \Shaarli\TestCase { /** * @var string datastore to test write operations -- cgit v1.2.3