Merge branch 'feature-tests'

This commit is contained in:
Dmitry Khomutov 2016-08-13 17:48:52 +07:00
commit 8113d302ed
37 changed files with 409 additions and 1125 deletions

View file

@ -21,13 +21,25 @@ What it doesn't do (yet)
* Virtualised testing.
* Multiple PHP-version tests.
* Install PEAR or PECL extensions.
* Deployments - We strongly recommend using [Deployer](http://phpdeployment.org)
* Deployments
Documentation
=============
[PHP Censor documentation](docs/README.md)
Tests
=====
```bash
cd /path/to/php-censor
./vendor/bin/phpunit
```
For Phar plugin tests set 'phar.readonly' setting to Off (0) in `php.ini` config. Otherwise tests will be skipped.
For database B8Framework tests create empty 'b8_test' MySQL database on 'localhost' with user/password: `root/root`.
License
=======

View file

@ -3,7 +3,8 @@ b8:
servers:
read: localhost
write: localhost
name: php-censor-db
port: 3306
name: php-censor-db
username: php-censor-user
password: php-censor-password
php-censor:

View file

@ -12,15 +12,16 @@
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<!--<testsuite name="PHP Censor Command Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Command</directory>
</testsuite>-->
<testsuite name="PHP Censor Controller Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Controller</directory>
<testsuite name="B8Framework Test Suite">
<directory suffix="Test.php">./tests/B8Framework</directory>
</testsuite>
<testsuite name="PHP Censor Helper Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Helper</directory>
</testsuite>
<testsuite name="PHP Censor Controller Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Controller</directory>
</testsuite>
<testsuite name="PHP Censor Logging Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Logging</directory>
</testsuite>
@ -30,14 +31,14 @@
<testsuite name="PHP Censor Plugin Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Plugin</directory>
</testsuite>
<!--<testsuite name="PHP Censor ProcessControl Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
</testsuite>-->
<testsuite name="PHP Censor Service Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Service</directory>
</testsuite>
<!--<testsuite name="B8Framework Test Suite">
<directory suffix="Test.php">./tests/B8Framework</directory>
</testsuite>-->
<testsuite name="PHP Censor Command Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/Command</directory>
</testsuite>
<testsuite name="PHP Censor ProcessControl Test Suite">
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -10,52 +10,16 @@ class Database extends \PDO
protected static $details = [];
protected static $lastUsed = ['read' => null, 'write' => null];
/**
* @deprecated
*/
public static function setReadServers($read)
{
$config = Config::getInstance();
$settings = $config->get('b8.database', []);
$settings['servers']['read'] = $read;
$config->set('b8.database', $settings);
}
/**
* @deprecated
*/
public static function setWriteServers($write)
{
$config = Config::getInstance();
$settings = $config->get('b8.database', []);
$settings['servers']['write'] = $write;
$config->set('b8.database', $settings);
}
/**
* @deprecated
*/
public static function setDetails($database, $username, $password)
{
$config = Config::getInstance();
$settings = $config->get('b8.database', []);
$settings['name'] = $database;
$settings['username'] = $username;
$settings['password'] = $password;
$config->set('b8.database', $settings);
}
protected static function init()
{
$config = Config::getInstance();
$config = Config::getInstance();
$settings = $config->get('b8.database', []);
self::$servers['read'] = $settings['servers']['read'];
self::$servers['read'] = $settings['servers']['read'];
self::$servers['write'] = $settings['servers']['write'];
self::$details['db'] = $settings['name'];
self::$details['user'] = $settings['username'];
self::$details['pass'] = $settings['password'];
self::$details['db'] = $settings['name'];
self::$details['user'] = $settings['username'];
self::$details['pass'] = $settings['password'];
self::$initialised = true;
}
@ -63,6 +27,7 @@ class Database extends \PDO
* @param string $type
*
* @return \b8\Database
*
* @throws \Exception
*/
public static function getConnection($type = 'read')

View file

@ -1,380 +0,0 @@
<?php
/**
* Database generator updates a database to match a set of Models.
*/
namespace b8\Database;
use b8\Database;
class Generator
{
protected $_db = null;
protected $_map = null;
protected $_tables = null;
protected $_ns = null;
protected $_path = null;
public function __construct(Database $db, $namespace, $path)
{
$this->_db = $db;
$this->_ns = $namespace;
$this->_path = $path;
$this->_map = new Map($this->_db);
$this->_tables = $this->_map->generate();
}
public function generate()
{
error_reporting(E_ERROR & E_WARNING);
$di = new \DirectoryIterator($this->_path);
$this->_todo = [
'drop_fk' => [],
'drop_index' => [],
'create' => [],
'alter' => [],
'add_index' => [],
'add_fk' => [],
];
foreach ($di as $file) {
if ($file->isDot()) {
continue;
}
$fileName = explode('.', $file->getBasename());
if ($fileName[count($fileName) - 1] != 'php') {
continue;
}
$modelName = '\\' . $this->_ns . '\\Model\\Base\\' . str_replace('.php', '', $file->getFilename());
require_once($this->_path . $file->getFilename());
$model = new $modelName();
$columns = $model->columns;
$indexes = $model->indexes;
$foreignKeys = $model->foreignKeys;
$tableName = $model->getTableName();
if (!array_key_exists($tableName, $this->_tables)) {
$this->_createTable($tableName, $columns, $indexes, $foreignKeys);
continue;
} else {
$table = $this->_tables[$tableName];
$this->_updateColumns($tableName, $table, $columns);
$this->_updateRelationships($tableName, $table, $foreignKeys);
$this->_updateIndexes($tableName, $table, $indexes);
}
}
print 'DROP FK: ' . count($this->_todo['drop_fk']) . PHP_EOL;
print 'DROP INDEX: ' . count($this->_todo['drop_index']) . PHP_EOL;
print 'CREATE TABLE: ' . count($this->_todo['create']) . PHP_EOL;
print 'ALTER TABLE: ' . count($this->_todo['alter']) . PHP_EOL;
print 'ADD INDEX: ' . count($this->_todo['add_index']) . PHP_EOL;
print 'ADD FK: ' . count($this->_todo['add_fk']) . PHP_EOL;
$order = array_keys($this->_todo);
while ($group = array_shift($order)) {
if (!isset($this->_todo[$group]) || !is_array($this->_todo[$group]) || !count($this->_todo[$group])) {
continue;
}
foreach ($this->_todo[$group] as $query) {
try {
//print $query . PHP_EOL;
$this->_db->query($query);
} catch (\Exception $ex) {
print 'FAILED TO EXECUTE: ' . $query . PHP_EOL;
print $ex->getMessage() . PHP_EOL . PHP_EOL;
}
}
}
}
protected function _createTable($tbl, $cols, $idxs, $fks)
{
$defs = [];
$pks = [];
foreach ($cols as $colName => $def) {
$add = '`' . $colName . '` ' . $def['type'];
switch ($def['type']) {
case 'text':
case 'longtext':
case 'mediumtext':
case 'date':
case 'datetime':
case 'float':
$add .= '';
break;
default:
$add .= !empty($def['length']) ? '(' . $def['length'] . ')' : '';
break;
}
if (empty($def['nullable']) || !$def['nullable']) {
$add .= ' NOT NULL ';
}
if (!empty($def['default'])) {
$add .= ' DEFAULT ' . (is_numeric($def['default']) ? $def['default'] : '\'' . $def['default'] . '\'');
}
if (!empty($def['auto_increment']) && $def['auto_increment']) {
$add .= ' AUTO_INCREMENT ';
}
if (!empty($def['primary_key']) && $def['primary_key']) {
$pks[] = '`' . $colName . '`';
}
$defs[] = $add;
}
if (count($pks)) {
$defs[] = 'PRIMARY KEY (' . implode(', ', $pks) . ')';
}
$stmt = 'CREATE TABLE `' . $tbl . '` (' . PHP_EOL;
$stmt .= implode(", \n", $defs);
$stmt .= PHP_EOL . ') ENGINE=InnoDB DEFAULT CHARSET=utf8';
$stmt .= PHP_EOL;
$this->_todo['create'][] = $stmt;
foreach ($idxs as $name => $idx) {
$this->_addIndex($tbl, $name, $idx);
}
foreach ($fks as $name => $fk) {
$this->_addFk($tbl, $name, $fk);
}
}
protected function _updateColumns($tableName, $table, $columns)
{
$currentColumns = $table['columns'];
while ($column = array_shift($currentColumns)) {
if (!array_key_exists($column['name'], $columns)) {
$this->_todo['alter'][$tableName . '.' . $column['name']] = 'ALTER TABLE `' . $tableName . '` DROP COLUMN `' . $column['name'] . '`';
} else {
$model = $columns[$column['name']];
$model['nullable'] = !isset($model['nullable']) ? false : $model['nullable'];
$model['default'] = !isset($model['default']) ? false : $model['default'];
$model['auto_increment'] = !isset($model['auto_increment']) ? false : $model['auto_increment'];
$model['primary_key'] = !isset($model['primary_key']) ? false : $model['primary_key'];
$column['is_primary_key'] = !isset($column['is_primary_key']) ? false : $column['is_primary_key'];
if (
$column['type'] != $model['type'] || (
$column['length'] != $model['length'] &&
!in_array($model['type'], ['text', 'longtext', 'mediumtext', 'date', 'datetime', 'float'])
) ||
$column['null'] != $model['nullable'] ||
$column['default'] != $model['default'] ||
$column['auto'] != $model['auto_increment']
) {
$this->_updateColumn($tableName, $column['name'], $column['name'], $model);
}
}
unset($columns[$column['name']]);
}
if (count($columns)) {
foreach ($columns as $name => $model) {
// Check if we're renaming a column:
if (isset($model['rename'])) {
unset($this->_todo['alter'][$tableName . '.' . $model['rename']]);
$this->_updateColumn($tableName, $model['rename'], $name, $model);
continue;
}
// New column
$add = '`' . $name . '` ' . $model['type'];;
switch ($model['type']) {
case 'text':
case 'longtext':
case 'mediumtext':
case 'date':
case 'datetime':
case 'float':
$add .= '';
break;
default:
$add .= !empty($model['length']) ? '(' . $model['length'] . ')' : '';
break;
}
if (empty($model['nullable']) || !$model['nullable']) {
$add .= ' NOT NULL ';
}
if (!empty($model['default'])) {
$add .= ' DEFAULT ' . (is_numeric($model['default']) ? $model['default'] : '\'' . $model['default'] . '\'');
}
if (!empty($model['auto_increment']) && $model['auto_increment']) {
$add .= ' AUTO_INCREMENT ';
}
if (!empty($model['primary_key']) && $model['primary_key'] && !isset($table['indexes']['PRIMARY'])) {
$add .= ' PRIMARY KEY ';
}
$this->_todo['alter'][] = 'ALTER TABLE `' . $tableName . '` ADD COLUMN ' . $add;
}
}
}
protected function _updateColumn($tableName, $prevName, $newName, $model)
{
$add = '`' . $newName . '` ' . $model['type'];;
switch ($model['type']) {
case 'text':
case 'longtext':
case 'mediumtext':
case 'date':
case 'datetime':
case 'float':
$add .= '';
break;
default:
$add .= !empty($model['length']) ? '(' . $model['length'] . ')' : '';
break;
}
if (empty($model['nullable']) || !$model['nullable']) {
$add .= ' NOT NULL ';
}
if (!empty($model['default'])) {
$add .= ' DEFAULT ' . (is_numeric($model['default']) ? $model['default'] : '\'' . $model['default'] . '\'');
}
if (!empty($model['auto_increment']) && $model['auto_increment']) {
$add .= ' AUTO_INCREMENT ';
}
$this->_todo['alter'][] = 'ALTER TABLE `' . $tableName . '` CHANGE COLUMN `' . $prevName . '` ' . $add;
}
protected function _updateRelationships($tableName, $table, $foreignKeys)
{
$current = $table['relationships']['toOne'];
while ($foreignKey = array_shift($current)) {
if (!array_key_exists($foreignKey['fk_name'], $foreignKeys)) {
$this->_dropFk($tableName, $foreignKey['fk_name']);
} elseif ($foreignKey['from_col'] != $foreignKeys[$foreignKey['fk_name']]['local_col'] ||
$foreignKey['table'] != $foreignKeys[$foreignKey['fk_name']]['table'] ||
$foreignKey['col'] != $foreignKeys[$foreignKey['fk_name']]['col'] ||
$foreignKey['fk_update'] != $foreignKeys[$foreignKey['fk_name']]['update'] ||
$foreignKey['fk_delete'] != $foreignKeys[$foreignKey['fk_name']]['delete']
) {
$this->_alterFk($tableName, $foreignKey['fk_name'], $foreignKeys[$foreignKey['fk_name']]);
}
unset($foreignKeys[$foreignKey['fk_name']]);
}
if (count($foreignKeys)) {
foreach ($foreignKeys as $name => $foreignKey) {
// New column
$this->_addFk($tableName, $name, $foreignKey);
}
}
}
protected function _updateIndexes($tableName, $table, $indexes)
{
$current = $table['indexes'];
while ($index = array_shift($current)) {
if (!array_key_exists($index['name'], $indexes)) {
$this->_dropIndex($tableName, $index['name']);
} elseif ($index['unique'] != $indexes[$index['name']]['unique'] ||
$index['columns'] != $indexes[$index['name']]['columns']
) {
$this->_alterIndex($tableName, $index['name'], $index);
}
unset($indexes[$index['name']]);
}
if (count($indexes)) {
foreach ($indexes as $name => $index) {
if ($name == 'PRIMARY') {
continue;
}
// New index
$this->_addIndex($tableName, $name, $index);
}
}
}
protected function _addIndex($table, $name, $idx, $stage = 'add_index')
{
if ($name == 'PRIMARY') {
return;
}
$q = 'CREATE ' . (isset($idx['unique']) && $idx['unique'] ? 'UNIQUE' : '') . ' INDEX `' . $name . '` ON `' . $table . '` (' . $idx['columns'] . ')';
$this->_todo[$stage][] = $q;
}
protected function _alterIndex($table, $name, $idx, $stage = 'index')
{
$this->_dropIndex($table, $name, $stage);
$this->_addIndex($table, $name, $idx, $stage);
}
protected function _dropIndex($table, $idxName, $stage = 'drop_index')
{
if ($idxName == 'PRIMARY') {
return;
}
$q = 'DROP INDEX `' . $idxName . '` ON `' . $table . '`';
$this->_todo[$stage][] = $q;
}
protected function _addFk($table, $name, $fk)
{
$q = 'ALTER TABLE `' . $table . '` ADD CONSTRAINT `' . $name . '` FOREIGN KEY (`' . $fk['local_col'] . '`) REFERENCES `' . $fk['table'] . '` (`' . $fk['col'] . '`)';
if (!empty($fk['delete'])) {
$q .= ' ON DELETE ' . $fk['delete'] . ' ';
}
if (!empty($fk['update'])) {
$q .= ' ON UPDATE ' . $fk['update'] . ' ';
}
$this->_todo['add_fk'][] = $q;
}
protected function _alterFk($table, $name, $fk)
{
$this->_dropFk($table, $name);
$this->_addFk($table, $name, $fk);
}
protected function _dropFk($table, $name)
{
$q = 'ALTER TABLE `' . $table . '` DROP FOREIGN KEY `' . $name . '`';
$this->_todo['drop_fk'][] = $q;
}
}

View file

@ -1,258 +0,0 @@
<?php
namespace b8\Database;
use b8\Database;
class Map
{
protected $_db = null;
protected $_tables = [];
public function __construct(Database $db)
{
$this->_db = $db;
}
public function generate()
{
$tables = $this->_getTables();
foreach ($tables as $table) {
$this->_tables[$table] = [];
$this->_tables[$table]['php_name'] = $this->_generatePhpName($table);
}
$this->_getRelationships();
$this->_getColumns();
$this->_getIndexes();
return $this->_tables;
}
protected function _getTables()
{
$details = $this->_db->getDetails();
$rtn = [];
foreach ($this->_db->query('SHOW TABLES')->fetchAll(\PDO::FETCH_ASSOC) as $tbl) {
$rtn[] = $tbl['Tables_in_' . $details['db']];
}
return $rtn;
}
protected function _getRelationships()
{
foreach ($this->_tables as $table => $t) {
$res = $this->_db->query('SHOW CREATE TABLE `' . $table . '`')->fetchAll(\PDO::FETCH_ASSOC);
foreach ($res as $r) {
$str = $r['Create Table'];
$matches = [];
if (preg_match_all('/CONSTRAINT\s+\`([a-zA-Z0-9_]+)\`\s+FOREIGN\s+KEY\s+\(\`([a-zA-Z0-9_]+)\`\)\s+REFERENCES\s+\`([a-zA-Z0-9_]+)\`\s+\(\`([a-zA-Z0-9_]+)\`\)(\s+ON (DELETE|UPDATE) (SET NULL|NO ACTION|CASCADE|RESTRICT))?(\s+ON (DELETE|UPDATE) (SET NULL|NO ACTION|CASCADE|RESTRICT))?/',
$str, $matches)) {
for ($i = 0; $i < count($matches[0]); $i++) {
$fromTable = $table;
$fromCol = $matches[2][$i];
$toTable = $matches[3][$i];
$toCol = $matches[4][$i];
$fkName = $matches[1][$i];
$fk = [];
if (isset($matches[6][$i])) {
$fk[$matches[6][$i]] = $matches[7][$i];
}
if (isset($matches[9][$i])) {
$fk[$matches[9][$i]] = $matches[10][$i];
}
$fk['UPDATE'] = empty($fk['UPDATE']) ? '' : $fk['UPDATE'];
$fk['DELETE'] = empty($fk['DELETE']) ? '' : $fk['DELETE'];
if (isset($this->_tables[$fromTable]) && isset($this->_tables[$toTable])) {
$phpName = $this->_generateFkName($fromCol, $this->_tables[$fromTable]['php_name']);
$this->_tables[$fromTable]['relationships']['toOne'][$fromCol] = [
'fk_name' => $fkName,
'fk_delete' => $fk['DELETE'],
'fk_update' => $fk['UPDATE'],
'table_php_name' => $this->_tables[$toTable]['php_name'],
'from_col_php' => $this->_generatePhpName($fromCol),
'from_col' => $fromCol,
'php_name' => $phpName,
'table' => $toTable,
'col' => $toCol,
'col_php' => $this->_generatePhpName($toCol)
];
$phpName = $this->_generateFkName(
$fromCol,
$this->_tables[$fromTable]['php_name']
) . $this->_tables[$fromTable]['php_name'] . 's';
$this->_tables[$toTable]['relationships']['toMany'][] = [
'from_col_php' => $this->_generatePhpName($fromCol),
'php_name' => $phpName,
'thisCol' => $toCol,
'table' => $fromTable,
'table_php' => $this->_generatePhpName($fromTable),
'fromCol' => $fromCol,
'col_php' => $this->_generatePhpName($toCol)
];
}
}
}
}
}
}
protected function _getColumns()
{
foreach ($this->_tables as $key => &$val) {
$cols = [];
foreach ($this->_db->query('DESCRIBE `' . $key . '`')->fetchAll(\PDO::FETCH_ASSOC) as $column) {
$col = $this->_processColumn([], $column, $val);
$cols[$col['name']] = $col;
}
$val['columns'] = $cols;
}
}
protected function _getIndexes()
{
foreach ($this->_tables as $key => &$val) {
$indexes = [];
foreach ($this->_db->query('SHOW INDEXES FROM `' . $key . '`')->fetchAll(\PDO::FETCH_ASSOC) as $idx) {
if (!isset($indexes[$idx['Key_name']])) {
$indexes[$idx['Key_name']] = [];
$indexes[$idx['Key_name']]['name'] = $idx['Key_name'];
$indexes[$idx['Key_name']]['unique'] = ($idx['Non_unique'] == '0') ? true : false;
$indexes[$idx['Key_name']]['columns'] = [];
}
$indexes[$idx['Key_name']]['columns'][$idx['Seq_in_index']] = $idx['Column_name'];
}
$indexes = array_map(function ($idx) {
ksort($idx['columns']);
$idx['columns'] = implode(', ', $idx['columns']);
return $idx;
}, $indexes);
$val['indexes'] = $indexes;
}
}
protected function _processColumn($col, $column, &$table)
{
$col['name'] = $column['Field'];
$col['php_name'] = $this->_generatePhpName($col['name']);
$matches = [];
preg_match('/^([a-zA-Z]+)(\()?([0-9\,]+)?(\))?/', $column['Type'], $matches);
$col['type'] = strtolower($matches[1]);
if (isset($matches[3])) {
$col['length'] = $matches[3];
}
$col['null'] = strtolower($column['Null']) == 'yes' ? true : false;
$col['auto'] = strtolower($column['Extra']) == 'auto_increment' ? true : false;
if ($column['Default'] == 'NULL' || is_null($column['Default'])) {
$col['default_is_null'] = true;
} else {
$col['default_is_null'] = false;
$col['default'] = $column['Default'];
}
if (!empty($column['Key'])) {
if ($column['Key'] == 'PRI') {
$col['is_primary_key'] = true;
$table['primary_key'] = ['column' => $col['name'], 'php_name' => $col['php_name']];
}
if ($column['Key'] == 'PRI' || $column['Key'] == 'UNI') {
$col['unique_indexed'] = true;
} else {
$col['many_indexed'] = true;
}
}
$col['validate'] = [];
if (!$col['null']) {
$col['validate_null'] = true;
}
switch ($col['type']) {
case 'tinyint':
case 'smallint':
case 'int':
case 'mediumint':
case 'bigint':
$col['php_type'] = 'int';
$col['to_php'] = '_sqlToInt';
$col['validate_int'] = true;
break;
case 'float':
case 'decimal':
$col['php_type'] = 'float';
$col['to_php'] = '_sqlToFloat';
$col['validate_float'] = true;
break;
case 'datetime':
case 'date':
$col['php_type'] = 'DateTime';
$col['to_php'] = '_sqlToDateTime';
$col['to_sql'] = '_dateTimeToSql';
$col['validate_date'] = true;
break;
case 'varchar':
case 'text':
default:
$col['php_type'] = 'string';
$col['validate_string'] = true;
break;
}
return $col;
}
protected function _generatePhpName($sqlName)
{
$rtn = $sqlName;
$rtn = str_replace('_', ' ', $rtn);
$rtn = ucwords($rtn);
$rtn = str_replace(' ', '', $rtn);
return $rtn;
}
protected function _generateFkName($sqlName, $tablePhpName)
{
$fkMethod = substr($sqlName, 0, strripos($sqlName, '_'));
if (empty($fkMethod)) {
$fkMethod = (substr(strtolower($sqlName), -2) == 'id') ? substr($sqlName, 0, -2) : $tablePhpName;
}
$fkMethod = str_replace('_', ' ', $fkMethod);
$fkMethod = ucwords($fkMethod);
$fkMethod = str_replace(' ', '', $fkMethod);
return $fkMethod;
}
}

View file

@ -97,11 +97,11 @@ abstract class Element
$view = new View($viewFile, B8_PATH . 'Form/View/');
}
$view->name = $this->getName();
$view->id = $this->getId();
$view->label = $this->getLabel();
$view->css = $this->getClass();
$view->ccss = $this->getContainerClass();
$view->name = $this->getName();
$view->id = $this->getId();
$view->label = $this->getLabel();
$view->css = $this->getClass();
$view->ccss = $this->getContainerClass();
$view->parent = $this->_parent;
$this->_onPreRender($view);

View file

@ -2,7 +2,7 @@
namespace b8;
use b8\Exception\HttpException;
class ViewRuntimeException extends \RuntimeException {}
class View
{
@ -13,7 +13,7 @@ class View
public function __construct($file, $path = null)
{
if (!self::exists($file, $path)) {
throw new \Exception('View file does not exist: ' . $file);
throw new ViewRuntimeException('View file does not exist: ' . $file);
}
$this->viewFile = self::getViewFile($file, $path);
@ -61,7 +61,7 @@ class View
}
if (!class_exists($class)) {
throw new HttpException('Helper class does not exist: ' . $class);
throw new \Exception('Helper class does not exist: ' . $class);
}
self::$_helpers[$method] = new $class();

View file

@ -20,9 +20,10 @@ use Symfony\Component\Console\Question\Question;
/**
* Create admin command - creates an admin user
* @author Wogan May (@woganmay)
* @package PHPCI
* @subpackage Console
*
* @author Wogan May (@woganmay)
* @package PHPCI
* @subpackage Console
*/
class CreateAdminCommand extends Command
{

View file

@ -144,9 +144,13 @@ abstract class BaseCommandExecutor implements CommandExecutor
}
/**
* Find a binary required by a plugin.
* Find a binary required by a plugin
*
* @param string $binary
* @param bool $quiet
* @param bool $quiet
*
* @throws Exception
*
* @return null|string
*/
public function findBinary($binary, $quiet = false)
@ -162,22 +166,26 @@ abstract class BaseCommandExecutor implements CommandExecutor
if (is_dir($composerBin) && is_file($composerBin . DIRECTORY_SEPARATOR . $bin)) {
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
return $composerBin . DIRECTORY_SEPARATOR . $bin;
}
if (is_file($this->rootDir . $bin)) {
if (is_file($this->rootDir . DIRECTORY_SEPARATOR . $bin)) {
$this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
return $this->rootDir . $bin;
return $this->rootDir . DIRECTORY_SEPARATOR . $bin;
}
if (is_file($this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin)) {
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
return $this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;
}
$findCmdResult = $this->findGlobalBinary($bin);
if (is_file($findCmdResult)) {
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
return $findCmdResult;
}
}
@ -185,6 +193,7 @@ abstract class BaseCommandExecutor implements CommandExecutor
if ($quiet) {
return null;
}
throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
}

View file

@ -102,7 +102,7 @@ class Email
*
* @param Builder $builder
*
* @return bool|int
* @return integer
*/
public function send(Builder $builder)
{
@ -110,9 +110,9 @@ class Email
$builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
if (empty($smtpServer)) {
return $this->sendViaMail();
return (integer)$this->sendViaMail();
} else {
return $this->sendViaSwiftMailer();
return (integer)$this->sendViaSwiftMailer();
}
}
@ -148,6 +148,7 @@ class Email
/**
* Sends the email using SwiftMailer.
*
* @return int
*/
protected function sendViaSwiftMailer()

View file

@ -125,12 +125,17 @@ class Lang
* Initialise the Language helper, try load the language file for the user's browser or the configured default.
*
* @param Config $config
* @param string $language_force
*/
public static function init(Config $config)
public static function init(Config $config, $language_force = null)
{
self::$en_strings = self::loadLanguage('en');
self::loadAvailableLanguages();
if ($language_force && self::setLanguage($language_force)) {
return;
}
// Try cookies first:
if (isset($_COOKIE) && array_key_exists('php-censor-language', $_COOKIE) && self::setLanguage($_COOKIE['php-censor-language'])) {
return;
@ -141,7 +146,7 @@ class Lang
$langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $lang) {
$parts = explode(';', $lang);
$parts = explode(';', $lang);
$language = strtolower($parts[0]);
if (self::setLanguage($language)) {

View file

@ -184,10 +184,10 @@ class BuildBase extends Model
];
/**
* Get the value of Id / id.
*
* @return int
*/
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
@ -196,10 +196,10 @@ class BuildBase extends Model
}
/**
* Get the value of ProjectId / project_id.
*
* @return int
*/
* Get the value of ProjectId / project_id.
*
* @return int
*/
public function getProjectId()
{
$rtn = $this->data['project_id'];
@ -208,10 +208,10 @@ class BuildBase extends Model
}
/**
* Get the value of CommitId / commit_id.
*
* @return string
*/
* Get the value of CommitId / commit_id.
*
* @return string
*/
public function getCommitId()
{
$rtn = $this->data['commit_id'];
@ -220,10 +220,10 @@ class BuildBase extends Model
}
/**
* Get the value of Status / status.
*
* @return int
*/
* Get the value of Status / status.
*
* @return int
*/
public function getStatus()
{
$rtn = $this->data['status'];
@ -232,10 +232,10 @@ class BuildBase extends Model
}
/**
* Get the value of Log / log.
*
* @return string
*/
* Get the value of Log / log.
*
* @return string
*/
public function getLog()
{
$rtn = $this->data['log'];
@ -244,10 +244,10 @@ class BuildBase extends Model
}
/**
* Get the value of Branch / branch.
*
* @return string
*/
* Get the value of Branch / branch.
*
* @return string
*/
public function getBranch()
{
$rtn = $this->data['branch'];
@ -256,10 +256,10 @@ class BuildBase extends Model
}
/**
* Get the value of Created / created.
*
* @return \DateTime
*/
* Get the value of Created / created.
*
* @return \DateTime
*/
public function getCreated()
{
$rtn = $this->data['created'];
@ -272,10 +272,10 @@ class BuildBase extends Model
}
/**
* Get the value of Started / started.
*
* @return \DateTime
*/
* Get the value of Started / started.
*
* @return \DateTime
*/
public function getStarted()
{
$rtn = $this->data['started'];
@ -288,10 +288,10 @@ class BuildBase extends Model
}
/**
* Get the value of Finished / finished.
*
* @return \DateTime
*/
* Get the value of Finished / finished.
*
* @return \DateTime
*/
public function getFinished()
{
$rtn = $this->data['finished'];
@ -304,10 +304,10 @@ class BuildBase extends Model
}
/**
* Get the value of CommitterEmail / committer_email.
*
* @return string
*/
* Get the value of CommitterEmail / committer_email.
*
* @return string
*/
public function getCommitterEmail()
{
$rtn = $this->data['committer_email'];
@ -316,10 +316,10 @@ class BuildBase extends Model
}
/**
* Get the value of CommitMessage / commit_message.
*
* @return string
*/
* Get the value of CommitMessage / commit_message.
*
* @return string
*/
public function getCommitMessage()
{
$rtn = $this->data['commit_message'];
@ -328,10 +328,10 @@ class BuildBase extends Model
}
/**
* Get the value of Extra / extra.
*
* @return string
*/
* Get the value of Extra / extra.
*
* @return string
*/
public function getExtra()
{
$rtn = $this->data['extra'];
@ -340,11 +340,10 @@ class BuildBase extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
* Set the value of Id / id. Must not be null.
*
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
@ -360,11 +359,10 @@ class BuildBase extends Model
}
/**
* Set the value of ProjectId / project_id.
*
* Must not be null.
* @param $value int
*/
* Set the value of ProjectId / project_id. Must not be null.
*
* @param $value int
*/
public function setProjectId($value)
{
$this->_validateNotNull('ProjectId', $value);
@ -380,11 +378,10 @@ class BuildBase extends Model
}
/**
* Set the value of CommitId / commit_id.
*
* Must not be null.
* @param $value string
*/
* Set the value of CommitId / commit_id. Must not be null.
*
* @param $value string
*/
public function setCommitId($value)
{
$this->_validateNotNull('CommitId', $value);
@ -400,11 +397,10 @@ class BuildBase extends Model
}
/**
* Set the value of Status / status.
*
* Must not be null.
* @param $value int
*/
* Set the value of Status / status. Must not be null.
*
* @param $value int
*/
public function setStatus($value)
{
$this->_validateNotNull('Status', $value);
@ -420,10 +416,10 @@ class BuildBase extends Model
}
/**
* Set the value of Log / log.
*
* @param $value string
*/
* Set the value of Log / log.
*
* @param $value string
*/
public function setLog($value)
{
$this->_validateString('Log', $value);
@ -438,11 +434,10 @@ class BuildBase extends Model
}
/**
* Set the value of Branch / branch.
*
* Must not be null.
* @param $value string
*/
* Set the value of Branch / branch. Must not be null.
*
* @param $value string
*/
public function setBranch($value)
{
$this->_validateNotNull('Branch', $value);
@ -458,10 +453,10 @@ class BuildBase extends Model
}
/**
* Set the value of Created / created.
*
* @param $value \DateTime
*/
* Set the value of Created / created.
*
* @param $value \DateTime
*/
public function setCreated($value)
{
$this->_validateDate('Created', $value);
@ -476,10 +471,10 @@ class BuildBase extends Model
}
/**
* Set the value of Started / started.
*
* @param $value \DateTime
*/
* Set the value of Started / started.
*
* @param $value \DateTime
*/
public function setStarted($value)
{
$this->_validateDate('Started', $value);
@ -494,10 +489,10 @@ class BuildBase extends Model
}
/**
* Set the value of Finished / finished.
*
* @param $value \DateTime
*/
* Set the value of Finished / finished.
*
* @param $value \DateTime
*/
public function setFinished($value)
{
$this->_validateDate('Finished', $value);
@ -512,10 +507,10 @@ class BuildBase extends Model
}
/**
* Set the value of CommitterEmail / committer_email.
*
* @param $value string
*/
* Set the value of CommitterEmail / committer_email.
*
* @param $value string
*/
public function setCommitterEmail($value)
{
$this->_validateString('CommitterEmail', $value);
@ -530,10 +525,10 @@ class BuildBase extends Model
}
/**
* Set the value of CommitMessage / commit_message.
*
* @param $value string
*/
* Set the value of CommitMessage / commit_message.
*
* @param $value string
*/
public function setCommitMessage($value)
{
$this->_validateString('CommitMessage', $value);
@ -548,10 +543,10 @@ class BuildBase extends Model
}
/**
* Set the value of Extra / extra.
*
* @param $value string
*/
* Set the value of Extra / extra.
*
* @param $value string
*/
public function setExtra($value)
{
$this->_validateString('Extra', $value);
@ -568,8 +563,6 @@ class BuildBase extends Model
/**
* Get the Project model for this Build by Id.
*
* @uses \PHPCensor\Store\ProjectStore::getById()
* @uses \PHPCensor\Model\Project
* @return \PHPCensor\Model\Project
*/
public function getProject()
@ -592,10 +585,10 @@ class BuildBase extends Model
}
/**
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
* @param $value mixed
*/
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
* @param $value mixed
*/
public function setProject($value)
{
// Is this an instance of Project?
@ -613,10 +606,10 @@ class BuildBase extends Model
}
/**
* Set Project - Accepts a Project model.
*
* @param $value Project
*/
* Set Project - Accepts a Project model.
*
* @param $value Project
*/
public function setProjectObject(Project $value)
{
return $this->setProjectId($value->getId());
@ -624,9 +617,7 @@ class BuildBase extends Model
/**
* Get BuildError models by BuildId for this Build.
*
* @uses \PHPCensor\Store\BuildErrorStore::getByBuildId()
* @uses \PHPCensor\Model\BuildError
*
* @return \PHPCensor\Model\BuildError[]
*/
public function getBuildBuildErrors()
@ -636,9 +627,7 @@ class BuildBase extends Model
/**
* Get BuildMeta models by BuildId for this Build.
*
* @uses \PHPCensor\Store\BuildMetaStore::getByBuildId()
* @uses \PHPCensor\Model\BuildMeta
*
* @return \PHPCensor\Model\BuildMeta[]
*/
public function getBuildBuildMetas()

View file

@ -15,18 +15,16 @@ use PHPCensor\Builder;
use Symfony\Component\Yaml\Parser as YamlParser;
/**
* Build Model
* @uses PHPCensor\Model\Base\BuildBase
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core
*/
* Build Model
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class Build extends BuildBase
{
const STATUS_NEW = 0;
const STATUS_NEW = 0;
const STATUS_RUNNING = 1;
const STATUS_SUCCESS = 2;
const STATUS_FAILED = 3;
const STATUS_FAILED = 3;
public $currentBuildPath;
@ -48,6 +46,7 @@ class Build extends BuildBase
/**
* Return a template to use to generate a link to a specific file.
*
* @return null
*/
public function getFileLinkTemplate()

View file

@ -9,6 +9,8 @@
namespace PHPCensor\Plugin;
use b8\Config;
use b8\ViewRuntimeException;
use Exception;
use b8\View;
use PHPCensor\Builder;
@ -58,6 +60,8 @@ class Email implements Plugin
/**
* Send a notification mail.
*
* @return boolean
*/
public function execute()
{
@ -72,15 +76,7 @@ class Email implements Plugin
$buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
$projectName = $this->build->getProject()->getTitle();
try {
$view = $this->getMailTemplate();
} catch (Exception $e) {
$this->phpci->log(
sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']),
LogLevel::WARNING
);
$view = $this->getDefaultMailTemplate();
}
$view = $this->getMailTemplate();
$view->build = $this->build;
$view->project = $this->build->getProject();
@ -109,7 +105,8 @@ class Email implements Plugin
* @param string[] $ccList
* @param string $subject Email subject
* @param string $body Email body
* @return array Array of failed addresses
*
* @return integer
*/
protected function sendEmail($toAddress, $ccList, $subject, $body)
{
@ -224,8 +221,17 @@ class Email implements Plugin
*/
protected function getMailTemplate()
{
if (isset($this->options['template'])) {
return new View('Email/' . $this->options['template']);
try {
if (isset($this->options['template'])) {
return new View('Email/' . $this->options['template']);
}
} catch (ViewRuntimeException $e) {
$this->phpci->log(
sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']),
LogLevel::WARNING
);
return $this->getDefaultMailTemplate();
}
return $this->getDefaultMailTemplate();

View file

@ -50,18 +50,13 @@ class PhpCpd implements Plugin
$this->phpci = $phpci;
$this->build = $build;
$this->path = $phpci->buildPath;
$this->standard = 'PSR1';
$this->path = $phpci->buildPath;
$this->ignore = $phpci->ignore;
if (!empty($options['path'])) {
$this->path = $phpci->buildPath . $options['path'];
}
if (!empty($options['standard'])) {
$this->standard = $options['standard'];
}
if (!empty($options['ignore'])) {
$this->ignore = $options['ignore'];
}

View file

@ -16,7 +16,7 @@ class TapParser
const TEST_LINE_PATTERN = '/^(ok|not ok)(?:\s+\d+)?(?:\s+\-)?\s*(.*?)(?:\s*#\s*(skip|todo)\s*(.*))?\s*$/i';
const TEST_YAML_START = '/^(\s*)---/';
const TEST_DIAGNOSTIC = '/^#/';
const TEST_COVERAGE = '/^Generating/';
const TEST_COVERAGE = '/(Generating code coverage|The Xdebug extension is not loaded|No code coverage)/';
/**
* @var string

View file

@ -28,14 +28,11 @@ class PosixProcessControl implements ProcessControlInterface
}
/**
* Sends a TERMINATE or KILL signal to the process using posix_kill.
*
* @param int $pid
* @param bool $forcefully Whether to send TERMINATE (false) or KILL (true).
* {@inheritdoc}
*/
public function kill($pid, $forcefully = false)
{
posix_kill($pid, $forcefully ? 9 : 15);
return posix_kill($pid, $forcefully ? 9 : 15);
}
/**

View file

@ -16,7 +16,8 @@ namespace PHPCensor\ProcessControl;
*/
interface ProcessControlInterface
{
/** Checks if a process exists.
/**
* Checks if a process exists.
*
* @param int $pid The process identifier.
*
@ -24,10 +25,13 @@ interface ProcessControlInterface
*/
public function isRunning($pid);
/** Terminate a running process.
/**
* Terminate a running process.
*
* @param int $pid The process identifier.
* @param bool $forcefully Whether to gently (false) or forcefully (true) terminate the process.
*
* @return boolean
*/
public function kill($pid, $forcefully = false);
}

View file

@ -30,14 +30,16 @@ class UnixProcessControl implements ProcessControlInterface
}
/**
* Sends a signal using the "kill" command.
*
* @param int $pid
* @param bool $forcefully
* {@inheritdoc}
*/
public function kill($pid, $forcefully = false)
{
exec(sprintf("kill -%d %d", $forcefully ? 9 : 15, $pid));
$output = [];
$result = 1;
exec(sprintf("kill -%d %d", $forcefully ? 9 : 15, $pid), $output, $result);
return !$result;
}
/**

View file

@ -31,15 +31,16 @@ class WindowsProcessControl implements ProcessControlInterface
}
/**
* Terminate the process using the "taskkill" command.
*
* @param integer $pid
*
* @param bool $forcefully
* {@inheritdoc}
*/
public function kill($pid, $forcefully = false)
{
$output = [];
$result = 1;
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
return !$result;
}
/**

View file

@ -4,12 +4,12 @@ namespace Tests\b8;
use b8\Config, b8\Cache;
class CacheTest extends PHPUnit_Framework_TestCase
class CacheTest extends \PHPUnit_Framework_TestCase
{
public function testCreateSingleton()
{
$cache = Cache::getCache(Cache::TYPE_APC);
$this->assertTrue($cache instanceof Cache);
self::assertInstanceOf('\b8\Cache\ApcCache', $cache);
}
public function testDisableCaching()

View file

@ -1,75 +0,0 @@
<?php
namespace Tests\b8;
use b8\Database\Generator, b8\Database\Map, b8\Database;
class DatabaseGenerationTest extends \PHPUnit_Framework_TestCase
{
protected $_host = 'localhost';
protected $_user = 'b8_test';
protected $_pass = 'b8_test';
protected $_name = 'b8_test';
protected $_db;
public function setUp()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
Database::setWriteServers([$this->_host]);
$this->_db = Database::getConnection('write');
$this->_db->query('DROP TABLE IF EXISTS tres');
$this->_db->query('DROP TABLE IF EXISTS dos');
$this->_db->query('DROP TABLE IF EXISTS uno');
}
public function testCreateDatabase()
{
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
$gen->generate();
$map = new Map($this->_db);
$t = $map->generate();
$this->assertTrue(array_key_exists('uno', $t));
$this->assertTrue(array_key_exists('dos', $t));
$this->assertTrue(array_key_exists('tres', $t));
$this->assertFalse(array_key_exists('bad_table', $t));
$this->assertTrue(count($t['uno']['indexes']) == 1);
$this->assertTrue(count($t['dos']['indexes']) == 3);
$this->assertTrue(count($t['tres']['indexes']) == 2);
$this->assertTrue(count($t['uno']['columns']) == 11);
$this->assertTrue(count($t['dos']['columns']) == 4);
$this->assertTrue(count($t['tres']['columns']) == 6);
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
$this->assertFalse(array_key_exists('PRIMARY', $t['tres']['indexes']));
}
public function testUpdateDatabase()
{
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
$gen->generate();
$gen = new Generator($this->_db, 'Update', __DIR__ . '/data/generation/update_models/');
$gen->generate();
$map = new Map($this->_db);
$t = $map->generate();
$this->assertTrue(array_key_exists('uno', $t));
$this->assertTrue(array_key_exists('dos', $t));
$this->assertTrue(array_key_exists('tres', $t));
$this->assertFalse(array_key_exists('bad_table', $t));
$this->assertTrue(count($t['uno']['indexes']) == 1);
$this->assertTrue(count($t['dos']['indexes']) == 3);
$this->assertTrue(count($t['tres']['indexes']) == 3);
$this->assertTrue(count($t['uno']['columns']) == 10);
$this->assertTrue(count($t['dos']['columns']) == 4);
$this->assertTrue(count($t['tres']['columns']) == 10);
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
$this->assertTrue(array_key_exists('PRIMARY', $t['tres']['indexes']));
}
}

View file

@ -2,20 +2,30 @@
namespace Tests\b8;
use b8\Config;
use b8\Database;
class DatabaseTest extends \PHPUnit_Framework_TestCase
{
protected $_host = 'localhost';
protected $_user = 'b8_test';
protected $_pass = 'b8_test';
protected $_name = 'b8_test';
protected function setUp()
{
$config = new Config([
'b8' => [
'database' => [
'servers' => [
'read' => 'localhost',
'write' => 'localhost',
],
'name' => 'b8_test',
'username' => 'root',
'password' => 'root',
],
],
]);
}
public function testGetReadConnection()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
Database::setReadServers([$this->_host]);
$connection = Database::getConnection('read');
$this->assertInstanceOf('\b8\Database', $connection);
@ -23,9 +33,6 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
public function testGetWriteConnection()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
Database::setWriteServers([$this->_host]);
$connection = Database::getConnection('write');
$this->assertInstanceOf('\b8\Database', $connection);
@ -33,14 +40,11 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
public function testGetDetails()
{
Database::setDetails($this->_name, $this->_user, $this->_pass);
Database::setReadServers(['localhost']);
$details = Database::getConnection('read')->getDetails();
$this->assertTrue(is_array($details));
$this->assertTrue(($details['db'] == $this->_name));
$this->assertTrue(($details['user'] == $this->_user));
$this->assertTrue(($details['pass'] == $this->_pass));
$this->assertTrue(($details['db'] == 'b8_test'));
$this->assertTrue(($details['user'] == 'root'));
$this->assertTrue(($details['pass'] == 'root'));
}
/**
@ -48,8 +52,22 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
*/
public function testConnectionFailure()
{
Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
Database::setReadServers(['localhost']);
Database::reset();
$config = new Config([
'b8' => [
'database' => [
'servers' => [
'read' => 'localhost',
'write' => 'localhost',
],
'name' => 'b8_test_2',
'username' => '',
'password' => '',
],
],
]);
Database::getConnection('read');
}
}

View file

@ -15,12 +15,17 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($f->getAction() == '/');
$this->assertTrue($f->getMethod() == 'POST');
$config = new Config();
Config::getInstance()->set('ViewPath', __DIR__ . '/data/view/');
$config = new Config([
'b8' => [
'view' => [
'path' => __DIR__ . '/data/view/'
]
]
]);
$this->assertTrue($f->render('form') == '/POST');
Config::getInstance()->set('ViewPath', '');
Config::getInstance()->set('b8.view.path', '');
$this->assertTrue(strpos((string)$f, '<form') !== false);
}
@ -32,7 +37,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
$f->setClass('element-class');
$f->setContainerClass('container-class');
$this->assertTrue($f->getName() == 'elementname');
$this->assertTrue($f->getName() == 'element-name');
$this->assertTrue($f->getId() == 'element-id');
$this->assertTrue($f->getLabel() == 'element-label');
$this->assertTrue($f->getClass() == 'element-class');

View file

@ -2,7 +2,8 @@
namespace Tests\b8;
use b8\View, b8\View\UserView;
use b8\View;
use b8\View\Template;
class ViewTest extends \PHPUnit_Framework_TestCase
{
@ -44,92 +45,94 @@ class ViewTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \b8\Exception\HttpException
* @expectedException \Exception
*/
public function testInvalidHelper()
{
$view = new UserView('{@Invalid:test}');
$view = new Template('{@Invalid:test}');
$view->render();
}
public function testSimpleUserView()
{
$view = new UserView('Hello');
$view = new Template('Hello');
$this->assertTrue($view->render() == 'Hello');
}
public function testUserViewYear()
{
$view = new UserView('{@year}');
$view = new Template('{@year}');
$this->assertTrue($view->render() == date('Y'));
}
public function testUserViewVars()
{
$view = new UserView('Hello {@who}');
$view = new Template('Hello {@who}');
$view->who = 'World';
$this->assertTrue($view->render() == 'Hello World');
$view = new UserView('Hello {@who}');
$view = new Template('Hello {@who}');
$this->assertTrue($view->render() == 'Hello ');
$view = new UserView('Hello {@who.name}');
$view = new Template('Hello {@who.name}');
$view->who = ['name' => 'Dan'];
$this->assertTrue($view->render() == 'Hello Dan');
$tmp = new UserView('Hello');
$tmp->who = 'World';
$view = new UserView('Hello {@tmp.who}');
$tmp = new Template('Hello');
$tmp->who = 'World';
$view = new Template('Hello {@tmp.who}');
$view->tmp = $tmp;
$this->assertTrue($view->render() == 'Hello World');
$tmp = new UserView('Hello');
$view = new UserView('Hello {@tmp.who}');
$view->tmp = $tmp;
try {
$tmp = new Template('Hello');
$view = new Template('Hello {@tmp.who}');
$view->tmp = $tmp;
$this->assertTrue($view->render() == 'Hello ');
} catch (\Exception $e) {
self::assertInstanceOf('\ErrorException', $e);
}
$this->assertTrue($view->render() == 'Hello ');
$view = new UserView('Hello {@who.toUpperCase}');
$view = new Template('Hello {@who.toUpperCase}');
$view->who = 'World';
$this->assertTrue($view->render() == 'Hello WORLD');
$view = new UserView('Hello {@who.toLowerCase}');
$view = new Template('Hello {@who.toLowerCase}');
$view->who = 'World';
$this->assertTrue($view->render() == 'Hello world');
}
public function testUserViewIf()
{
$view = new UserView('Hello{if who} World{/if}');
$view = new Template('Hello{if who} World{/if}');
$view->who = true;
$this->assertTrue($view->render() == 'Hello World');
$view = new UserView('Hello{if who} World{/if}');
$view = new Template('Hello{if who} World{/if}');
$view->who = false;
$this->assertTrue($view->render() == 'Hello');
$view = new UserView('Hello{ifnot who} World{/ifnot}');
$view = new Template('Hello{ifnot who} World{/ifnot}');
$view->who = true;
$this->assertTrue($view->render() == 'Hello');
$view = new UserView('Hello {if Format:not_present}World{/if}');
$view = new Template('Hello {if Format:not_present}World{/if}');
$this->assertTrue($view->render() == 'Hello ');
$view = new UserView('Hello {ifnot Format:not_present}World{/ifnot}');
$view = new Template('Hello {ifnot Format:not_present}World{/ifnot}');
$this->assertTrue($view->render() == 'Hello World');
}
public function testUserViewLoop()
{
$view = new UserView('Hello {loop who}{@item}{/loop}');
$view = new Template('Hello {loop who}{@item}{/loop}');
$view->who = ['W', 'o', 'r', 'l', 'd'];
$this->assertTrue($view->render() == 'Hello World');
$view = new UserView('Hello {loop who}{@item}{/loop}');
$view = new Template('Hello {loop who}{@item}{/loop}');
$this->assertTrue($view->render() == 'Hello ');
$view = new UserView('Hello {loop who}{@item}{/loop}');
$view = new Template('Hello {loop who}{@item}{/loop}');
$view->who = 'World';
$this->assertTrue($view->render() == 'Hello World');
}

View file

@ -10,6 +10,8 @@
namespace Tests\PHPCensor\Plugin\Command;
use PHPCensor\Command\CreateAdminCommand;
use PHPCensor\Store\UserStore;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
@ -26,27 +28,23 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase
protected $application;
/**
* @var \Symfony\Component\Console\Helper\DialogHelper|\PHPUnit_Framework_MockObject_MockObject
* @var \Symfony\Component\Console\Helper\QuestionHelper|\PHPUnit_Framework_MockObject_MockObject
*/
protected $dialog;
protected $helper;
public function setup()
public function setUp()
{
parent::setup();
parent::setUp();
$this->command = $this->getMockBuilder('PHPCensor\\Command\\CreateAdminCommand')
->setConstructorArgs([$this->getMock('PHPCensor\\Store\\UserStore')])
->setMethods(['reloadConfig'])
$userStoreMock = $this->getMock('PHPCensor\\Store\\UserStore');
$this->command = new CreateAdminCommand($userStoreMock);
$this->helper = $this
->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')
->setMethods(['ask'])
->getMock();
$this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
->setMethods([
'ask',
'askAndValidate',
'askHiddenResponse',
])->getMock()
;
$this->application = new Application();
}
@ -55,19 +53,18 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase
*/
protected function getCommandTester()
{
$this->application->getHelperSet()->set($this->dialog, 'dialog');
$this->application->getHelperSet()->set($this->helper, 'question');
$this->application->add($this->command);
$command = $this->application->find('php-censor:create-admin');
$commandTester = new CommandTester($command);
$commandTester = new CommandTester($this->command);
return $commandTester;
}
public function testExecute()
{
$this->dialog->expects($this->at(0))->method('askAndValidate')->will($this->returnValue('test@example.com'));
$this->dialog->expects($this->at(1))->method('ask')->will($this->returnValue('A name'));
$this->dialog->expects($this->at(2))->method('askHiddenResponse')->will($this->returnValue('foobar123'));
$this->helper->expects($this->at(0))->method('ask')->will($this->returnValue('test@example.com'));
$this->helper->expects($this->at(1))->method('ask')->will($this->returnValue('A name'));
$this->helper->expects($this->at(2))->method('ask')->will($this->returnValue('foobar123'));
$commandTester = $this->getCommandTester();
$commandTester->execute([]);

View file

@ -9,6 +9,7 @@
namespace Tests\PHPCensor\Command;
use PHPCensor\Command\CreateBuildCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
@ -24,9 +25,9 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
*/
protected $application;
public function setup()
public function setUp()
{
parent::setup();
parent::setUp();
$projectMock = $this->getMock('PHPCensor\\Model\\Project');
@ -41,6 +42,7 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
$buildServiceMock = $this->getMockBuilder('PHPCensor\\Service\\BuildService')
->disableOriginalConstructor()
->getMock();
$buildServiceMock->method('createBuild')
->withConsecutive(
[$projectMock, null, null, null, null, null],
@ -48,10 +50,7 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
[$projectMock, null, 'master', null, null, null]
);
$this->command = $this->getMockBuilder('PHPCensor\\Command\\CreateBuildCommand')
->setConstructorArgs([$projectStoreMock, $buildServiceMock])
->setMethods(['reloadConfig'])
->getMock();
$this->command = new CreateBuildCommand($projectStoreMock, $buildServiceMock);
$this->application = new Application();
}

View file

@ -18,36 +18,34 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
{
public $config;
public $admin;
/**
* @var Application
*/
protected $application;
public function setup()
public function setUp()
{
parent::setup();
parent::setUp();
$this->application = new Application();
$this->application->setHelperSet(new HelperSet());
}
/**
* @return \PHPUnit_Framework_MockObject_MockBuilder
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getDialogHelperMock()
protected function getHelperMock()
{
// We check that there's no interaction with user.
$dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
->setMethods([
'ask',
'askConfirmation',
'askAndValidate',
'askHiddenResponse',
'askHiddenResponseAndValidate',
])->getMock();
return $dialog;
return $this
->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')
->setMethods(['ask'])
->getMock();
}
/**
* @return \PHPUnit_Framework_MockObject_MockBuilder
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getInstallCommandMock()
{
@ -84,9 +82,9 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
return $command;
}
protected function getCommandTester($dialog)
protected function getCommandTester($helper)
{
$this->application->getHelperSet()->set($dialog, 'dialog');
$this->application->getHelperSet()->set($helper, 'question');
$this->application->add($this->getInstallCommandMock());
$command = $this->application->find('php-censor:install');
$commandTester = new CommandTester($command);
@ -98,6 +96,7 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
{
$config = [
'--db-host' => 'localhost',
'--db-port' => '3306',
'--db-name' => 'php-censor-db',
'--db-user' => 'php-censor-user',
'--db-pass' => 'php-censor-password',
@ -129,26 +128,18 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testAutomaticInstallation()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
$dialog->expects($this->never())->method('ask');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$this->executeWithoutParam(null, $dialog);
}
public function testDatabaseHostnameConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$this->executeWithoutParam('--db-host', $dialog);
@ -159,14 +150,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testDatabaseNameConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$this->executeWithoutParam('--db-name', $dialog);
@ -176,14 +163,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testDatabaseUserConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$this->executeWithoutParam('--db-user', $dialog);
@ -193,14 +176,9 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testDatabasePasswordConfig()
{
$dialog = $this->getDialogHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->never())->method('ask');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->once())->method('askHiddenResponse')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$dialog = $this->getHelperMock();
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$this->executeWithoutParam('--db-pass', $dialog);
@ -210,14 +188,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testUrlConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->never())->method('ask');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->once())->method('askAndValidate')->willReturn('http://testedvalue.com');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$dialog->expects($this->once())->method('ask')->willReturn('http://testedvalue.com');
$this->executeWithoutParam('--url', $dialog);
@ -227,14 +201,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testAdminEmailConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->never())->method('ask');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->once())->method('askAndValidate')->willReturn('admin@php-censor.local');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$dialog->expects($this->once())->method('ask')->willReturn('admin@php-censor.local');
$this->executeWithoutParam('--admin-mail', $dialog);
@ -244,14 +214,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testAdminNameConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// Define expectation for dialog.
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->never())->method('askHiddenResponse');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$this->executeWithoutParam('--admin-name', $dialog);
@ -261,14 +227,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
public function testAdminPasswordConfig()
{
$dialog = $this->getDialogHelperMock();
$dialog = $this->getHelperMock();
// We specified an input value for hostname.
$dialog->expects($this->never())->method('ask');
$dialog->expects($this->never())->method('askConfirmation');
$dialog->expects($this->never())->method('askAndValidate');
$dialog->expects($this->once())->method('askHiddenResponse')->willReturn('testedvalue');
$dialog->expects($this->never())->method('askHiddenResponseAndValidate');
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
$this->executeWithoutParam('--admin-pass', $dialog);

View file

@ -30,7 +30,7 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase
$config = [
'smtp_address' => 'mail.example.com',
'smtp_port' => 225,
'smtp_encryption' => true,
'smtp_encryption' => 'tls',
'smtp_username' => 'php-censor-user',
'smtp_password' => 'php-censor-password',
'default_mailto_address' => 'admin@php-censor.local',
@ -54,7 +54,7 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase
$config = [
'smtp_address' => 'mail.example.com',
'smtp_port' => 225,
'smtp_encryption' => true,
'smtp_encryption' => 'tls',
'smtp_username' => 'php-censor-user',
'smtp_password' => 'php-censor-password',
'default_mailto_address' => 'admin@php-censor.local',

View file

@ -10,6 +10,7 @@
namespace Tests\PHPCensor\Plugin;
use b8\Config;
use PHPCensor\Plugin\Email as EmailPlugin;
use PHPCensor\Model\Build;
@ -61,6 +62,14 @@ class EmailTest extends \PHPUnit_Framework_TestCase
$this->mailDelivered = true;
$self = $this;
$config = new Config([
'b8' => [
'view' => [
'path' => SRC_DIR . 'View/'
]
]
]);
$this->mockProject = $this->getMock(
'\PHPCensor\Model\Project',
['getTitle'],
@ -104,7 +113,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase
[
'getSystemConfig',
'getBuild',
'log'
'log',
'logDebug'
],
[],
"mockBuilder_email",
@ -119,7 +129,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(['email_settings' => ['from_address' => "test-from-address@example.com"]]));
}
protected function loadEmailPluginWithOptions($arrOptions = [], $buildStatus = null, $mailDelivered = true)
protected function loadEmailPluginWithOptions($arrOptions = [], $buildStatus = null, $mailDelivered = 1)
{
$this->mailDelivered = $mailDelivered;
@ -147,10 +157,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase
$this->testedEmailPlugin->expects($this->any())
->method('sendEmail')
->will($this->returnCallback(function ($to, $cc, $subject, $body) use ($self) {
$self->message['to'][] = $to;
$self->message['cc'] = $cc;
$self->message['to'][] = $to;
$self->message['cc'] = $cc;
$self->message['subject'] = $subject;
$self->message['body'] = $body;
$self->message['body'] = $body;
return $self->mailDelivered;
}));
@ -356,7 +366,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
'addresses' => ['test-receiver@example.com']
],
Build::STATUS_FAILED,
true
1
);
$returnValue = $this->testedEmailPlugin->execute();
@ -374,7 +384,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
'addresses' => ['test-receiver@example.com']
],
Build::STATUS_FAILED,
false
0
);
$returnValue = $this->testedEmailPlugin->execute();

View file

@ -39,7 +39,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
protected function buildTemp()
{
$directory = tempnam(ROOT_DIR . 'tests' . DIRECTORY_SEPARATOR . 'PHPCensor' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR, 'source');
$directory = tempnam(ROOT_DIR . 'tests' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR, 'source');
unlink($directory);
return $directory;
}
@ -95,13 +95,13 @@ class PharTest extends \PHPUnit_Framework_TestCase
$plugin = $this->getPlugin();
$this->assertInstanceOf('PHPCensor\Plugin', $plugin);
$this->assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild());
$this->assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder());
$this->assertInstanceOf('PHPCensor\Builder', $plugin->getPHPCI());
}
public function testDirectory()
{
$plugin = $this->getPlugin();
$plugin->getBuilder()->buildPath = 'foo';
$plugin->getPHPCI()->buildPath = 'foo';
$this->assertEquals('foo', $plugin->getDirectory());
$plugin = $this->getPlugin(['directory' => 'dirname']);
@ -141,7 +141,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
$plugin = $this->getPlugin();
$path = $this->buildSource();
$plugin->getBuilder()->buildPath = $path;
$plugin->getPHPCI()->buildPath = $path;
$this->assertTrue($plugin->execute());
@ -159,7 +159,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
$plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']);
$path = $this->buildSource();
$plugin->getBuilder()->buildPath = $path;
$plugin->getPHPCI()->buildPath = $path;
$this->assertTrue($plugin->execute());
@ -185,7 +185,7 @@ STUB;
file_put_contents($path . '/stub.php', $content);
$plugin = $this->getPlugin(['stub' => 'stub.php']);
$plugin->getBuilder()->buildPath = $path;
$plugin->getPHPCI()->buildPath = $path;
$this->assertTrue($plugin->execute());
@ -201,7 +201,7 @@ STUB;
$directory = $this->buildTemp();
$plugin = $this->getPlugin(['directory' => $directory]);
$plugin->getBuilder()->buildPath = $this->buildSource();
$plugin->getPHPCI()->buildPath = $this->buildSource();
$this->assertFalse($plugin->execute());
}

View file

@ -98,7 +98,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase
public function testExecutePlugin_LogsFailureForNonExistentClasses()
{
$options = [];
$options = [];
$pluginName = 'DOESNTEXIST';
$this->mockBuildLogger->logFailure('Plugin does not exist: ' . $pluginName)->shouldBeCalledTimes(1);
@ -108,7 +108,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase
public function testExecutePlugin_LogsFailureWhenExceptionsAreThrownByPlugin()
{
$options = [];
$options = [];
$pluginName = 'PhpUnit';
$expectedException = new \RuntimeException("Generic Error");

View file

@ -77,6 +77,21 @@ TAP version 13
Generating code coverage report in HTML format ... done
TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals([], $result);
}
public function testTapCoverageXdebug()
{
$content = <<<TAP
TAP version 13
Warning: The Xdebug extension is not loaded
No code coverage will be generated.
TAP;
$parser = new TapParser($content);
$result = $parser->parse();

View file

@ -7,7 +7,7 @@ namespace Tests\PHPCensor\ProcessControl;
abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
{
/**
* @var type
* @var resource
*/
protected $process;
@ -31,13 +31,13 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
$this->pipes = [];
$this->process = proc_open($this->getTestCommand(), $desc, $this->pipes);
usleep(500);
sleep(1);
$this->assertTrue(is_resource($this->process));
$this->assertTrue($this->isRunning());
$status = proc_get_status($this->process);
return $status['pid'];
return (integer)$status['pid'];
}
/** End the running process.
@ -65,7 +65,7 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
return false;
}
$status = proc_get_status($this->process);
return $status['running'];
return (boolean)$status['running'];
}
public function testIsRunning()
@ -94,10 +94,10 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
$pid = $this->startProcess();
$this->object->kill($pid);
usleep(500);
self::assertTrue($this->object->kill($pid));
sleep(1);
$this->assertFalse($this->isRunning());
self::assertFalse($this->isRunning());
}
public function testForcefullyKill()
@ -109,9 +109,9 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
$pid = $this->startProcess();
$this->object->kill($pid, true);
usleep(500);
sleep(1);
$this->assertFalse($this->isRunning());
self::assertFalse($this->isRunning());
}
abstract public function testIsAvailable();

View file

@ -7,7 +7,7 @@ class WindowsProcessControlTest extends ProcessControlTest
{
protected function setUp()
{
$this->object = new WindowsProcessControl;
$this->object = new WindowsProcessControl();
}
public function getTestCommand()

View file

@ -66,4 +66,4 @@ if (!defined('IS_CONSOLE')) {
define('IS_CONSOLE', false);
}
\PHPCensor\Helper\Lang::init($config);
\PHPCensor\Helper\Lang::init($config, 'en');