diff --git a/composer.json b/composer.json
index 2c413cbef..41cda21da 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
"require-dev": {
"maximebf/debugbar": "^1.15",
"phpunit/phpunit": "6.*",
- "phpunit/dbunit": ">=3.0"
+ "symfony/yaml": "^3.3.6"
},
"autoload": {
"psr-0": { "": "application/libraries/" },
diff --git a/tests/PHPUnit/Ilch/DatabaseTestCase.php b/tests/PHPUnit/Ilch/DatabaseTestCase.php
index 5a4f5bbd9..1b39af949 100644
--- a/tests/PHPUnit/Ilch/DatabaseTestCase.php
+++ b/tests/PHPUnit/Ilch/DatabaseTestCase.php
@@ -5,8 +5,8 @@
namespace PHPUnit\Ilch;
-use Ilch\Registry as Registry;
-use Ilch\Database\Factory as Factory;
+use Ilch\Registry;
+use Ilch\Database\Factory;
/**
* Base class for database test cases for Ilch.
@@ -16,7 +16,7 @@
*
* @package ilch_phpunit
*/
-abstract class DatabaseTestCase extends \PHPUnit\DbUnit\TestCase
+abstract class DatabaseTestCase extends \PHPUnit\Framework\TestCase
{
/** @var int don't automatically provision - for individual proovsioning */
const PROVISION_DISABLED = 0;
@@ -33,12 +33,10 @@ abstract class DatabaseTestCase extends \PHPUnit\DbUnit\TestCase
static protected $configData = [];
/**
- * Only instantiate pdo once for test clean-up/fixture load
- *
- * @static Static so we can don't have to connect for every test again.
- * @var \PDO
+ * Files used for creating the database schema
+ * @var array
*/
- static private $pdo = null;
+ protected static $dbSchemaFiles = [__DIR__ . '/_files/db_schema.sql'];
/**
* @var bool
@@ -51,34 +49,15 @@ abstract class DatabaseTestCase extends \PHPUnit\DbUnit\TestCase
*/
static protected $fillDbOnSetUp = self::PROVISION_ON_SETUP;
- /**
- * Files used for creating the database schema
- * @var array
- */
- protected static $dbSchemaFiles = [__DIR__ . '/_files/db_schema.sql'];
-
- /**
- * Instantiated PHPUnit_Extensions_Database_DB_IDatabaseConnection for the tests.
- *
- * @var \PHPUnit_Extensions_Database_DB_IDatabaseConnection
- */
- private $conn = null;
-
/**
* The db instance to test with.
*
* @var \Ilch\Database\MySQL
*/
- protected $db = null;
-
- /**
- * Save provisioning state for PROVISION_ON_SETUP_BEFORE_CLASS
- * @var bool
- */
- private $dbProvisioned;
+ protected $db;
/**
- * Setup config
+ * This method is called before the first test of this test class is run.
*/
public static function setUpBeforeClass()
{
@@ -97,8 +76,8 @@ public static function setUpBeforeClass()
if (static::$dropTablesOnProvision) {
static::dropTables($db);
}
- $db->queryMulti(static::getSchemaSQLQueries());
}
+ $db->queryMulti(static::getSchemaSQLQueries());
}
/**
@@ -109,14 +88,12 @@ protected function setUp()
$this->db = Registry::get('db');
if ($this->db === false) {
- $this->markTestIncomplete('Necessary DB configuration is not set.');
+ self::markTestIncomplete('Necessary DB configuration is not set.');
parent::setUp();
return;
}
- /*
- * Deleting all tables from the db and setting up the db using the given schema
- */
+ // Deleting all tables from the db and setting up the db using the given schema
if (static::$fillDbOnSetUp === self::PROVISION_ON_SETUP) {
if (static::$dropTablesOnProvision) {
static::dropTables($this->db);
@@ -127,43 +104,6 @@ protected function setUp()
parent::setUp();
}
- /**
- * Creates the db connection to the test database.
- *
- * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection|null Returns null if the necessary config was not set
- */
- final public function getConnection()
- {
- $dbData = [];
- $config = Registry::get('config');
-
- foreach (['dbEngine', 'dbHost', 'dbUser', 'dbPassword', 'dbName', 'dbPrefix'] as $configKey) {
- /*
- * Using the data for the db from the config.
- * We check if special config variables for this test execution exist.
- * If so we gonna use it. Otherwise we have to skip the tests.
- */
- if ($config->get($configKey) !== null) {
- $dbData[$configKey] = $config->get($configKey);
- } else {
- $this->markTestSkipped('Necessary DB configuration is not set.');
- }
- }
-
- $dsn = strtolower($dbData['dbEngine']) . ':dbname=' . $dbData['dbName'] . ';host=' . $dbData['dbHost'];
- $dbData['dbDsn'] = $dsn;
-
- if ($this->conn === null) {
- if (self::$pdo === null) {
- self::$pdo = new \PDO($dbData['dbDsn'], $dbData['dbUser'], $dbData['dbPassword']);
- }
-
- $this->conn = $this->createDefaultDBConnection(self::$pdo, $dbData['dbName']);
- }
-
- return $this->conn;
- }
-
/**
* Returns database schema sql statements to initialize database
*
@@ -171,7 +111,7 @@ final public function getConnection()
*/
protected static function getSchemaSQLQueries()
{
- return array_reduce(self::$dbSchemaFiles, function($carry, $fileName) {
+ return array_reduce(self::$dbSchemaFiles, static function($carry, $fileName) {
$carry .= file_get_contents($fileName);
return $carry;
}, '');
@@ -179,6 +119,7 @@ protected static function getSchemaSQLQueries()
/**
* Deleting all tables from the db
+ *
* @param \Ilch\Database\Mysql $db
*/
protected static function dropTables(\Ilch\Database\Mysql $db)
@@ -191,23 +132,4 @@ protected static function dropTables(\Ilch\Database\Mysql $db)
$db->query($sql);
}
}
-
- /**
- * Returns the database operation executed in test setup.
- *
- * @return \PHPUnit_Extensions_Database_Operation_IDatabaseOperation
- */
- protected function getSetUpOperation()
- {
- if (static::$fillDbOnSetUp === self::PROVISION_ON_SETUP_BEFORE_CLASS) {
- if ($this->dbProvisioned) {
- return \PHPUnit\DbUnit\Operation\Factory::NONE();
- }
- $this->dbProvisioned = true;
- } elseif (static::$fillDbOnSetUp === self::PROVISION_DISABLED) {
- return \PHPUnit\DbUnit\Operation\Factory::NONE();
- }
-
- return \PHPUnit\DbUnit\Operation\Factory::CLEAN_INSERT();
- }
}
diff --git a/tests/PHPUnit/Ilch/PhpunitDataset.php b/tests/PHPUnit/Ilch/PhpunitDataset.php
new file mode 100644
index 000000000..374ea1139
--- /dev/null
+++ b/tests/PHPUnit/Ilch/PhpunitDataset.php
@@ -0,0 +1,95 @@
+db = $db;
+ }
+
+ /**
+ * Load information from multiple files (yml).
+ *
+ * @param array $fullpaths full paths to yml files to load.
+ */
+ public function loadFromFiles(array $fullpaths)
+ {
+ foreach ($fullpaths as $table => $fullpath) {
+ // Only a table when it's an associative array.
+ $table = \is_int($table) ? null : $table;
+ $this->loadFromFile($fullpath, $table);
+ }
+ }
+
+ /**
+ * Load information from one file (yml).
+ *
+ * @param string $fullpath full path to yml file to load.
+ */
+ public function loadFromFile(string $fullpath)
+ {
+ if (!file_exists($fullpath)) {
+ throw new coding_exception('File not found: ' . $fullpath);
+ }
+
+ if (!is_readable($fullpath)) {
+ throw new coding_exception('File not readable: ' . $fullpath);
+ }
+
+ $extension = strtolower(pathinfo($fullpath, PATHINFO_EXTENSION));
+ if ($extension !== 'yml') {
+ throw new coding_exception('Cannot handle files with extension: ' . $extension);
+ }
+
+ $this->loadFromString(file_get_contents($fullpath));
+ }
+
+ /**
+ * Load information from a string (yaml).
+ *
+ * @param string $content contents of yaml file to load.
+ */
+ public function loadFromString(string $content)
+ {
+ try {
+ $parsedYaml = Yaml::parse($content);
+ $this->sendToDatabase($parsedYaml);
+ } catch (ParseException $exception) {
+ printf('Unable to parse the YAML string: %s', $exception->getMessage());
+ }
+ }
+
+ /**
+ * Send all the information to the database.
+ *
+ * @param array $tables
+ */
+ public function sendToDatabase(array $tables)
+ {
+ foreach($tables as $table => $rows) {
+ $tableNotEmpty = (bool) $this->db->select('*')
+ ->from($table)
+ ->execute()
+ ->fetchCell();
+
+ if ($tableNotEmpty) {
+ $this->db->truncate($table);
+ }
+
+ foreach($rows as $row => $columns) {
+ $this->db->insert($table)
+ ->values($columns)
+ ->execute();
+ }
+ }
+ }
+}
diff --git a/tests/PHPUnit/Ilch/TestCase.php b/tests/PHPUnit/Ilch/TestCase.php
index 2790c4351..7bfd4487c 100644
--- a/tests/PHPUnit/Ilch/TestCase.php
+++ b/tests/PHPUnit/Ilch/TestCase.php
@@ -39,7 +39,7 @@ protected function tearDown()
parent::tearDown();
foreach ($this->tearDownCallbacks as $callback) {
- if (is_callable($callback)) {
+ if (\is_callable($callback)) {
$callback();
}
}
diff --git a/tests/PHPUnit/Ilch/TestHelper.php b/tests/PHPUnit/Ilch/TestHelper.php
index ee26d6d68..531185c78 100644
--- a/tests/PHPUnit/Ilch/TestHelper.php
+++ b/tests/PHPUnit/Ilch/TestHelper.php
@@ -5,7 +5,7 @@
namespace PHPUnit\Ilch;
-use Ilch\Registry as Registry;
+use Ilch\Registry;
use Ilch\Config\File as Config;
/**
@@ -29,14 +29,12 @@ class TestHelper
*/
public static function setConfigInRegistry(array $configData)
{
- if (static::$config === null) {
- if (!Registry::has('config') && file_exists(CONFIG_PATH . '/config.php')) {
- static::$config = new Config();
- static::$config->loadConfigFromFile(CONFIG_PATH . '/config.php');
+ if ((static::$config === null) && !Registry::has('config') && file_exists(CONFIG_PATH . '/config.php')) {
+ static::$config = new Config();
+ static::$config->loadConfigFromFile(CONFIG_PATH . '/config.php');
- foreach ($configData as $configKey => $configValue) {
- static::$config->set($configKey, $configValue);
- }
+ foreach ($configData as $configKey => $configValue) {
+ static::$config->set($configKey, $configValue);
}
}
diff --git a/tests/libraries/ilch/AccessesTest.php b/tests/libraries/ilch/AccessesTest.php
index 89544aa20..6d1f6cf6f 100644
--- a/tests/libraries/ilch/AccessesTest.php
+++ b/tests/libraries/ilch/AccessesTest.php
@@ -9,6 +9,7 @@
use Ilch\Request;
use Ilch\Accesses;
use PHPUnit\Ilch\DatabaseTestCase;
+use PHPUnit\Ilch\PhpunitDataset;
class AccessesTest extends DatabaseTestCase
{
@@ -21,6 +22,8 @@ class AccessesTest extends DatabaseTestCase
protected $_SESSION;
+ protected $phpunitDataset;
+
protected static function getSchemaSQLQueries()
{
return 'CREATE TABLE IF NOT EXISTS `[prefix]_groups` (
@@ -80,28 +83,19 @@ protected static function getSchemaSQLQueries()
public function setUp()
{
parent::setUp();
-
+ $this->phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/_files/mysql_accesses.yml');
$this->request = new Request();
$_SESSION = [];
}
- /**
- * Returns the test dataset.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_IDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/_files/mysql_accesses.yml');
- }
-
public function testHasAccessModule()
{
$_SESSION['user_id'] = 1;
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertTrue($result, 'User 1 should have access.');
+ self::assertTrue($result, 'User 1 should have access.');
}
/**
@@ -114,7 +108,7 @@ public function testHasAccessModuleArticle()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertTrue($result, 'User 2 should have access to the article module.');
+ self::assertTrue($result, 'User 2 should have access to the article module.');
}
/**
@@ -127,7 +121,7 @@ public function testHasAccessModuleCheckout()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertTrue($result, 'User 2 should have access to the checkout module.');
+ self::assertTrue($result, 'User 2 should have access to the checkout module.');
}
/**
@@ -140,7 +134,7 @@ public function testHasAccessModuleForumNoAccess()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertFalse($result, 'User 2 should not have access to the forum module.');
+ self::assertFalse($result, 'User 2 should not have access to the forum module.');
}
public function testHasAccessAdmin()
@@ -149,7 +143,7 @@ public function testHasAccessAdmin()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Admin');
- $this->assertTrue($result, 'An admin should have access.');
+ self::assertTrue($result, 'An admin should have access.');
}
/**
@@ -164,7 +158,7 @@ public function testHasAccessPage()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertTrue($result, 'User 2 should have access to the page.');
+ self::assertTrue($result, 'User 2 should have access to the page.');
}
/**
@@ -180,6 +174,6 @@ public function testHasAccessPageNoAccess()
$accesses = new Accesses($this->request);
$result = $accesses->hasAccess('Module');
- $this->assertFalse($result, 'User 2 should not have access to the page.');
+ self::assertFalse($result, 'User 2 should not have access to the page.');
}
}
diff --git a/tests/libraries/ilch/ConfigTest.php b/tests/libraries/ilch/ConfigTest.php
index 6ed025059..a761f7767 100644
--- a/tests/libraries/ilch/ConfigTest.php
+++ b/tests/libraries/ilch/ConfigTest.php
@@ -36,7 +36,7 @@ public function setUp()
public function testSetAndGetConfig()
{
$this->config->set('email', 'testuser@testmail.com');
- $this->assertEquals(
+ self::assertEquals(
'testuser@testmail.com',
$this->config->get('email'),
'Config value got manipulated unexpectedly.'
@@ -57,7 +57,7 @@ public function testLoadConfigFromFile()
$this->config->loadConfigFromFile(__DIR__ . '/_files/config.php');
- $this->assertEquals(
+ self::assertEquals(
$configArray,
[
'dbHost' => $this->config->get('dbHost'),
diff --git a/tests/libraries/ilch/Database/Mysql/InsertTest.php b/tests/libraries/ilch/Database/Mysql/InsertTest.php
index afbc1ad51..7e1d76ff5 100644
--- a/tests/libraries/ilch/Database/Mysql/InsertTest.php
+++ b/tests/libraries/ilch/Database/Mysql/InsertTest.php
@@ -25,17 +25,15 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['escape', 'getLastInsertId'])
->getMockForAbstractClass();
- $db->expects($this->any())
- ->method('escape')
- ->will($this->returnCallback(function ($value, $addQuotes = false) {
+ $db->method('escape')
+ ->willReturnCallback(function ($value, $addQuotes = false) {
if ($addQuotes) {
$value = '"' . $value . '"';
}
return $value;
- }));
- $db->expects($this->any())
- ->method('getLastInsertId')
- ->will($this->returnValue($this->lastInsetId));
+ });
+ $db->method('getLastInsertId')
+ ->willReturn($this->lastInsetId);
$this->out = new Insert($db);
}
@@ -66,6 +64,6 @@ public function testGenerateSqlForValues()
$expected = 'INSERT INTO `[prefix]_Test` '
. '(`super`,`next`) VALUES ("data","fieldData")';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
}
diff --git a/tests/libraries/ilch/Database/Mysql/ResultTest.php b/tests/libraries/ilch/Database/Mysql/ResultTest.php
index 2d6ed68b1..a606145c7 100644
--- a/tests/libraries/ilch/Database/Mysql/ResultTest.php
+++ b/tests/libraries/ilch/Database/Mysql/ResultTest.php
@@ -1,26 +1,26 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../../_files/mysql_database.yml');
}
/**
@@ -32,7 +32,7 @@ protected function getDataSet()
public function testFetchCell($cellParam, $expected)
{
$result = $this->db->select('*', 'groups')->execute();
- $this->assertEquals($expected, $result->fetchCell($cellParam));
+ self::assertEquals($expected, $result->fetchCell($cellParam));
}
/**
@@ -73,7 +73,7 @@ public function dpForFetchCell()
public function testFetchArray($type, $expected)
{
$result = $this->db->select('*', 'groups')->execute();
- $this->assertEquals($expected, $result->fetchArray($type));
+ self::assertEquals($expected, $result->fetchArray($type));
}
/**
@@ -110,7 +110,7 @@ public function testFetchRow()
->execute();
foreach ($expectedRows as $expectedRow) {
- $this->assertSame($expectedRow, $result->fetchRow());
+ self::assertSame($expectedRow, $result->fetchRow());
}
}
@@ -127,7 +127,7 @@ public function testFetchAssoc()
->execute();
foreach ($expectedRows as $expectedRow) {
- $this->assertSame($expectedRow, $result->fetchAssoc());
+ self::assertSame($expectedRow, $result->fetchAssoc());
}
}
@@ -144,7 +144,7 @@ public function testFetchRows($keyField, $type, $expectedRows)
->limit(2)
->execute();
- $this->assertEquals($expectedRows, $result->fetchRows($keyField, $type));
+ self::assertEquals($expectedRows, $result->fetchRows($keyField, $type));
}
/**
@@ -210,7 +210,7 @@ public function testFetchList($selectFields, $field, $keyField, $expectedList)
->limit(2)
->execute();
- $this->assertEquals($expectedList, $result->fetchList($field, $keyField));
+ self::assertEquals($expectedList, $result->fetchList($field, $keyField));
}
/**
@@ -257,7 +257,7 @@ public function testGetNumRows($limit)
->limit($limit)
->execute();
- $this->assertSame($limit, $result->getFoundRows());
+ self::assertSame($limit, $result->getFoundRows());
}
/**
@@ -280,7 +280,7 @@ public function testGetFieldCount($selectFields, $expected)
->limit(1)
->execute();
- $this->assertSame($expected, $result->getFieldCount());
+ self::assertSame($expected, $result->getFieldCount());
}
/**
@@ -309,7 +309,7 @@ public function testGetFoundRows()
->useFoundRows()
->execute();
- $this->assertSame($expected, $result->getFoundRows());
+ self::assertSame($expected, $result->getFoundRows());
}
public function testSetCurrentRow()
@@ -320,7 +320,7 @@ public function testSetCurrentRow()
$result->setCurrentRow(1);
- $this->assertSame('Guest', $result->fetchCell());
+ self::assertSame('Guest', $result->fetchCell());
}
public function testGetMysqliResult()
@@ -337,7 +337,7 @@ public function testGetMysqliResult()
];
foreach ($mysqliResult as $key => $row) {
- $this->assertSame($expectedRows[$key], $row);
+ self::assertSame($expectedRows[$key], $row);
}
}
}
diff --git a/tests/libraries/ilch/Database/Mysql/SelectTest.php b/tests/libraries/ilch/Database/Mysql/SelectTest.php
index 06d3c1267..b3fd4d4ea 100644
--- a/tests/libraries/ilch/Database/Mysql/SelectTest.php
+++ b/tests/libraries/ilch/Database/Mysql/SelectTest.php
@@ -24,14 +24,13 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['escape'])
->getMockForAbstractClass();
- $db->expects($this->any())
- ->method('escape')
- ->will($this->returnCallback(function ($value, $addQuotes = false) {
+ $db->method('escape')
+ ->willReturnCallback(function ($value, $addQuotes = false) {
if ($addQuotes) {
$value = '"' . $value . '"';
}
return $value;
- }));
+ });
$this->out = new Select($db);
}
@@ -56,7 +55,7 @@ public function testGenerateSqlForTable($table, $expectedSqlPart)
$expected = 'SELECT * FROM ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -93,7 +92,7 @@ public function testGenerateSqlForFields($fields, $expectedSqlPart)
$expected = 'SELECT ' . $expectedSqlPart . ' FROM `[prefix]_Test`';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -149,7 +148,7 @@ public function dpForFields()
*/
public function testGenerateSqlForWhere($where, $expectedSqlPart, $type = null)
{
- if (is_callable($where)) {
+ if (\is_callable($where)) {
$where = $where($this->out);
}
@@ -163,7 +162,7 @@ public function testGenerateSqlForWhere($where, $expectedSqlPart, $type = null)
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' WHERE ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -252,7 +251,7 @@ public function testGenerateSqlForWhereWithSpecialOperator($operator)
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' WHERE `field1` ' . $operator . ' "5"';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -283,7 +282,7 @@ public function testGenerateSqlForOrWhere($where, $type, $orWhere, $expectedSqlP
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' WHERE ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -332,7 +331,7 @@ public function testGenerateSqlForOrderBy(array $order, $expectedSqlPart)
$expected = 'SELECT * FROM `[prefix]_Test` ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -366,7 +365,7 @@ public function testGenerateSqlForLimitWithInteger($limit, $expectedSqlPart)
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' LIMIT ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -395,7 +394,7 @@ public function testGenerateSqlForLimitWithOffset()
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' LIMIT 5, 10';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -413,7 +412,7 @@ public function testGenerateSqlForLimitWithPage($page, $expectedOffset)
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' LIMIT ' . $expectedOffset . ', 10';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -447,7 +446,7 @@ public function testGenerateSqlWithGroup($groupByFields, $expectedSqlPart)
$expected = 'SELECT * FROM `[prefix]_Test`'
. ' GROUP BY ' . $expectedSqlPart;
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
/**
@@ -485,7 +484,7 @@ public function testGenerateSqlForJoinConditions($conditions, $expectedSqlPart)
$expectedSql = 'SELECT * FROM `[prefix]_Test` AS `a`'
. ' INNER JOIN `[prefix]_Table2` AS `b` ON ' . $expectedSqlPart;
- $this->assertEquals($expectedSql, $this->out->generateSql());
+ self::assertEquals($expectedSql, $this->out->generateSql());
}
/**
diff --git a/tests/libraries/ilch/Database/Mysql/UpdateTest.php b/tests/libraries/ilch/Database/Mysql/UpdateTest.php
index 3e45aa850..af1714be0 100644
--- a/tests/libraries/ilch/Database/Mysql/UpdateTest.php
+++ b/tests/libraries/ilch/Database/Mysql/UpdateTest.php
@@ -1,12 +1,11 @@
disableOriginalConstructor()
->setMethods(['escape'])
->getMockForAbstractClass();
- $db->expects($this->any())
- ->method('escape')
- ->will($this->returnCallback(function ($value, $addQuotes = false) {
+ $db->method('escape')
+ ->willReturnCallback(function ($value, $addQuotes = false) {
if ($addQuotes) {
$value = '"' . $value . '"';
}
return $value;
- }));
+ });
$this->out = new Update($db);
}
@@ -61,7 +59,7 @@ public function testGenerateSqlForValues()
$expected = 'UPDATE `[prefix]_Test` SET '
. '`super` = "data",`next` = "fieldData"';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
public function testGenerateSqlForValuesAndSimpleWhere()
@@ -74,6 +72,6 @@ public function testGenerateSqlForValuesAndSimpleWhere()
. '`super` = "data",`next` = "fieldData"'
. ' WHERE `id` = "5"';
- $this->assertEquals($expected, $this->out->generateSql());
+ self::assertEquals($expected, $this->out->generateSql());
}
}
diff --git a/tests/libraries/ilch/Database/MysqlTest.php b/tests/libraries/ilch/Database/MysqlTest.php
index e020fa60b..0b10e413f 100644
--- a/tests/libraries/ilch/Database/MysqlTest.php
+++ b/tests/libraries/ilch/Database/MysqlTest.php
@@ -1,12 +1,13 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
}
/**
@@ -39,7 +37,7 @@ public function testSelectCellNormalField()
->execute()
->fetchCell();
- $this->assertEquals('2', $result, 'Wrong cell value was returned.');
+ self::assertEquals('2', $result, 'Wrong cell value was returned.');
}
/**
@@ -53,7 +51,7 @@ public function testSelectCellWithCount()
->execute()
->fetchCell();
- $this->assertEquals('2', $result, 'Wrong cell value was returned.');
+ self::assertEquals('2', $result, 'Wrong cell value was returned.');
}
/**
@@ -72,7 +70,7 @@ public function testUpdateWithEmptyValue()
->execute()
->fetchCell();
- $this->assertEquals('', $result, 'The db entry has not being updated with an empty string.');
+ self::assertEquals('', $result, 'The db entry has not being updated with an empty string.');
}
/**
@@ -88,6 +86,6 @@ public function testInsertWithEmptyValue()
->execute()
->fetchCell();
- $this->assertEquals(1, $result, 'The db entry has not being inserted with an empty string.');
+ self::assertEquals(1, $result, 'The db entry has not being inserted with an empty string.');
}
}
diff --git a/tests/libraries/ilch/DateTest.php b/tests/libraries/ilch/DateTest.php
index 9b8e50228..ad8c5fa2e 100644
--- a/tests/libraries/ilch/DateTest.php
+++ b/tests/libraries/ilch/DateTest.php
@@ -1,6 +1,6 @@
assertEquals(
+ self::assertEquals(
'UTC',
$date->getTimeZone()->getName(),
'Timezone is not UTC as expected when creating Ilch_Date without a paramter.'
@@ -46,7 +46,7 @@ public function testExtendFromDateTime()
{
$ilchDate = new \Ilch\Date('2013-09-24 13:44:53');
- $this->assertInstanceOf('DateTime', $ilchDate, 'No DateTime object was created by the constructor.');
+ self::assertInstanceOf('DateTime', $ilchDate, 'No DateTime object was created by the constructor.');
}
/**
@@ -56,7 +56,7 @@ public function testToDb()
{
$ilchDate = new \Ilch\Date('2013-09-24 15:44:53');
- $this->assertEquals('2013-09-24 15:44:53', $ilchDate->toDb(), 'The date was not returned in UTC.');
+ self::assertEquals('2013-09-24 15:44:53', $ilchDate->toDb(), 'The date was not returned in UTC.');
}
/**
@@ -66,7 +66,7 @@ public function testToDbLocal()
{
$ilchDate = new \Ilch\Date('2013-09-24 15:44:53');
- $this->assertEquals(
+ self::assertEquals(
'2013-09-24 17:44:53',
$ilchDate->toDb(true),
'The date was not in the local timezone returned.'
@@ -81,7 +81,7 @@ public function testToDbCustomFormat()
$ilchDate = new \Ilch\Date('2013-09-24 15:44:53');
$ilchDate->setDbFormat('d.m.Y H:i:s');
- $this->assertEquals(
+ self::assertEquals(
'24.09.2013 15:44:53',
$ilchDate->toDb(),
'The date was not returned with the correct format.'
@@ -98,7 +98,7 @@ public function testGetDateTimeAfterToDb()
$ilchDate = new \Ilch\Date('2013-09-24 22:32:46');
$ilchDate->toDb();
- $this->assertEquals(
+ self::assertEquals(
'2013-09-24 22:32:46',
$ilchDate->format('Y-m-d H:i:s'),
'A time with the wrong timezone was returned.'
@@ -112,7 +112,7 @@ public function testTypeCast()
{
$ilchDate = new \Ilch\Date('2013-09-24 22:32:46');
- $this->assertEquals(
+ self::assertEquals(
'2013-09-24 22:32:46',
(string)$ilchDate,
'The object could not be typecasted correctly to string.'
@@ -127,7 +127,7 @@ public function testTypeCastCustomFormat()
$ilchDate = new \Ilch\Date('2013-09-24 22:32:46');
$ilchDate->setDefaultFormat('d.m.Y H:i:s');
- $this->assertEquals(
+ self::assertEquals(
'24.09.2013 22:32:46',
(string)$ilchDate,
'The object could not be typecasted correctly to string using a custom format.'
@@ -142,9 +142,9 @@ public function testTimestampDoesNotChange()
$date = new \Ilch\Date();
$date->setTimestamp(1379521501);
- $this->assertEquals(1379521501, $date->getTimestamp(), 'The timestamp was not returned in UTC.');
- $this->assertEquals(1379521501, $date->format('U', true), 'The timestamp was not returned in UTC.');
- $this->assertEquals(1379521501, $date->format('U', false), 'The timestamp was not returned in UTC.');
+ self::assertEquals(1379521501, $date->getTimestamp(), 'The timestamp was not returned in UTC.');
+ self::assertEquals(1379521501, $date->format('U', true), 'The timestamp was not returned in UTC.');
+ self::assertEquals(1379521501, $date->format('U'), 'The timestamp was not returned in UTC.');
}
/**
@@ -155,7 +155,7 @@ public function testFormatToLocal()
$date = new \Ilch\Date();
$date->setTimestamp(1379521501);
- $this->assertEquals(
+ self::assertEquals(
'2013-09-18 18:25:01',
$date->format('Y-m-d H:i:s', true),
'The time was not returned in local time.'
@@ -170,7 +170,7 @@ public function testFormatToUTC()
$date = new \Ilch\Date();
$date->setTimestamp(1379521501);
- $this->assertEquals('2013-09-18 16:25:01', $date->format('Y-m-d H:i:s'), 'The time was not returned in UTC.');
+ self::assertEquals('2013-09-18 16:25:01', $date->format('Y-m-d H:i:s'), 'The time was not returned in UTC.');
}
/**
@@ -180,7 +180,7 @@ public function testConstructLocalTime()
{
$date = new \Ilch\Date('2013-09-18 18:25:01', 'Europe/Berlin');
- $this->assertEquals(
+ self::assertEquals(
'2013-09-18 18:25:01',
$date->format('Y-m-d H:i:s', true),
'The time was not returned in local time.'
diff --git a/tests/libraries/ilch/Layout/Helper/GetMenuTest.php b/tests/libraries/ilch/Layout/Helper/GetMenuTest.php
index cb01343ce..646b3c81f 100644
--- a/tests/libraries/ilch/Layout/Helper/GetMenuTest.php
+++ b/tests/libraries/ilch/Layout/Helper/GetMenuTest.php
@@ -11,25 +11,25 @@
use Ilch\Router;
use Ilch\Translator;
use PHPUnit\Ilch\DatabaseTestCase;
+use PHPUnit\Ilch\PhpunitDataset;
class GetMenuTest extends DatabaseTestCase
{
static protected $fillDbOnSetUp = self::PROVISION_ON_SETUP_BEFORE_CLASS;
- protected static function getSchemaSQLQueries()
+ protected $phpunitDataset;
+
+ public function setUp()
{
- $adminConfig = new \Modules\Admin\Config\Config();
- return $adminConfig->getInstallSql();
+ parent::setUp();
+ $this->phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../../_files/mysql_menu.yml');
}
- /**
- * Returns the test dataset.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_IDataSet
- */
- protected function getDataSet()
+ protected static function getSchemaSQLQueries()
{
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../../_files/mysql_menu.yml');
+ $adminConfig = new \Modules\Admin\Config\Config();
+ return $adminConfig->getInstallSql();
}
/**
@@ -49,7 +49,7 @@ public function testGetMenu(array $options, $expected, $currentUrlModule = 'arti
$out = new GetMenu($layout);
- $this->assertSame($expected, $out->getMenu(1, '
%s
%c', $options));
+ self::assertSame($expected, $out->getMenu(1, '%s
%c', $options));
}
public function dpForTestGetMenu()
diff --git a/tests/libraries/ilch/RequestTest.php b/tests/libraries/ilch/RequestTest.php
index ab5488fe6..3b6c95e8e 100644
--- a/tests/libraries/ilch/RequestTest.php
+++ b/tests/libraries/ilch/RequestTest.php
@@ -46,7 +46,7 @@ public function testSetAndGetParams()
$this->request->setParams($params);
$actualParams = $this->request->getParams();
- $this->assertEquals($params, $actualParams, 'Param array got manipulated unexpectedly.');
+ self::assertEquals($params, $actualParams, 'Param array got manipulated unexpectedly.');
}
/**
@@ -61,7 +61,7 @@ public function testGetSingleParam()
];
$this->request->setParams($params);
- $this->assertEquals(123, $actualParam = $this->request->getParam('id'), 'Param got manipulated unexpectedly.');
+ self::assertEquals(123, $actualParam = $this->request->getParam('id'), 'Param got manipulated unexpectedly.');
}
/**
@@ -77,7 +77,7 @@ public function testGetSingleParamNull()
];
$this->request->setParams($params);
- $this->assertEquals(
+ self::assertEquals(
null,
$actualParam = $this->request->getParam('nullParam'),
'Param got manipulated unexpectedly.'
@@ -99,7 +99,7 @@ public function testSaveParamsWithNullValue()
$this->request->setParams($params);
$actualParams = $this->request->getParams();
- $this->assertArrayHasKey('nullParam', $actualParams, 'The param with value null got deleted.');
+ self::assertArrayHasKey('nullParam', $actualParams, 'The param with value null got deleted.');
}
/**
@@ -110,7 +110,7 @@ public function testSaveSingleParamWithNullValue()
$this->request->setParam('nullParam', null);
$actualParams = $this->request->getParams();
- $this->assertArrayHasKey('nullParam', $actualParams, 'The param with value null got deleted.');
+ self::assertArrayHasKey('nullParam', $actualParams, 'The param with value null got deleted.');
}
/**
@@ -121,7 +121,7 @@ public function testSaveSingleParam()
$this->request->setParam('username', 'testuser');
$actualParams = $this->request->getParams();
- $this->assertArrayHasKey('username', $actualParams, 'The saved param got deleted.');
+ self::assertArrayHasKey('username', $actualParams, 'The saved param got deleted.');
}
/**
@@ -140,7 +140,7 @@ public function testSetAndManipulateSourceParams()
$params['testvar'] = false;
$actualParams = $this->request->getParams();
- $this->assertEquals($expectedParams, $actualParams, 'Param array got manipulated unexpectedly.');
+ self::assertEquals($expectedParams, $actualParams, 'Param array got manipulated unexpectedly.');
}
/**
@@ -149,7 +149,7 @@ public function testSetAndManipulateSourceParams()
public function testGetModuleName()
{
$this->request->setModuleName('moduleNameTest');
- $this->assertEquals('moduleNameTest', $this->request->getModuleName(), 'Modulename changed.');
+ self::assertEquals('moduleNameTest', $this->request->getModuleName(), 'Modulename changed.');
}
/**
@@ -158,7 +158,7 @@ public function testGetModuleName()
public function testGetControllerName()
{
$this->request->setControllerName('controllerNameTest');
- $this->assertEquals('controllerNameTest', $this->request->getControllerName(), 'Controllername changed.');
+ self::assertEquals('controllerNameTest', $this->request->getControllerName(), 'Controllername changed.');
}
/**
@@ -167,7 +167,7 @@ public function testGetControllerName()
public function testGetActionName()
{
$this->request->setActionName('actionNameTest');
- $this->assertEquals('actionNameTest', $this->request->getActionName(), 'Actionname changed.');
+ self::assertEquals('actionNameTest', $this->request->getActionName(), 'Actionname changed.');
}
/**
@@ -183,7 +183,7 @@ public function testIsPost()
$_POST = $params;
$_REQUEST = $params;
- $this->assertTrue($this->request->isPost());
+ self::assertTrue($this->request->isPost());
}
/**
@@ -193,7 +193,7 @@ public function testGetQuery()
{
$_GET['username'] = 'testuser';
- $this->assertEquals(
+ self::assertEquals(
'testuser',
$this->request->getQuery('username'),
'The request object didnt returned the GET parameter.'
@@ -207,7 +207,7 @@ public function testGetPost()
{
$_POST['username'] = 'testuser';
- $this->assertEquals(
+ self::assertEquals(
'testuser',
$this->request->getPost('username'),
'The request object didnt returned the POST parameter.'
diff --git a/tests/libraries/ilch/RouterTest.php b/tests/libraries/ilch/RouterTest.php
index 1a0e09494..6e96076a8 100644
--- a/tests/libraries/ilch/RouterTest.php
+++ b/tests/libraries/ilch/RouterTest.php
@@ -37,15 +37,15 @@ public function testDefaultRegexpPattern()
$pattern = Router::DEFAULT_REGEX_PATTERN;
$pattern = '#^' . $pattern . '$#i';
- $this->assertRegExp($pattern, 'module/controller');
- $this->assertRegExp($pattern, 'module/controller/action');
- $this->assertRegExp($pattern, 'module/controller/action/param1/value1/param2/value2');
+ self::assertRegExp($pattern, 'module/controller');
+ self::assertRegExp($pattern, 'module/controller/action');
+ self::assertRegExp($pattern, 'module/controller/action/param1/value1/param2/value2');
}
public function testParamConvertingIntoArray()
{
$params = $this->router->convertParamStringIntoArray('param1/value1/param2/value2');
- $this->assertEquals($params, ['param1' => 'value1', 'param2' => 'value2']);
+ self::assertEquals(['param1' => 'value1', 'param2' => 'value2'], $params);
}
public function testMatchModuleController()
@@ -59,7 +59,7 @@ public function testMatchModuleController()
];
$match = $this->router->matchByRegexp($expectedResult[0]);
- $this->assertTrue(is_array($match), 'Expected match result need to be an array!');
+ self::assertTrue(\is_array($match), 'Expected match result need to be an array!');
}
public function testMatchModuleControllerAction()
@@ -76,7 +76,7 @@ public function testMatchModuleControllerAction()
];
$match = $this->router->matchByRegexp($expectedResult[0]);
- $this->assertTrue(is_array($match), 'Expected route does not match!');
+ self::assertTrue(\is_array($match), 'Expected route does not match!');
}
public function testMatchModuleControllerActionParams()
@@ -96,16 +96,16 @@ public function testMatchModuleControllerActionParams()
];
$match = $this->router->matchByRegexp($expectedResult[0]);
- $this->assertTrue(is_array($match), 'Expected route does not match!');
+ self::assertTrue(\is_array($match), 'Expected route does not match!');
$params = $this->router->convertParamStringIntoArray($match['params']);
- $this->assertEquals($params, ['param1' => 'value1', 'param2' => 'value2']);
+ self::assertEquals(['param1' => 'value1', 'param2' => 'value2'], $params);
}
public function testMatchByQuery()
{
$route = 'page/index/show/param1/value1/param2/value2';
$match = $this->router->matchByQuery($route);
- $this->assertTrue(is_array($match), 'Expected route does not match!');
+ self::assertTrue(\is_array($match), 'Expected route does not match!');
}
/**
@@ -129,11 +129,11 @@ public function testUpdateRequestByQuery(
$result = $this->router->matchByQuery($route);
$this->router->updateRequest($result);
- $this->assertSame($expectIsAdmin, $this->request->isAdmin());
- $this->assertSame($expectedModule, $this->request->getModuleName());
- $this->assertSame($expectedController, $this->request->getControllerName());
- $this->assertSame($expectedAction, $this->request->getActionName());
- $this->assertSame($expectedParams, $this->request->getParams());
+ self::assertSame($expectIsAdmin, $this->request->isAdmin());
+ self::assertSame($expectedModule, $this->request->getModuleName());
+ self::assertSame($expectedController, $this->request->getControllerName());
+ self::assertSame($expectedAction, $this->request->getActionName());
+ self::assertSame($expectedParams, $this->request->getParams());
}
/**
@@ -175,21 +175,21 @@ public function testUpdateRequestByRegexp()
$result = $this->router->matchByRegexp($route);
$this->router->updateRequest($result);
- $this->assertSame(false, $this->request->isAdmin());
- $this->assertSame('page', $this->request->getModuleName());
- $this->assertSame('index', $this->request->getControllerName());
- $this->assertSame('show', $this->request->getActionName());
- $this->assertSame(['param1' => 'value1', 'param2' => 'value2'], $this->request->getParams());
+ self::assertFalse($this->request->isAdmin());
+ self::assertSame('page', $this->request->getModuleName());
+ self::assertSame('index', $this->request->getControllerName());
+ self::assertSame('show', $this->request->getActionName());
+ self::assertSame(['param1' => 'value1', 'param2' => 'value2'], $this->request->getParams());
$route = 'admin/page/index/show/param1/value1/param2/value2';
$result = $this->router->matchByRegexp($route);
$this->router->updateRequest($result);
- $this->assertSame(true, $this->request->isAdmin());
- $this->assertSame('page', $this->request->getModuleName());
- $this->assertSame('index', $this->request->getControllerName());
- $this->assertSame('show', $this->request->getActionName());
- $this->assertSame(['param1' => 'value1', 'param2' => 'value2'], $this->request->getParams());
+ self::assertTrue($this->request->isAdmin());
+ self::assertSame('page', $this->request->getModuleName());
+ self::assertSame('index', $this->request->getControllerName());
+ self::assertSame('show', $this->request->getActionName());
+ self::assertSame(['param1' => 'value1', 'param2' => 'value2'], $this->request->getParams());
}
}
diff --git a/tests/libraries/ilch/TranslatorTest.php b/tests/libraries/ilch/TranslatorTest.php
index 956742e43..d3f5d2cfe 100644
--- a/tests/libraries/ilch/TranslatorTest.php
+++ b/tests/libraries/ilch/TranslatorTest.php
@@ -21,7 +21,7 @@ class TranslatorTest extends TestCase
public function testLoadTranslationsFile()
{
$translator = new Translator('de_DE');
- $this->assertTrue($translator->load(__DIR__ . '/_files'));
+ self::assertTrue($translator->load(__DIR__ . '/_files'));
}
/**
@@ -30,7 +30,7 @@ public function testLoadTranslationsFile()
public function testLoadTranslationFileNotExists()
{
$translator = new Translator('xx_xx');
- $this->assertFalse(
+ self::assertFalse(
$translator->load(__DIR__ . '/_files'),
'The translator didn\'t return false when the translation file doesn\'t exist.'
);
@@ -42,7 +42,7 @@ public function testLoadTranslationFileNotExists()
public function testLoadTranslationDirNotExists()
{
$translator = new Translator('de_DE');
- $this->assertFalse(
+ self::assertFalse(
$translator->load('someImaginaryFolder'),
'The translator didn\'t return false when the given translation directory doesn\'t exist.'
);
@@ -57,7 +57,7 @@ public function testTrans()
$translator = new Translator('en_EN');
$translator->load(__DIR__ . '/_files');
- $this->assertEquals(
+ self::assertEquals(
'The user gets what he wants!',
$translator->trans('userGetsWhatHeWants'),
'The text wasnt translated using the translation file.'
@@ -73,7 +73,7 @@ public function testTransNotTranslated()
$translator = new Translator('en_EN');
$translator->load(__DIR__ . '/_files');
- $this->assertEquals(
+ self::assertEquals(
'notTranslatedText',
$translator->trans('notTranslatedText'),
'The text wasnt simply returned.'
@@ -89,7 +89,7 @@ public function testTransPlaceholder()
$translator = new Translator('en_EN');
$translator->load(__DIR__ . '/_files');
- $this->assertEquals(
+ self::assertEquals(
'Welcome, Hans',
$translator->trans('welcomeUser', 'Hans'),
'The text wasnt returned with the placeholder.'
@@ -105,7 +105,7 @@ public function testTransMultiplePlaceholder()
$translator = new Translator('en_EN');
$translator->load(__DIR__ . '/_files');
- $this->assertEquals(
+ self::assertEquals(
'Welcome, Hans, ur last login was yesterday',
$translator->trans('welcomeUserExtended', 'Hans', 'yesterday'),
'The text wasnt returned with the placeholder.'
@@ -118,7 +118,7 @@ public function testTransMultiplePlaceholder()
public function testRequestLocaleDefinition()
{
$translator = new Translator('en_EN');
- $this->assertEquals('en_EN', $translator->getLocale());
+ self::assertEquals('en_EN', $translator->getLocale());
}
/**
@@ -128,7 +128,7 @@ public function testRequestLocaleDefinition()
public function testRequestLocaleDefinitionDefault()
{
$translator = new Translator();
- $this->assertEquals('de_DE', $translator->getLocale());
+ self::assertEquals('de_DE', $translator->getLocale());
}
/**
@@ -140,7 +140,7 @@ public function testGetTranslationsArray()
$translator->load(__DIR__ . '/_files');
$expectedTranslations = require __DIR__ . '/_files/en.php';
- $this->assertEquals(
+ self::assertEquals(
$expectedTranslations,
$translator->getTranslations(),
'The translations array was returned wrongly.'
@@ -153,6 +153,6 @@ public function testGetTranslationsArray()
public function testShortenLocale()
{
$translator = new Translator();
- $this->assertEquals('en', $translator->shortenLocale('en_EN'), 'The locale wasn\'t trimmed correctly.');
+ self::assertEquals('en', $translator->shortenLocale('en_EN'), 'The locale wasn\'t trimmed correctly.');
}
}
diff --git a/tests/libraries/ilch/Validation/Validators/DateTest.php b/tests/libraries/ilch/Validation/Validators/DateTest.php
index b268fdfd5..03a93adee 100644
--- a/tests/libraries/ilch/Validation/Validators/DateTest.php
+++ b/tests/libraries/ilch/Validation/Validators/DateTest.php
@@ -22,10 +22,10 @@ public function testValidator($data, $expectedIsValid, $expectedErrorKey = '', $
{
$validator = new Date($data);
$validator->run();
- $this->assertSame($expectedIsValid, $validator->isValid());
+ self::assertSame($expectedIsValid, $validator->isValid());
if (!empty($expectedErrorKey)) {
- $this->assertSame($expectedErrorKey, $validator->getErrorKey());
- $this->assertSame($expectedErrorParameters, $validator->getErrorParameters());
+ self::assertSame($expectedErrorKey, $validator->getErrorKey());
+ self::assertSame($expectedErrorParameters, $validator->getErrorParameters());
}
}
diff --git a/tests/libraries/ilch/Validation/Validators/MaxTest.php b/tests/libraries/ilch/Validation/Validators/MaxTest.php
index 30dabb38f..03aad620a 100644
--- a/tests/libraries/ilch/Validation/Validators/MaxTest.php
+++ b/tests/libraries/ilch/Validation/Validators/MaxTest.php
@@ -1,6 +1,6 @@
run();
- $this->assertSame($expectedIsValid, $validator->isValid());
+ self::assertSame($expectedIsValid, $validator->isValid());
if (!empty($expectedErrorKey)) {
- $this->assertSame($expectedErrorKey, $validator->getErrorKey());
- $this->assertSame($expectedErrorParameters, $validator->getErrorParameters());
+ self::assertSame($expectedErrorKey, $validator->getErrorKey());
+ self::assertSame($expectedErrorParameters, $validator->getErrorParameters());
}
}
diff --git a/tests/libraries/ilch/Validation/Validators/MinTest.php b/tests/libraries/ilch/Validation/Validators/MinTest.php
index 8dae57794..8e11ce0fb 100644
--- a/tests/libraries/ilch/Validation/Validators/MinTest.php
+++ b/tests/libraries/ilch/Validation/Validators/MinTest.php
@@ -1,6 +1,6 @@
run();
- $this->assertSame($expectedIsValid, $validator->isValid());
+ self::assertSame($expectedIsValid, $validator->isValid());
if (!empty($expectedErrorKey)) {
- $this->assertSame($expectedErrorKey, $validator->getErrorKey());
- $this->assertSame($expectedErrorParameters, $validator->getErrorParameters());
+ self::assertSame($expectedErrorKey, $validator->getErrorKey());
+ self::assertSame($expectedErrorParameters, $validator->getErrorParameters());
}
}
diff --git a/tests/libraries/ilch/ValidationTest.php b/tests/libraries/ilch/ValidationTest.php
index 94a870c18..d70ed367d 100644
--- a/tests/libraries/ilch/ValidationTest.php
+++ b/tests/libraries/ilch/ValidationTest.php
@@ -33,9 +33,9 @@ public function testValidationWithSingleValidator(array $params, $expected, $inv
{
$validation = Validation::create($params, ['testField' => ($inverted ? 'NOT' : '').'integer']);
- $this->assertSame($expected, $validation->isValid());
+ self::assertSame($expected, $validation->isValid());
if (!$expected) {
- $this->assertTrue($validation->getErrorBag()->hasError('testField'));
+ self::assertTrue($validation->getErrorBag()->hasError('testField'));
}
}
@@ -71,9 +71,9 @@ public function testValidationWithValidatorChainWithBreakingChain(
) {
$validation = Validation::create($params, ['testField' => $validatorRules]);
- $this->assertSame($expected, $validation->isValid());
+ self::assertSame($expected, $validation->isValid());
if (!$expected) {
- $this->assertSame($expectedErrors, $validation->getErrorBag()->getErrors());
+ self::assertSame($expectedErrors, $validation->getErrorBag()->getErrors());
}
}
@@ -135,9 +135,9 @@ function () {
$validation = Validation::create($params, ['testField' => $validatorRules]);
- $this->assertSame($expected, $validation->isValid());
+ self::assertSame($expected, $validation->isValid());
if (!$expected) {
- $this->assertSame($expectedErrors, $validation->getErrorBag()->getErrors());
+ self::assertSame($expectedErrors, $validation->getErrorBag()->getErrors());
}
}
@@ -198,6 +198,6 @@ function () {
$errorMessages = $validation->getErrorBag()->getErrorMessages();
- $this->assertSame(['Das Feld muss mindestens 3 betragen.'], $errorMessages);
+ self::assertSame(['Das Feld muss mindestens 3 betragen.'], $errorMessages);
}
}
diff --git a/tests/modules/admin/_files/mysql_database.yml b/tests/modules/admin/_files/mysql_database.yml
index 1195ce733..b9275764e 100644
--- a/tests/modules/admin/_files/mysql_database.yml
+++ b/tests/modules/admin/_files/mysql_database.yml
@@ -4,14 +4,14 @@ admin_notifications:
timestamp: "2014-01-01 12:12:12"
module: "article"
message: "Testmessage1"
- url: "http://www.google.de"
+ url: "https://www.google.de"
type: "articleNewArticle"
-
id: 2
timestamp: "2014-01-01 12:12:12"
module: "awards"
message: "Testmessage2"
- url: "http://www.ilch.de"
+ url: "https://www.ilch.de"
type: "awardsNewAward"
admin_notifications_permission:
diff --git a/tests/modules/admin/mappers/LayoutAdvSettingsTest.php b/tests/modules/admin/mappers/LayoutAdvSettingsTest.php
index 3cf4bae63..d8a318ad3 100644
--- a/tests/modules/admin/mappers/LayoutAdvSettingsTest.php
+++ b/tests/modules/admin/mappers/LayoutAdvSettingsTest.php
@@ -10,6 +10,7 @@
use Modules\Admin\Config\Config as ModuleConfig;
use Modules\Admin\Mappers\LayoutAdvSettings;
use Modules\Admin\Models\LayoutAdvSettings as LayoutAdvSettingsModel;
+use PHPUnit\Ilch\PhpunitDataset;
/**
* Tests the LayoutAdvSettings mapper class.
@@ -22,23 +23,16 @@ class LayoutAdvSettingsTest extends DatabaseTestCase
* @var LayoutAdvSettings
*/
protected $out;
+ protected $phpunitDataset;
public function setUp()
{
parent::setUp();
+ $this->phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
$this->out = new LayoutAdvSettings();
}
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
- }
-
/**
* Returns database schema sql statements to initialize database
*
@@ -57,10 +51,10 @@ public function testGetSetting()
{
$layoutSetting = $this->out->getSetting('testLayoutKey1', 'testKey1');
- $this->assertEquals($layoutSetting->getId(), 1);
- $this->assertSame($layoutSetting->getLayoutKey(), 'testLayoutKey1');
- $this->assertSame($layoutSetting->getKey(), 'testKey1');
- $this->assertSame($layoutSetting->getValue(), 'testValue1');
+ self::assertEquals(1, $layoutSetting->getId());
+ self::assertSame($layoutSetting->getLayoutKey(), 'testLayoutKey1');
+ self::assertSame($layoutSetting->getKey(), 'testKey1');
+ self::assertSame($layoutSetting->getValue(), 'testValue1');
}
/**
@@ -70,15 +64,15 @@ public function testGetSettings()
{
$layoutSetting = $this->out->getSettings('testLayoutKey1');
- $this->assertEquals($layoutSetting['testKey1']->getId(), 1);
- $this->assertSame($layoutSetting['testKey1']->getLayoutKey(), 'testLayoutKey1');
- $this->assertSame($layoutSetting['testKey1']->getKey(), 'testKey1');
- $this->assertSame($layoutSetting['testKey1']->getValue(), 'testValue1');
+ self::assertEquals(1, $layoutSetting['testKey1']->getId());
+ self::assertSame($layoutSetting['testKey1']->getLayoutKey(), 'testLayoutKey1');
+ self::assertSame($layoutSetting['testKey1']->getKey(), 'testKey1');
+ self::assertSame($layoutSetting['testKey1']->getValue(), 'testValue1');
- $this->assertEquals($layoutSetting['testKey2']->getId(), 2);
- $this->assertSame($layoutSetting['testKey2']->getLayoutKey(), 'testLayoutKey1');
- $this->assertSame($layoutSetting['testKey2']->getKey(), 'testKey2');
- $this->assertSame($layoutSetting['testKey2']->getValue(), 'testValue2');
+ self::assertEquals(2, $layoutSetting['testKey2']->getId());
+ self::assertSame($layoutSetting['testKey2']->getLayoutKey(), 'testLayoutKey1');
+ self::assertSame($layoutSetting['testKey2']->getKey(), 'testKey2');
+ self::assertSame($layoutSetting['testKey2']->getValue(), 'testValue2');
}
/**
@@ -88,9 +82,9 @@ public function testGetListOfLayoutKeys()
{
$layoutKeyList = $this->out->getListOfLayoutKeys();
- $this->assertCount(2, $layoutKeyList);
- $this->assertSame($layoutKeyList[0], 'testLayoutKey1');
- $this->assertSame($layoutKeyList[1], 'testLayoutKey2');
+ self::assertCount(2, $layoutKeyList);
+ self::assertSame($layoutKeyList[0], 'testLayoutKey1');
+ self::assertSame($layoutKeyList[1], 'testLayoutKey2');
}
/**
@@ -98,7 +92,7 @@ public function testGetListOfLayoutKeys()
*/
public function testHasSettings()
{
- $this->assertTrue($this->out->hasSettings('testLayoutKey1'));
+ self::assertTrue($this->out->hasSettings('testLayoutKey1'));
}
/**
@@ -106,7 +100,7 @@ public function testHasSettings()
*/
public function testHasSettingsNotExisting()
{
- $this->assertFalse($this->out->hasSettings('notExistingLayoutKey'));
+ self::assertFalse($this->out->hasSettings('notExistingLayoutKey'));
}
/**
@@ -122,10 +116,10 @@ public function testSaveSingleOne()
$this->out->save($layoutSettingsArray);
$layoutSetting = $this->out->getSetting('testLayoutKey3','testKey5');
- $this->assertEquals($layoutSetting->getId(), 5);
- $this->assertSame($layoutSetting->getLayoutKey(), 'testLayoutKey3');
- $this->assertSame($layoutSetting->getKey(), 'testKey5');
- $this->assertSame($layoutSetting->getValue(), 'testValue5');
+ self::assertEquals(5, $layoutSetting->getId());
+ self::assertSame($layoutSetting->getLayoutKey(), 'testLayoutKey3');
+ self::assertSame($layoutSetting->getKey(), 'testKey5');
+ self::assertSame($layoutSetting->getValue(), 'testValue5');
}
/**
@@ -148,15 +142,15 @@ public function testSaveMultiple()
$this->out->save($layoutSettingsArray);
$layoutSetting = $this->out->getSettings('testLayoutKey3');
- $this->assertEquals($layoutSetting['testKey5']->getId(), 5);
- $this->assertSame($layoutSetting['testKey5']->getLayoutKey(), 'testLayoutKey3');
- $this->assertSame($layoutSetting['testKey5']->getKey(), 'testKey5');
- $this->assertSame($layoutSetting['testKey5']->getValue(), 'testValue5');
-
- $this->assertEquals($layoutSetting['testKey6']->getId(), 6);
- $this->assertSame($layoutSetting['testKey6']->getLayoutKey(), 'testLayoutKey3');
- $this->assertSame($layoutSetting['testKey6']->getKey(), 'testKey6');
- $this->assertSame($layoutSetting['testKey6']->getValue(), 'testValue6');
+ self::assertEquals(5, $layoutSetting['testKey5']->getId());
+ self::assertSame($layoutSetting['testKey5']->getLayoutKey(), 'testLayoutKey3');
+ self::assertSame($layoutSetting['testKey5']->getKey(), 'testKey5');
+ self::assertSame($layoutSetting['testKey5']->getValue(), 'testValue5');
+
+ self::assertEquals(6, $layoutSetting['testKey6']->getId());
+ self::assertSame($layoutSetting['testKey6']->getLayoutKey(), 'testLayoutKey3');
+ self::assertSame($layoutSetting['testKey6']->getKey(), 'testKey6');
+ self::assertSame($layoutSetting['testKey6']->getValue(), 'testValue6');
}
/**
@@ -165,7 +159,7 @@ public function testSaveMultiple()
public function testDeleteSetting()
{
$this->out->deleteSetting('testLayoutKey1','testKey1');
- $this->assertEmpty($this->out->getSetting('testLayoutKey1','testKey1'));
+ self::assertEmpty($this->out->getSetting('testLayoutKey1','testKey1'));
}
/**
@@ -174,7 +168,7 @@ public function testDeleteSetting()
public function testDeleteSettingById()
{
$this->out->deleteSettingById(2);
- $this->assertEmpty($this->out->getSetting('testLayoutKey1','testKey2'));
+ self::assertEmpty($this->out->getSetting('testLayoutKey1','testKey2'));
}
/**
@@ -183,6 +177,6 @@ public function testDeleteSettingById()
public function testDeleteSettings()
{
$this->out->deleteSettings('testLayoutKey2');
- $this->assertEmpty($this->out->getSettings('testLayoutKey2'));
+ self::assertEmpty($this->out->getSettings('testLayoutKey2'));
}
}
diff --git a/tests/modules/admin/mappers/NotificationPermissionTest.php b/tests/modules/admin/mappers/NotificationPermissionTest.php
index 01ae9907e..a4632af09 100644
--- a/tests/modules/admin/mappers/NotificationPermissionTest.php
+++ b/tests/modules/admin/mappers/NotificationPermissionTest.php
@@ -10,6 +10,7 @@
use Modules\Admin\Config\Config as ModuleConfig;
use Modules\Admin\Mappers\NotificationPermission as NotificationPermissionMapper;
use Modules\Admin\Models\NotificationPermission as NotificationPermissionModel;
+use PHPUnit\Ilch\PhpunitDataset;
/**
* Tests the NotificationPermission mapper class.
@@ -22,10 +23,13 @@ class NotificationPermissionTest extends DatabaseTestCase
* @var UserMapper
*/
protected $out;
+ protected $phpunitDataset;
public function setUp()
{
parent::setUp();
+ $this->phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
$this->out = new NotificationPermissionMapper();
}
@@ -35,7 +39,7 @@ public function setUp()
*/
public function testGetPermissions()
{
- $this->assertTrue(count($this->out->getPermissions()) == 2);
+ self::assertCount(2, $this->out->getPermissions());
}
/**
@@ -44,7 +48,7 @@ public function testGetPermissions()
*/
public function testGetPermissionOfModuleNotExisting()
{
- $this->assertNull($this->out->getPermissionOfModule('xyzmodul'));
+ self::assertNull($this->out->getPermissionOfModule('xyzmodul'));
}
/**
@@ -59,7 +63,7 @@ public function testUpdatePermissionOfModule()
$notificationPermissionModel->setLimit(3);
$this->out->updatePermissionOfModule($notificationPermissionModel);
- $this->assertEquals($notificationPermissionModel, $this->out->getPermissionOfModule('article'));
+ self::assertEquals($notificationPermissionModel, $this->out->getPermissionOfModule('article'));
}
/**
@@ -70,7 +74,7 @@ public function testUpdatePermissionGrantedOfModule()
{
$this->out->updatePermissionGrantedOfModule('article', false);
$notificationPermissionModel = $this->out->getPermissionOfModule('article');
- $this->assertTrue($notificationPermissionModel->getGranted() == 0);
+ self::assertEquals(0, $notificationPermissionModel->getGranted());
}
/**
@@ -81,7 +85,7 @@ public function testUpdateLimitOfModule()
{
$this->out->updateLimitOfModule('article', 3);
$notificationPermissionModel = $this->out->getPermissionOfModule('article');
- $this->assertTrue($notificationPermissionModel->getLimit() == 3);
+ self::assertEquals(3, $notificationPermissionModel->getLimit());
}
/**
@@ -94,7 +98,7 @@ public function testUpdateLimitOfModuleInvalidLimit()
$this->out->updateLimitOfModule('article', 300);
$notificationPermissionModel = $this->out->getPermissionOfModule('article');
// If the limit is bigger than 255 (UNSIGNED TINYINT) then it gets set to the maximum of 255.
- $this->assertTrue($notificationPermissionModel->getLimit() == 255);
+ self::assertEquals(255, $notificationPermissionModel->getLimit());
}
/**
@@ -107,7 +111,7 @@ public function testUpdateLimitOfModuleInvalidLimitNegative()
$this->out->updateLimitOfModule('article', -1);
$notificationPermissionModel = $this->out->getPermissionOfModule('article');
// If the limit is negative (UNSIGNED) then it gets set to 0.
- $this->assertTrue($notificationPermissionModel->getLimit() == 0);
+ self::assertEquals(0, $notificationPermissionModel->getLimit());
}
/**
@@ -122,7 +126,7 @@ public function testAddPermissionForModule()
$notificationPermissionModel->setLimit(5);
$this->out->addPermissionForModule($notificationPermissionModel);
- $this->assertEquals($notificationPermissionModel, $this->out->getPermissionOfModule('away'));
+ self::assertEquals($notificationPermissionModel, $this->out->getPermissionOfModule('away'));
}
/**
@@ -132,17 +136,7 @@ public function testAddPermissionForModule()
public function testDeletePermissionOfModule()
{
$this->out->deletePermissionOfModule('article');
- $this->assertNull($this->out->getPermissionOfModule('article'));
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertNull($this->out->getPermissionOfModule('article'));
}
/**
diff --git a/tests/modules/admin/mappers/NotificationsTest.php b/tests/modules/admin/mappers/NotificationsTest.php
index 202dec77f..0ea0e1f36 100644
--- a/tests/modules/admin/mappers/NotificationsTest.php
+++ b/tests/modules/admin/mappers/NotificationsTest.php
@@ -1,6 +1,6 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
$this->out = new NotificationsMapper();
}
@@ -41,17 +46,17 @@ public function testGetNotificationById()
$notificationModel->setTimestamp('2014-01-01 12:12:12');
$notificationModel->setModule('article');
$notificationModel->setMessage('Testmessage1');
- $notificationModel->setURL('http://www.google.de');
+ $notificationModel->setURL('https://www.google.de');
$notificationModel->setType('articleNewArticle');
$notification = $this->out->getNotificationById(1);
- $this->assertTrue($notification->getId() == 1);
+ self::assertEquals(1, $notification->getId());
// The timestamp can vary by one hour. Therefore for example comparing
// the notificationModel with the one from the database assertEquals() would not work always.
- $this->assertTrue($notification->getModule() == 'article');
- $this->assertTrue($notification->getMessage() == 'Testmessage1');
- $this->assertTrue($notification->getURL() == 'http://www.google.de');
- $this->assertTrue($notification->getType() == 'articleNewArticle');
+ self::assertSame($notification->getModule(), 'article');
+ self::assertSame($notification->getMessage(), 'Testmessage1');
+ self::assertSame($notification->getURL(), 'https://www.google.de');
+ self::assertSame($notification->getType(), 'articleNewArticle');
}
/**
@@ -61,7 +66,7 @@ public function testGetNotificationById()
*/
public function testGetNotificationByIdNotExisting()
{
- $this->assertNull($this->out->getNotificationById(99));
+ self::assertNull($this->out->getNotificationById(99));
}
/**
@@ -70,7 +75,7 @@ public function testGetNotificationByIdNotExisting()
*/
public function testGetNotifications()
{
- $this->assertTrue(count($this->out->getNotifications()) == 2);
+ self::assertCount(2, $this->out->getNotifications());
}
/**
@@ -79,7 +84,7 @@ public function testGetNotifications()
*/
public function testGetNotificationsByModule()
{
- $this->assertTrue(count($this->out->getNotificationsByModule('article')) == 1);
+ self::assertCount(1, $this->out->getNotificationsByModule('article'));
}
/**
@@ -88,7 +93,7 @@ public function testGetNotificationsByModule()
*/
public function testGetNotificationsByModuleNotExisting()
{
- $this->assertEmpty($this->out->getNotificationsByModule('xyzmodule'));
+ self::assertEmpty($this->out->getNotificationsByModule('xyzmodule'));
}
/**
@@ -97,7 +102,7 @@ public function testGetNotificationsByModuleNotExisting()
*/
public function testGetNotificationsByType()
{
- $this->assertTrue(count($this->out->getNotificationsByType('articleNewArticle')) == 1);
+ self::assertCount(1, $this->out->getNotificationsByType('articleNewArticle'));
}
/**
@@ -106,7 +111,7 @@ public function testGetNotificationsByType()
*/
public function testGetNotificationsByTypeNotExisting()
{
- $this->assertEmpty($this->out->getNotificationsByType('xyzmodule'));
+ self::assertEmpty($this->out->getNotificationsByType('xyzmodule'));
}
/**
@@ -120,10 +125,10 @@ public function testIsValidNotification()
$notificationModel->setTimestamp('2014-01-01 12:12:12');
$notificationModel->setModule('article');
$notificationModel->setMessage('Testmessage1');
- $notificationModel->setURL('http://www.google.de');
+ $notificationModel->setURL('https://www.google.de');
$_SERVER['HTTP_HOST'] = '127.0.0.1';
- $this->assertTrue($this->out->isValidNotification($notificationModel));
+ self::assertTrue($this->out->isValidNotification($notificationModel));
}
/**
@@ -136,16 +141,16 @@ public function testAddNotification()
$notificationModel = new NotificationModel();
$notificationModel->setModule('awards');
$notificationModel->setMessage('Testmessage3');
- $notificationModel->setURL('http://www.google.de');
+ $notificationModel->setURL('https://www.google.de');
$notificationModel->setType('awardsNewAward');
$_SERVER['HTTP_HOST'] = '127.0.0.1';
- $this->assertTrue($this->out->addNotification($notificationModel) == 3);
+ self::assertEquals(3, $this->out->addNotification($notificationModel));
$notification = $this->out->getNotificationById(3);
- $this->assertTrue($notification->getModule() == 'awards');
- $this->assertTrue($notification->getMessage() == 'Testmessage3');
- $this->assertTrue($notification->getURL() == 'http://www.google.de');
- $this->assertTrue($notification->getType() == 'awardsNewAward');
+ self::assertSame($notification->getModule(), 'awards');
+ self::assertSame($notification->getMessage(), 'Testmessage3');
+ self::assertSame($notification->getURL(), 'https://www.google.de');
+ self::assertSame($notification->getType(), 'awardsNewAward');
}
/**
@@ -159,16 +164,16 @@ public function testUpdateNotificationById()
$notificationModel->setId(2);
$notificationModel->setModule('awards');
$notificationModel->setMessage('Testmessage3');
- $notificationModel->setURL('http://www.google.de');
+ $notificationModel->setURL('https://www.google.de');
$notificationModel->setType('awardsNewAward2');
$_SERVER['HTTP_HOST'] = '127.0.0.1';
$this->out->updateNotificationById($notificationModel);
$notification = $this->out->getNotificationById(2);
- $this->assertTrue($notification->getModule() == 'awards');
- $this->assertTrue($notification->getMessage() == 'Testmessage3');
- $this->assertTrue($notification->getURL() == 'http://www.google.de');
- $this->assertTrue($notification->getType() == 'awardsNewAward2');
+ self::assertSame($notification->getModule(), 'awards');
+ self::assertSame($notification->getMessage(), 'Testmessage3');
+ self::assertSame($notification->getURL(), 'https://www.google.de');
+ self::assertSame($notification->getType(), 'awardsNewAward2');
}
/**
@@ -178,7 +183,7 @@ public function testUpdateNotificationById()
public function testDeleteNotificationById()
{
$this->out->deleteNotificationById(1);
- $this->assertNull($this->out->getNotificationById(1));
+ self::assertNull($this->out->getNotificationById(1));
}
/**
@@ -188,7 +193,7 @@ public function testDeleteNotificationById()
public function testDeleteNotificationByIdNotExisting()
{
$this->out->deleteNotificationById(99);
- $this->assertTrue(count($this->out->getNotifications()) == 2);
+ self::assertCount(2, $this->out->getNotifications());
}
/**
@@ -198,7 +203,7 @@ public function testDeleteNotificationByIdNotExisting()
public function testDeleteNotificationsByModule()
{
$this->out->deleteNotificationsByModule('article');
- $this->assertTrue(count($this->out->getNotificationsByModule('article')) == 0);
+ self::assertCount(0, $this->out->getNotificationsByModule('article'));
}
/**
@@ -208,7 +213,7 @@ public function testDeleteNotificationsByModule()
public function testDeleteNotificationsByModuleNotExisting()
{
$this->out->deleteNotificationsByModule('xyzmodule');
- $this->assertTrue(count($this->out->getNotifications()) == 2);
+ self::assertCount(2, $this->out->getNotifications());
}
/**
@@ -218,7 +223,7 @@ public function testDeleteNotificationsByModuleNotExisting()
public function testDeleteNotificationsByType()
{
$this->out->deleteNotificationsByType('awardsNewAward');
- $this->assertTrue(count($this->out->getNotificationsByType('awardsNewAward')) == 0);
+ self::assertCount(0, $this->out->getNotificationsByType('awardsNewAward'));
}
/**
@@ -228,7 +233,7 @@ public function testDeleteNotificationsByType()
public function testDeleteNotificationsByTypeNotExisting()
{
$this->out->deleteNotificationsByType('xyzmodule');
- $this->assertTrue(count($this->out->getNotifications()) == 2);
+ self::assertCount(2, $this->out->getNotifications());
}
/**
@@ -237,17 +242,7 @@ public function testDeleteNotificationsByTypeNotExisting()
*/
public function testDeleteAllNotifications() {
$this->out->deleteAllNotifications();
- $this->assertTrue(count($this->out->getNotifications()) == 0);
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertCount(0, $this->out->getNotifications());
}
/**
diff --git a/tests/modules/forum/mappers/RankTest.php b/tests/modules/forum/mappers/RankTest.php
index a8a40e33b..230ec6239 100644
--- a/tests/modules/forum/mappers/RankTest.php
+++ b/tests/modules/forum/mappers/RankTest.php
@@ -1,15 +1,16 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
}
/**
@@ -31,7 +36,7 @@ public function testGetRanks()
$mapper = new RankMapper();
$ranks = $mapper->getRanks();
- $this->assertTrue(count($ranks) == 3);
+ self::assertCount(3, $ranks);
}
/**
@@ -42,9 +47,9 @@ public function testGetRankById()
$mapper = new RankMapper();
$rank = $mapper->getRankById(1);
- $this->assertTrue($rank->getId() == 1);
- $this->assertTrue($rank->getTitle() == 'Gruenschnabel');
- $this->assertTrue($rank->getPosts() == 0);
+ self::assertEquals(1, $rank->getId());
+ self::assertSame($rank->getTitle(), 'Gruenschnabel');
+ self::assertEquals(0, $rank->getPosts());
}
/**
@@ -55,9 +60,9 @@ public function testGetRankByPosts()
$mapper = new RankMapper();
$rank = $mapper->getRankByPosts(1);
- $this->assertTrue($rank->getId() == 1);
- $this->assertTrue($rank->getTitle() == 'Gruenschnabel');
- $this->assertTrue($rank->getPosts() == 0);
+ self::assertEquals(1, $rank->getId());
+ self::assertSame($rank->getTitle(), 'Gruenschnabel');
+ self::assertEquals(0, $rank->getPosts());
}
/**
@@ -68,9 +73,9 @@ public function testGetRankByPostsExact()
$mapper = new RankMapper();
$rank = $mapper->getRankByPosts(25);
- $this->assertTrue($rank->getId() == 2);
- $this->assertTrue($rank->getTitle() == 'Jungspund');
- $this->assertTrue($rank->getPosts() == 25);
+ self::assertEquals(2, $rank->getId());
+ self::assertSame($rank->getTitle(), 'Jungspund');
+ self::assertEquals(25, $rank->getPosts());
}
/**
@@ -82,9 +87,9 @@ public function testGetRankByPostsAbove()
$mapper = new RankMapper();
$rank = $mapper->getRankByPosts(30);
- $this->assertTrue($rank->getId() == 2);
- $this->assertTrue($rank->getTitle() == 'Jungspund');
- $this->assertTrue($rank->getPosts() == 25);
+ self::assertEquals(2, $rank->getId());
+ self::assertSame($rank->getTitle(), 'Jungspund');
+ self::assertEquals(25, $rank->getPosts());
}
/**
@@ -95,9 +100,9 @@ public function testGetRankByPostsHigh()
$mapper = new RankMapper();
$rank = $mapper->getRankByPosts(50);
- $this->assertTrue($rank->getId() == 3);
- $this->assertTrue($rank->getTitle() == 'Mitglied');
- $this->assertTrue($rank->getPosts() == 50);
+ self::assertEquals(3, $rank->getId());
+ self::assertSame($rank->getTitle(), 'Mitglied');
+ self::assertEquals(50, $rank->getPosts());
}
/**
@@ -115,9 +120,9 @@ public function testSaveAdd()
$rank = $mapper->getRankById(4);
- $this->assertTrue($rank->getId() == 4);
- $this->assertTrue($rank->getTitle() == 'TestTitle');
- $this->assertTrue($rank->getPosts() == 100);
+ self::assertEquals(4, $rank->getId());
+ self::assertSame($rank->getTitle(), 'TestTitle');
+ self::assertEquals(100, $rank->getPosts());
}
/**
@@ -136,9 +141,9 @@ public function testSaveEdit()
$rank = $mapper->getRankById(3);
- $this->assertTrue($rank->getId() == 3);
- $this->assertTrue($rank->getTitle() == 'TestTitle');
- $this->assertTrue($rank->getPosts() == 100);
+ self::assertEquals(3, $rank->getId());
+ self::assertSame($rank->getTitle(), 'TestTitle');
+ self::assertEquals(100, $rank->getPosts());
}
/**
@@ -151,17 +156,7 @@ public function testDelete()
$mapper->delete(3);
$ranks = $mapper->getRanks();
- $this->assertTrue(count($ranks) == 2);
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertCount(2, $ranks);
}
/**
diff --git a/tests/modules/forum/models/RankTest.php b/tests/modules/forum/models/RankTest.php
index b91f2b2a5..df6c8f023 100644
--- a/tests/modules/forum/models/RankTest.php
+++ b/tests/modules/forum/models/RankTest.php
@@ -1,6 +1,6 @@
setId(1);
- $this->assertEquals(1, $model->getId(), 'The rank id was not saved correctly.');
+ self::assertEquals(1, $model->getId(), 'The rank id was not saved correctly.');
}
/**
@@ -35,7 +35,7 @@ public function testTitle()
$model = new RankModel();
$model->setTitle('TestTitle');
- $this->assertEquals('TestTitle', $model->getTitle(), 'The rank title was not saved correctly.');
+ self::assertEquals('TestTitle', $model->getTitle(), 'The rank title was not saved correctly.');
}
/**
@@ -46,6 +46,6 @@ public function testPosts()
$model = new RankModel();
$model->setPosts(100);
- $this->assertEquals(100, $model->getPosts(), 'The rank posts was not saved correctly.');
+ self::assertEquals(100, $model->getPosts(), 'The rank posts was not saved correctly.');
}
}
diff --git a/tests/modules/user/mappers/AuthTokenTest.php b/tests/modules/user/mappers/AuthTokenTest.php
index 7868e2412..aa645b54d 100644
--- a/tests/modules/user/mappers/AuthTokenTest.php
+++ b/tests/modules/user/mappers/AuthTokenTest.php
@@ -1,6 +1,6 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
+ }
+
/**
* Tests if an auth token model is returned with that selector and the expected content.
*/
@@ -27,10 +37,10 @@ public function testGetAuthToken()
$mapper = new AuthTokenMapper();
$authToken = $mapper->getAuthToken('selector');
- $this->assertInstanceOf(AuthTokenModel::class, $authToken);
- $this->assertEquals('token', $authToken->getToken());
- $this->assertEquals(1, $authToken->getUserid());
- $this->assertEquals('2014-01-01 12:12:12', $authToken->getExpires());
+ self::assertInstanceOf(AuthTokenModel::class, $authToken);
+ self::assertEquals('token', $authToken->getToken());
+ self::assertEquals(1, $authToken->getUserid());
+ self::assertEquals('2014-01-01 12:12:12', $authToken->getExpires());
}
/**
@@ -41,7 +51,7 @@ public function testGetAuthTokenNotExisting()
$mapper = new AuthTokenMapper();
$authToken = $mapper->getAuthToken('invalid');
- $this->assertNull($authToken);
+ self::assertNull($authToken);
}
/**
@@ -57,12 +67,12 @@ public function testAddAuthToken()
$model->setUserid(3);
$model->setExpires('2014-01-02 10:10:10');
- $this->assertEquals(3, $mapper->AddAuthToken($model));
+ self::assertEquals(3, $mapper->AddAuthToken($model));
$authToken = $mapper->getAuthToken('selector3');
- $this->assertInstanceOf(AuthTokenModel::class, $authToken);
- $this->assertEquals('token3', $authToken->getToken());
- $this->assertEquals(3, $authToken->getUserid());
- $this->assertEquals('2014-01-02 10:10:10', $authToken->getExpires());
+ self::assertInstanceOf(AuthTokenModel::class, $authToken);
+ self::assertEquals('token3', $authToken->getToken());
+ self::assertEquals(3, $authToken->getUserid());
+ self::assertEquals('2014-01-02 10:10:10', $authToken->getExpires());
}
/**
@@ -78,12 +88,12 @@ public function testUpdateAuthToken()
$model->setUserid(4);
$model->setExpires('2014-01-02 10:10:10');
- $this->assertEquals(1, $mapper->updateAuthToken($model));
+ self::assertEquals(1, $mapper->updateAuthToken($model));
$authToken = $mapper->getAuthToken('selector2');
- $this->assertInstanceOf(AuthTokenModel::class, $authToken);
- $this->assertEquals('token2', $authToken->getToken());
- $this->assertEquals(4, $authToken->getUserid());
- $this->assertEquals('2014-01-02 10:10:10', $authToken->getExpires());
+ self::assertInstanceOf(AuthTokenModel::class, $authToken);
+ self::assertEquals('token2', $authToken->getToken());
+ self::assertEquals(4, $authToken->getUserid());
+ self::assertEquals('2014-01-02 10:10:10', $authToken->getExpires());
}
/**
@@ -99,7 +109,7 @@ public function testUpdateAuthTokenNotExisting()
$model->setUserid(4);
$model->setExpires('2014-01-02 10:10:10');
- $this->assertEquals(0, $mapper->updateAuthToken($model));
+ self::assertEquals(0, $mapper->updateAuthToken($model));
}
/**
@@ -109,7 +119,7 @@ public function testDeleteAuthToken()
{
$mapper = new AuthTokenMapper();
- $this->assertEquals(1, $mapper->deleteAuthToken('selector2'));
+ self::assertEquals(1, $mapper->deleteAuthToken('selector2'));
}
/**
@@ -119,7 +129,7 @@ public function testDeleteAuthTokenNotExisting()
{
$mapper = new AuthTokenMapper();
- $this->assertEquals(0, $mapper->deleteAuthToken('invalid'));
+ self::assertEquals(0, $mapper->deleteAuthToken('invalid'));
}
/**
@@ -129,7 +139,7 @@ public function testDeleteAllAuthTokenOfUser()
{
$mapper = new AuthTokenMapper();
- $this->assertEquals(1, $mapper->deleteAllAuthTokenOfUser(1));
+ self::assertEquals(1, $mapper->deleteAllAuthTokenOfUser(1));
}
/**
@@ -139,7 +149,7 @@ public function testDeleteAllAuthTokenOfUserNonExisting()
{
$mapper = new AuthTokenMapper();
- $this->assertEquals(0, $mapper->deleteAllAuthTokenOfUser(-1));
+ self::assertEquals(0, $mapper->deleteAllAuthTokenOfUser(-1));
}
/**
@@ -149,17 +159,7 @@ public function testDeleteExpiredAuthTokens()
{
$mapper = new AuthTokenMapper();
- $this->assertEquals(2, $mapper->deleteExpiredAuthTokens());
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertEquals(2, $mapper->deleteExpiredAuthTokens());
}
/**
diff --git a/tests/modules/user/mappers/CookieStolenTest.php b/tests/modules/user/mappers/CookieStolenTest.php
index 08fba70dd..0aff29da9 100644
--- a/tests/modules/user/mappers/CookieStolenTest.php
+++ b/tests/modules/user/mappers/CookieStolenTest.php
@@ -1,15 +1,16 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
+ }
+
/**
* Tests containsCookieStolen(). Should return 1.
*/
@@ -25,7 +35,7 @@ public function testContainsCookieStolen()
{
$mapper = new CookieStolenMapper();
- $this->assertEquals(1, $mapper->containsCookieStolen(1));
+ self::assertEquals(1, $mapper->containsCookieStolen(1));
}
/**
@@ -35,7 +45,7 @@ public function testContainsCookieStolenNotExisting()
{
$mapper = new CookieStolenMapper();
- $this->assertEquals(0, $mapper->containsCookieStolen(0));
+ self::assertEquals(0, $mapper->containsCookieStolen(0));
}
/**
@@ -46,7 +56,7 @@ public function testAddCookieStolen()
$mapper = new CookieStolenMapper();
$mapper->addCookieStolen(2);
- $this->assertEquals(1, $mapper->containsCookieStolen(2));
+ self::assertEquals(1, $mapper->containsCookieStolen(2));
}
/**
@@ -56,7 +66,7 @@ public function testDeleteCookieStolen()
{
$mapper = new CookieStolenMapper();
- $this->assertEquals(1, $mapper->deleteCookieStolen(1));
+ self::assertEquals(1, $mapper->deleteCookieStolen(1));
}
/**
@@ -66,17 +76,7 @@ public function testDeleteCookieStolenNotExisting()
{
$mapper = new CookieStolenMapper();
- $this->assertEquals(0, $mapper->deleteCookieStolen(0));
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertEquals(0, $mapper->deleteCookieStolen(0));
}
/**
diff --git a/tests/modules/user/mappers/GroupTest.php b/tests/modules/user/mappers/GroupTest.php
index 738ca67bb..b1a02d22f 100644
--- a/tests/modules/user/mappers/GroupTest.php
+++ b/tests/modules/user/mappers/GroupTest.php
@@ -1,13 +1,13 @@
loadFromArray($groupRow);
- $this->assertTrue($group !== false);
- $this->assertEquals(1, $group->getId());
- $this->assertEquals('Administrator', $group->getName());
+ self::assertNotFalse($group);
+ self::assertEquals(1, $group->getId());
+ self::assertEquals('Administrator', $group->getName());
}
}
diff --git a/tests/modules/user/mappers/UserTest.php b/tests/modules/user/mappers/UserTest.php
index 12dfcc940..0766ebfd9 100644
--- a/tests/modules/user/mappers/UserTest.php
+++ b/tests/modules/user/mappers/UserTest.php
@@ -1,6 +1,6 @@
phpunitDataset = new PhpunitDataset($this->db);
+ $this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');
$this->out = new UserMapper();
}
-
public function testGetAdministratorCount()
{
- $this->assertEquals(1, $this->out->getAdministratorCount());
- }
-
- /**
- * Creates and returns a dataset object.
- *
- * @return \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
- */
- protected function getDataSet()
- {
- return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__ . '/../_files/mysql_database.yml');
+ self::assertEquals(1, $this->out->getAdministratorCount());
}
/**
diff --git a/tests/modules/user/models/GroupTest.php b/tests/modules/user/models/GroupTest.php
index dc2baa672..115fcd089 100644
--- a/tests/modules/user/models/GroupTest.php
+++ b/tests/modules/user/models/GroupTest.php
@@ -1,6 +1,6 @@
setName('newGroup');
- $this->assertEquals('newGroup', $group->getName(), 'The group name did not save correctly.');
+ self::assertEquals('newGroup', $group->getName(), 'The group name did not save correctly.');
}
/**
@@ -34,7 +34,7 @@ public function testId()
$group = new Group();
$group->setId(3);
- $this->assertEquals(3, $group->getId(), 'The group id did not save correctly.');
- $this->assertTrue(is_int($group->getId()), 'The group id was not returned as an Integer.');
+ self::assertEquals(3, $group->getId(), 'The group id did not save correctly.');
+ self::assertTrue(\is_int($group->getId()), 'The group id was not returned as an Integer.');
}
}
diff --git a/tests/modules/user/models/UserTest.php b/tests/modules/user/models/UserTest.php
index 59c14f0a8..6cf5ee67d 100644
--- a/tests/modules/user/models/UserTest.php
+++ b/tests/modules/user/models/UserTest.php
@@ -1,6 +1,6 @@
setId(123);
- $this->assertEquals(123, $user->getId(), 'The id wasnt saved or returned correctly.');
+ self::assertEquals(123, $user->getId(), 'The id wasnt saved or returned correctly.');
}
/**
@@ -43,7 +43,7 @@ public function testSetGetUsername()
{
$user = new User();
$user->setName('username');
- $this->assertEquals('username', $user->getName(), 'The username wasnt saved or returned correctly.');
+ self::assertEquals('username', $user->getName(), 'The username wasnt saved or returned correctly.');
}
/**
@@ -53,7 +53,7 @@ public function testSetGetEmail()
{
$user = new User();
$user->setEmail('email');
- $this->assertEquals('email', $user->getEmail(), 'The email wasnt saved or returned correctly.');
+ self::assertEquals('email', $user->getEmail(), 'The email wasnt saved or returned correctly.');
}
/**
@@ -72,7 +72,7 @@ public function testSetGetGroups()
$group3->setName('Clanleader');
$user = new User();
$user->setGroups([$group1, $group2, $group3]);
- $this->assertEquals(
+ self::assertEquals(
[$group1, $group2, $group3],
$user->getGroups(),
'The user groups wasnt saved or returned correctly.'
@@ -96,7 +96,7 @@ public function testAddGroup()
$user = new User();
$user->setGroups([$group1, $group3]);
$user->addGroup($group2);
- $this->assertEquals(
+ self::assertEquals(
[$group1, $group3, $group2],
$user->getGroups(),
'The user groups wasnt added or returned correctly.'
@@ -124,11 +124,11 @@ public function testHasGroup()
$user->addGroup($group1)->addGroup($group2)->addGroup($group3);
- $this->assertTrue($user->hasGroup(2), 'The user has not the group with id "2".');
- $this->assertFalse($user->hasGroup(4), 'The user has the group with id "4".');
+ self::assertTrue($user->hasGroup(2), 'The user has not the group with id "2".');
+ self::assertFalse($user->hasGroup(4), 'The user has the group with id "4".');
$user->setGroups([]);
- $this->assertFalse($user->hasGroup(2), 'The user has the group with id "2".');
+ self::assertFalse($user->hasGroup(2), 'The user has the group with id "2".');
}
/**
@@ -144,22 +144,22 @@ public function testHasAccess()
$user->addGroup($group);
$dbMock = $this->createPartialMock(Mysql::class, ['queryCell', 'escape']);
- $dbMock->expects($this->once())
+ $dbMock->expects(self::once())
->method('escape')
->willReturnArgument(0);
- $dbMock->expects($this->once())
+ $dbMock->expects(self::once())
->method('queryCell')
->with(
- $this->logicalAnd(
- $this->stringContains('FROM [prefix]_groups_access'),
- $this->stringContains('INNER JOIN `[prefix]_modules`'),
- $this->stringContains('user')
+ self::logicalAnd(
+ self::stringContains('FROM [prefix]_groups_access'),
+ self::stringContains('INNER JOIN `[prefix]_modules`'),
+ self::stringContains('user')
)
)
- ->will($this->returnValue('0'));
+ ->willReturn('0');
Registry::remove('db');
Registry::set('db', $dbMock);
- $this->assertEquals(0, $user->hasAccess('module_user'));
+ self::assertEquals(0, $user->hasAccess('module_user'));
}
}