namespace Shaarli\Api;
use Shaarli\Config\ConfigManager;
-
+use Shaarli\History;
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;
*
* @package Api
*/
-class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase
+class ApiMiddlewareTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations
protected static $testDatastore = 'sandbox/datastore.php';
/**
- * @var \ConfigManager instance
+ * @var ConfigManager instance
*/
protected $conf;
protected $container;
/**
- * 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.json.php');
+ $this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('api.secret', 'NapoleonWasALizard');
$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['history'] = $history;
}
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: API is disabled', $body->message);
- $this->assertContains('ApiAuthorizationException', $body->stacktrace);
+ $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: JWT token not provided', $body->message);
- $this->assertContains('ApiAuthorizationException', $body->stacktrace);
+ $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message);
- $this->assertContains('ApiAuthorizationException', $body->stacktrace);
+ $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Invalid JWT header', $body->message);
- $this->assertContains('ApiAuthorizationException', $body->stacktrace);
+ $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Malformed JWT token', $body->message);
- $this->assertContains('ApiAuthorizationException', $body->stacktrace);
+ $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
}