]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/api/controllers/PostLinkTest.php
Drop PHP 5.5 compatibility and upgrade PHPUnit to v5.x
[github/shaarli/Shaarli.git] / tests / api / controllers / PostLinkTest.php
index 3ed7bcb072326e98019ab8c16e4a09e8ae5baac8..100a91704f866e383430cf2e690522302ba20957 100644 (file)
@@ -3,11 +3,13 @@
 namespace Shaarli\Api\Controllers;
 
 
+use PHPUnit\Framework\TestCase;
 use Shaarli\Config\ConfigManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
 use Slim\Http\Response;
+use Slim\Router;
 
 /**
  * Class PostLinkTest
@@ -16,13 +18,18 @@ use Slim\Http\Response;
  *
  * @package Shaarli\Api\Controllers
  */
-class PostLinkTest extends \PHPUnit_Framework_TestCase
+class PostLinkTest extends TestCase
 {
     /**
      * @var string datastore to test write operations
      */
     protected static $testDatastore = 'sandbox/datastore.php';
 
+    /**
+     * @var string datastore to test write operations
+     */
+    protected static $testHistory = 'sandbox/history.php';
+
     /**
      * @var ConfigManager instance
      */
@@ -33,6 +40,11 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
      */
     protected $refDB = null;
 
+    /**
+     * @var \History instance.
+     */
+    protected $history;
+
     /**
      * @var Container instance.
      */
@@ -57,13 +69,18 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
         $this->refDB = new \ReferenceLinkDB();
         $this->refDB->write(self::$testDatastore);
 
+        $refHistory = new \ReferenceHistory();
+        $refHistory->write(self::$testHistory);
+        $this->history = new \History(self::$testHistory);
+
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
+        $this->container['history'] = new \History(self::$testHistory);
 
         $this->controller = new Links($this->container);
 
-        $mock = $this->getMock('\Slim\Router', ['relativePathFor']);
+        $mock = $this->createMock(Router::class);
         $mock->expects($this->any())
              ->method('relativePathFor')
              ->willReturn('api/v1/links/1');
@@ -85,6 +102,7 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
     public function tearDown()
     {
         @unlink(self::$testDatastore);
+        @unlink(self::$testHistory);
     }
 
     /**
@@ -112,6 +130,13 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(false, $data['private']);
         $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']));
         $this->assertEquals('', $data['updated']);
+
+        $historyEntry = $this->history->getHistory()[0];
+        $this->assertEquals(\History::CREATED, $historyEntry['event']);
+        $this->assertTrue(
+            (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
+        );
+        $this->assertEquals(43, $historyEntry['id']);
     }
 
     /**