X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fapi%2Fcontrollers%2Ftags%2FPutTagTest.php;h=74edde787b745dbddeda6308e51d94c8bd8df61f;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=c45fa7222a46426f71e56540e8327e7d4913cb20;hpb=bdc5152d486ca75372c271f94623b248bc127800;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index c45fa722..74edde78 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -1,16 +1,18 @@ conf = new ConfigManager('tests/utils/config/configJson.json.php'); + $this->conf = new ConfigManager('tests/utils/config/configJson'); + $this->conf->set('resource.datastore', self::$testDatastore); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); - $refHistory = new \ReferenceHistory(); $refHistory->write(self::$testHistory); - $this->history = new \Shaarli\History(self::$testHistory); + $this->history = new History(self::$testHistory); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->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'] = $this->history; $this->controller = new Tags($this->container); @@ -82,7 +84,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); @@ -108,17 +110,17 @@ class PutTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals($newName, $data['name']); $this->assertEquals(2, $data['occurrences']); - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertNotTrue(isset($tags[$tagName])); $this->assertEquals(2, $tags[$newName]); $historyEntry = $this->history->getHistory()[0]; - $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); $historyEntry = $this->history->getHistory()[1]; - $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']); + $this->assertEquals(History::UPDATED, $historyEntry['event']); $this->assertTrue( (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] ); @@ -132,7 +134,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase $tagName = 'gnu'; $newName = 'w3c'; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(1, $tags[$newName]); $this->assertEquals(2, $tags[$tagName]); @@ -150,23 +152,23 @@ class PutTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals($newName, $data['name']); $this->assertEquals(3, $data['occurrences']); - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertNotTrue(isset($tags[$tagName])); $this->assertEquals(3, $tags[$newName]); } /** * Test tag update with an empty new tag name => ApiBadParametersException - * - * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException - * @expectedExceptionMessage New tag name is required in the request body */ public function testPutTagEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class); + $this->expectExceptionMessage('New tag name is required in the request body'); + $tagName = 'gnu'; $newName = ''; - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(2, $tags[$tagName]); $env = Environment::mock([ @@ -184,7 +186,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase try { $this->controller->putTag($request, new Response(), ['tagName' => $tagName]); } catch (ApiBadParametersException $e) { - $tags = $this->linkDB->linksCountPerTag(); + $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertEquals(2, $tags[$tagName]); throw $e; } @@ -192,12 +194,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase /** * Test tag update on non existent tag => ApiTagNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testPutTag404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]);