Repaired tests + refactored code for tests
This commit is contained in:
parent
b327ad8083
commit
9de4fb51d3
14
README.md
14
README.md
|
@ -21,13 +21,25 @@ What it doesn't do (yet)
|
||||||
* Virtualised testing.
|
* Virtualised testing.
|
||||||
* Multiple PHP-version tests.
|
* Multiple PHP-version tests.
|
||||||
* Install PEAR or PECL extensions.
|
* Install PEAR or PECL extensions.
|
||||||
* Deployments - We strongly recommend using [Deployer](http://phpdeployment.org)
|
* Deployments
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
=============
|
=============
|
||||||
|
|
||||||
[PHP Censor documentation](docs/README.md)
|
[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
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ b8:
|
||||||
servers:
|
servers:
|
||||||
read: localhost
|
read: localhost
|
||||||
write: localhost
|
write: localhost
|
||||||
name: php-censor-db
|
port: 3306
|
||||||
|
name: php-censor-db
|
||||||
username: php-censor-user
|
username: php-censor-user
|
||||||
password: php-censor-password
|
password: php-censor-password
|
||||||
php-censor:
|
php-censor:
|
||||||
|
|
23
phpunit.xml
23
phpunit.xml
|
@ -12,15 +12,16 @@
|
||||||
bootstrap="./tests/bootstrap.php"
|
bootstrap="./tests/bootstrap.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<!--<testsuite name="PHP Censor Command Test Suite">
|
<testsuite name="B8Framework Test Suite">
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Command</directory>
|
<directory suffix="Test.php">./tests/B8Framework</directory>
|
||||||
</testsuite>-->
|
|
||||||
<testsuite name="PHP Censor Controller Test Suite">
|
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Controller</directory>
|
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|
||||||
<testsuite name="PHP Censor Helper Test Suite">
|
<testsuite name="PHP Censor Helper Test Suite">
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Helper</directory>
|
<directory suffix="Test.php">./tests/PHPCensor/Helper</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
<testsuite name="PHP Censor Controller Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests/PHPCensor/Controller</directory>
|
||||||
|
</testsuite>
|
||||||
<testsuite name="PHP Censor Logging Test Suite">
|
<testsuite name="PHP Censor Logging Test Suite">
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Logging</directory>
|
<directory suffix="Test.php">./tests/PHPCensor/Logging</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
@ -30,14 +31,14 @@
|
||||||
<testsuite name="PHP Censor Plugin Test Suite">
|
<testsuite name="PHP Censor Plugin Test Suite">
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Plugin</directory>
|
<directory suffix="Test.php">./tests/PHPCensor/Plugin</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<!--<testsuite name="PHP Censor ProcessControl Test Suite">
|
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
|
|
||||||
</testsuite>-->
|
|
||||||
<testsuite name="PHP Censor Service Test Suite">
|
<testsuite name="PHP Censor Service Test Suite">
|
||||||
<directory suffix="Test.php">./tests/PHPCensor/Service</directory>
|
<directory suffix="Test.php">./tests/PHPCensor/Service</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<!--<testsuite name="B8Framework Test Suite">
|
<testsuite name="PHP Censor Command Test Suite">
|
||||||
<directory suffix="Test.php">./tests/B8Framework</directory>
|
<directory suffix="Test.php">./tests/PHPCensor/Command</directory>
|
||||||
</testsuite>-->
|
</testsuite>
|
||||||
|
<testsuite name="PHP Censor ProcessControl Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
|
||||||
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -10,52 +10,16 @@ class Database extends \PDO
|
||||||
protected static $details = [];
|
protected static $details = [];
|
||||||
protected static $lastUsed = ['read' => null, 'write' => null];
|
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()
|
protected static function init()
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$settings = $config->get('b8.database', []);
|
$settings = $config->get('b8.database', []);
|
||||||
self::$servers['read'] = $settings['servers']['read'];
|
|
||||||
|
self::$servers['read'] = $settings['servers']['read'];
|
||||||
self::$servers['write'] = $settings['servers']['write'];
|
self::$servers['write'] = $settings['servers']['write'];
|
||||||
self::$details['db'] = $settings['name'];
|
self::$details['db'] = $settings['name'];
|
||||||
self::$details['user'] = $settings['username'];
|
self::$details['user'] = $settings['username'];
|
||||||
self::$details['pass'] = $settings['password'];
|
self::$details['pass'] = $settings['password'];
|
||||||
self::$initialised = true;
|
self::$initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +27,7 @@ class Database extends \PDO
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*
|
*
|
||||||
* @return \b8\Database
|
* @return \b8\Database
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getConnection($type = 'read')
|
public static function getConnection($type = 'read')
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -97,11 +97,11 @@ abstract class Element
|
||||||
$view = new View($viewFile, B8_PATH . 'Form/View/');
|
$view = new View($viewFile, B8_PATH . 'Form/View/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->name = $this->getName();
|
$view->name = $this->getName();
|
||||||
$view->id = $this->getId();
|
$view->id = $this->getId();
|
||||||
$view->label = $this->getLabel();
|
$view->label = $this->getLabel();
|
||||||
$view->css = $this->getClass();
|
$view->css = $this->getClass();
|
||||||
$view->ccss = $this->getContainerClass();
|
$view->ccss = $this->getContainerClass();
|
||||||
$view->parent = $this->_parent;
|
$view->parent = $this->_parent;
|
||||||
|
|
||||||
$this->_onPreRender($view);
|
$this->_onPreRender($view);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace b8;
|
namespace b8;
|
||||||
|
|
||||||
use b8\Exception\HttpException;
|
class ViewRuntimeException extends \RuntimeException {}
|
||||||
|
|
||||||
class View
|
class View
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ class View
|
||||||
public function __construct($file, $path = null)
|
public function __construct($file, $path = null)
|
||||||
{
|
{
|
||||||
if (!self::exists($file, $path)) {
|
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);
|
$this->viewFile = self::getViewFile($file, $path);
|
||||||
|
@ -61,7 +61,7 @@ class View
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($class)) {
|
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();
|
self::$_helpers[$method] = new $class();
|
||||||
|
|
|
@ -20,9 +20,10 @@ use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create admin command - creates an admin user
|
* Create admin command - creates an admin user
|
||||||
* @author Wogan May (@woganmay)
|
*
|
||||||
* @package PHPCI
|
* @author Wogan May (@woganmay)
|
||||||
* @subpackage Console
|
* @package PHPCI
|
||||||
|
* @subpackage Console
|
||||||
*/
|
*/
|
||||||
class CreateAdminCommand extends Command
|
class CreateAdminCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 string $binary
|
||||||
* @param bool $quiet
|
* @param bool $quiet
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function findBinary($binary, $quiet = false)
|
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)) {
|
if (is_dir($composerBin) && is_file($composerBin . DIRECTORY_SEPARATOR . $bin)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
||||||
|
|
||||||
return $composerBin . DIRECTORY_SEPARATOR . $bin;
|
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);
|
$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)) {
|
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);
|
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
|
||||||
|
|
||||||
return $this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;
|
return $this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
$findCmdResult = $this->findGlobalBinary($bin);
|
$findCmdResult = $this->findGlobalBinary($bin);
|
||||||
if (is_file($findCmdResult)) {
|
if (is_file($findCmdResult)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
|
||||||
|
|
||||||
return $findCmdResult;
|
return $findCmdResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,6 +193,7 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
||||||
if ($quiet) {
|
if ($quiet) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
|
throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ class Email
|
||||||
*
|
*
|
||||||
* @param Builder $builder
|
* @param Builder $builder
|
||||||
*
|
*
|
||||||
* @return bool|int
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function send(Builder $builder)
|
public function send(Builder $builder)
|
||||||
{
|
{
|
||||||
|
@ -110,9 +110,9 @@ class Email
|
||||||
$builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
|
$builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
|
||||||
|
|
||||||
if (empty($smtpServer)) {
|
if (empty($smtpServer)) {
|
||||||
return $this->sendViaMail();
|
return (integer)$this->sendViaMail();
|
||||||
} else {
|
} else {
|
||||||
return $this->sendViaSwiftMailer();
|
return (integer)$this->sendViaSwiftMailer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ class Email
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the email using SwiftMailer.
|
* Sends the email using SwiftMailer.
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function sendViaSwiftMailer()
|
protected function sendViaSwiftMailer()
|
||||||
|
|
|
@ -125,12 +125,17 @@ class Lang
|
||||||
* Initialise the Language helper, try load the language file for the user's browser or the configured default.
|
* Initialise the Language helper, try load the language file for the user's browser or the configured default.
|
||||||
*
|
*
|
||||||
* @param Config $config
|
* @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::$en_strings = self::loadLanguage('en');
|
||||||
self::loadAvailableLanguages();
|
self::loadAvailableLanguages();
|
||||||
|
|
||||||
|
if ($language_force && self::setLanguage($language_force)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Try cookies first:
|
// Try cookies first:
|
||||||
if (isset($_COOKIE) && array_key_exists('php-censor-language', $_COOKIE) && self::setLanguage($_COOKIE['php-censor-language'])) {
|
if (isset($_COOKIE) && array_key_exists('php-censor-language', $_COOKIE) && self::setLanguage($_COOKIE['php-censor-language'])) {
|
||||||
return;
|
return;
|
||||||
|
@ -141,7 +146,7 @@ class Lang
|
||||||
$langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
|
||||||
foreach ($langs as $lang) {
|
foreach ($langs as $lang) {
|
||||||
$parts = explode(';', $lang);
|
$parts = explode(';', $lang);
|
||||||
$language = strtolower($parts[0]);
|
$language = strtolower($parts[0]);
|
||||||
|
|
||||||
if (self::setLanguage($language)) {
|
if (self::setLanguage($language)) {
|
||||||
|
|
|
@ -184,10 +184,10 @@ class BuildBase extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Id / id.
|
* Get the value of Id / id.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['id'];
|
$rtn = $this->data['id'];
|
||||||
|
@ -196,10 +196,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of ProjectId / project_id.
|
* Get the value of ProjectId / project_id.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getProjectId()
|
public function getProjectId()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['project_id'];
|
$rtn = $this->data['project_id'];
|
||||||
|
@ -208,10 +208,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of CommitId / commit_id.
|
* Get the value of CommitId / commit_id.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCommitId()
|
public function getCommitId()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['commit_id'];
|
$rtn = $this->data['commit_id'];
|
||||||
|
@ -220,10 +220,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Status / status.
|
* Get the value of Status / status.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getStatus()
|
public function getStatus()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['status'];
|
$rtn = $this->data['status'];
|
||||||
|
@ -232,10 +232,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Log / log.
|
* Get the value of Log / log.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLog()
|
public function getLog()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['log'];
|
$rtn = $this->data['log'];
|
||||||
|
@ -244,10 +244,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Branch / branch.
|
* Get the value of Branch / branch.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBranch()
|
public function getBranch()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['branch'];
|
$rtn = $this->data['branch'];
|
||||||
|
@ -256,10 +256,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Created / created.
|
* Get the value of Created / created.
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getCreated()
|
public function getCreated()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['created'];
|
$rtn = $this->data['created'];
|
||||||
|
@ -272,10 +272,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Started / started.
|
* Get the value of Started / started.
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getStarted()
|
public function getStarted()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['started'];
|
$rtn = $this->data['started'];
|
||||||
|
@ -288,10 +288,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Finished / finished.
|
* Get the value of Finished / finished.
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getFinished()
|
public function getFinished()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['finished'];
|
$rtn = $this->data['finished'];
|
||||||
|
@ -304,10 +304,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of CommitterEmail / committer_email.
|
* Get the value of CommitterEmail / committer_email.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCommitterEmail()
|
public function getCommitterEmail()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['committer_email'];
|
$rtn = $this->data['committer_email'];
|
||||||
|
@ -316,10 +316,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of CommitMessage / commit_message.
|
* Get the value of CommitMessage / commit_message.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCommitMessage()
|
public function getCommitMessage()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['commit_message'];
|
$rtn = $this->data['commit_message'];
|
||||||
|
@ -328,10 +328,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of Extra / extra.
|
* Get the value of Extra / extra.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getExtra()
|
public function getExtra()
|
||||||
{
|
{
|
||||||
$rtn = $this->data['extra'];
|
$rtn = $this->data['extra'];
|
||||||
|
@ -340,11 +340,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Id / id.
|
* Set the value of Id / id. Must not be null.
|
||||||
*
|
*
|
||||||
* Must not be null.
|
* @param $value int
|
||||||
* @param $value int
|
*/
|
||||||
*/
|
|
||||||
public function setId($value)
|
public function setId($value)
|
||||||
{
|
{
|
||||||
$this->_validateNotNull('Id', $value);
|
$this->_validateNotNull('Id', $value);
|
||||||
|
@ -360,11 +359,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of ProjectId / project_id.
|
* Set the value of ProjectId / project_id. Must not be null.
|
||||||
*
|
*
|
||||||
* Must not be null.
|
* @param $value int
|
||||||
* @param $value int
|
*/
|
||||||
*/
|
|
||||||
public function setProjectId($value)
|
public function setProjectId($value)
|
||||||
{
|
{
|
||||||
$this->_validateNotNull('ProjectId', $value);
|
$this->_validateNotNull('ProjectId', $value);
|
||||||
|
@ -380,11 +378,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of CommitId / commit_id.
|
* Set the value of CommitId / commit_id. Must not be null.
|
||||||
*
|
*
|
||||||
* Must not be null.
|
* @param $value string
|
||||||
* @param $value string
|
*/
|
||||||
*/
|
|
||||||
public function setCommitId($value)
|
public function setCommitId($value)
|
||||||
{
|
{
|
||||||
$this->_validateNotNull('CommitId', $value);
|
$this->_validateNotNull('CommitId', $value);
|
||||||
|
@ -400,11 +397,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Status / status.
|
* Set the value of Status / status. Must not be null.
|
||||||
*
|
*
|
||||||
* Must not be null.
|
* @param $value int
|
||||||
* @param $value int
|
*/
|
||||||
*/
|
|
||||||
public function setStatus($value)
|
public function setStatus($value)
|
||||||
{
|
{
|
||||||
$this->_validateNotNull('Status', $value);
|
$this->_validateNotNull('Status', $value);
|
||||||
|
@ -420,10 +416,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Log / log.
|
* Set the value of Log / log.
|
||||||
*
|
*
|
||||||
* @param $value string
|
* @param $value string
|
||||||
*/
|
*/
|
||||||
public function setLog($value)
|
public function setLog($value)
|
||||||
{
|
{
|
||||||
$this->_validateString('Log', $value);
|
$this->_validateString('Log', $value);
|
||||||
|
@ -438,11 +434,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Branch / branch.
|
* Set the value of Branch / branch. Must not be null.
|
||||||
*
|
*
|
||||||
* Must not be null.
|
* @param $value string
|
||||||
* @param $value string
|
*/
|
||||||
*/
|
|
||||||
public function setBranch($value)
|
public function setBranch($value)
|
||||||
{
|
{
|
||||||
$this->_validateNotNull('Branch', $value);
|
$this->_validateNotNull('Branch', $value);
|
||||||
|
@ -458,10 +453,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Created / created.
|
* Set the value of Created / created.
|
||||||
*
|
*
|
||||||
* @param $value \DateTime
|
* @param $value \DateTime
|
||||||
*/
|
*/
|
||||||
public function setCreated($value)
|
public function setCreated($value)
|
||||||
{
|
{
|
||||||
$this->_validateDate('Created', $value);
|
$this->_validateDate('Created', $value);
|
||||||
|
@ -476,10 +471,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Started / started.
|
* Set the value of Started / started.
|
||||||
*
|
*
|
||||||
* @param $value \DateTime
|
* @param $value \DateTime
|
||||||
*/
|
*/
|
||||||
public function setStarted($value)
|
public function setStarted($value)
|
||||||
{
|
{
|
||||||
$this->_validateDate('Started', $value);
|
$this->_validateDate('Started', $value);
|
||||||
|
@ -494,10 +489,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Finished / finished.
|
* Set the value of Finished / finished.
|
||||||
*
|
*
|
||||||
* @param $value \DateTime
|
* @param $value \DateTime
|
||||||
*/
|
*/
|
||||||
public function setFinished($value)
|
public function setFinished($value)
|
||||||
{
|
{
|
||||||
$this->_validateDate('Finished', $value);
|
$this->_validateDate('Finished', $value);
|
||||||
|
@ -512,10 +507,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of CommitterEmail / committer_email.
|
* Set the value of CommitterEmail / committer_email.
|
||||||
*
|
*
|
||||||
* @param $value string
|
* @param $value string
|
||||||
*/
|
*/
|
||||||
public function setCommitterEmail($value)
|
public function setCommitterEmail($value)
|
||||||
{
|
{
|
||||||
$this->_validateString('CommitterEmail', $value);
|
$this->_validateString('CommitterEmail', $value);
|
||||||
|
@ -530,10 +525,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of CommitMessage / commit_message.
|
* Set the value of CommitMessage / commit_message.
|
||||||
*
|
*
|
||||||
* @param $value string
|
* @param $value string
|
||||||
*/
|
*/
|
||||||
public function setCommitMessage($value)
|
public function setCommitMessage($value)
|
||||||
{
|
{
|
||||||
$this->_validateString('CommitMessage', $value);
|
$this->_validateString('CommitMessage', $value);
|
||||||
|
@ -548,10 +543,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of Extra / extra.
|
* Set the value of Extra / extra.
|
||||||
*
|
*
|
||||||
* @param $value string
|
* @param $value string
|
||||||
*/
|
*/
|
||||||
public function setExtra($value)
|
public function setExtra($value)
|
||||||
{
|
{
|
||||||
$this->_validateString('Extra', $value);
|
$this->_validateString('Extra', $value);
|
||||||
|
@ -568,8 +563,6 @@ class BuildBase extends Model
|
||||||
/**
|
/**
|
||||||
* Get the Project model for this Build by Id.
|
* Get the Project model for this Build by Id.
|
||||||
*
|
*
|
||||||
* @uses \PHPCensor\Store\ProjectStore::getById()
|
|
||||||
* @uses \PHPCensor\Model\Project
|
|
||||||
* @return \PHPCensor\Model\Project
|
* @return \PHPCensor\Model\Project
|
||||||
*/
|
*/
|
||||||
public function getProject()
|
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.
|
* Set Project - Accepts an ID, an array representing a Project or a Project model.
|
||||||
*
|
*
|
||||||
* @param $value mixed
|
* @param $value mixed
|
||||||
*/
|
*/
|
||||||
public function setProject($value)
|
public function setProject($value)
|
||||||
{
|
{
|
||||||
// Is this an instance of Project?
|
// Is this an instance of Project?
|
||||||
|
@ -613,10 +606,10 @@ class BuildBase extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Project - Accepts a Project model.
|
* Set Project - Accepts a Project model.
|
||||||
*
|
*
|
||||||
* @param $value Project
|
* @param $value Project
|
||||||
*/
|
*/
|
||||||
public function setProjectObject(Project $value)
|
public function setProjectObject(Project $value)
|
||||||
{
|
{
|
||||||
return $this->setProjectId($value->getId());
|
return $this->setProjectId($value->getId());
|
||||||
|
@ -625,8 +618,6 @@ class BuildBase extends Model
|
||||||
/**
|
/**
|
||||||
* Get BuildError models by BuildId for this Build.
|
* Get BuildError models by BuildId for this Build.
|
||||||
*
|
*
|
||||||
* @uses \PHPCensor\Store\BuildErrorStore::getByBuildId()
|
|
||||||
* @uses \PHPCensor\Model\BuildError
|
|
||||||
* @return \PHPCensor\Model\BuildError[]
|
* @return \PHPCensor\Model\BuildError[]
|
||||||
*/
|
*/
|
||||||
public function getBuildBuildErrors()
|
public function getBuildBuildErrors()
|
||||||
|
@ -637,8 +628,6 @@ class BuildBase extends Model
|
||||||
/**
|
/**
|
||||||
* Get BuildMeta models by BuildId for this Build.
|
* Get BuildMeta models by BuildId for this Build.
|
||||||
*
|
*
|
||||||
* @uses \PHPCensor\Store\BuildMetaStore::getByBuildId()
|
|
||||||
* @uses \PHPCensor\Model\BuildMeta
|
|
||||||
* @return \PHPCensor\Model\BuildMeta[]
|
* @return \PHPCensor\Model\BuildMeta[]
|
||||||
*/
|
*/
|
||||||
public function getBuildBuildMetas()
|
public function getBuildBuildMetas()
|
||||||
|
|
|
@ -15,18 +15,16 @@ use PHPCensor\Builder;
|
||||||
use Symfony\Component\Yaml\Parser as YamlParser;
|
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build Model
|
* Build Model
|
||||||
* @uses PHPCensor\Model\Base\BuildBase
|
*
|
||||||
* @author Dan Cryer <dan@block8.co.uk>
|
* @author Dan Cryer <dan@block8.co.uk>
|
||||||
* @package PHPCI
|
*/
|
||||||
* @subpackage Core
|
|
||||||
*/
|
|
||||||
class Build extends BuildBase
|
class Build extends BuildBase
|
||||||
{
|
{
|
||||||
const STATUS_NEW = 0;
|
const STATUS_NEW = 0;
|
||||||
const STATUS_RUNNING = 1;
|
const STATUS_RUNNING = 1;
|
||||||
const STATUS_SUCCESS = 2;
|
const STATUS_SUCCESS = 2;
|
||||||
const STATUS_FAILED = 3;
|
const STATUS_FAILED = 3;
|
||||||
|
|
||||||
public $currentBuildPath;
|
public $currentBuildPath;
|
||||||
|
|
||||||
|
@ -48,6 +46,7 @@ class Build extends BuildBase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a template to use to generate a link to a specific file.
|
* Return a template to use to generate a link to a specific file.
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function getFileLinkTemplate()
|
public function getFileLinkTemplate()
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
namespace PHPCensor\Plugin;
|
namespace PHPCensor\Plugin;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
|
use b8\ViewRuntimeException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use b8\View;
|
use b8\View;
|
||||||
use PHPCensor\Builder;
|
use PHPCensor\Builder;
|
||||||
|
@ -58,6 +60,8 @@ class Email implements Plugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a notification mail.
|
* Send a notification mail.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
|
@ -72,15 +76,7 @@ class Email implements Plugin
|
||||||
$buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
|
$buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
|
||||||
$projectName = $this->build->getProject()->getTitle();
|
$projectName = $this->build->getProject()->getTitle();
|
||||||
|
|
||||||
try {
|
$view = $this->getMailTemplate();
|
||||||
$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->build = $this->build;
|
$view->build = $this->build;
|
||||||
$view->project = $this->build->getProject();
|
$view->project = $this->build->getProject();
|
||||||
|
@ -109,7 +105,8 @@ class Email implements Plugin
|
||||||
* @param string[] $ccList
|
* @param string[] $ccList
|
||||||
* @param string $subject Email subject
|
* @param string $subject Email subject
|
||||||
* @param string $body Email body
|
* @param string $body Email body
|
||||||
* @return array Array of failed addresses
|
*
|
||||||
|
* @return integer
|
||||||
*/
|
*/
|
||||||
protected function sendEmail($toAddress, $ccList, $subject, $body)
|
protected function sendEmail($toAddress, $ccList, $subject, $body)
|
||||||
{
|
{
|
||||||
|
@ -224,8 +221,17 @@ class Email implements Plugin
|
||||||
*/
|
*/
|
||||||
protected function getMailTemplate()
|
protected function getMailTemplate()
|
||||||
{
|
{
|
||||||
if (isset($this->options['template'])) {
|
try {
|
||||||
return new View('Email/' . $this->options['template']);
|
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();
|
return $this->getDefaultMailTemplate();
|
||||||
|
|
|
@ -50,18 +50,13 @@ class PhpCpd implements Plugin
|
||||||
$this->phpci = $phpci;
|
$this->phpci = $phpci;
|
||||||
$this->build = $build;
|
$this->build = $build;
|
||||||
|
|
||||||
$this->path = $phpci->buildPath;
|
$this->path = $phpci->buildPath;
|
||||||
$this->standard = 'PSR1';
|
|
||||||
$this->ignore = $phpci->ignore;
|
$this->ignore = $phpci->ignore;
|
||||||
|
|
||||||
if (!empty($options['path'])) {
|
if (!empty($options['path'])) {
|
||||||
$this->path = $phpci->buildPath . $options['path'];
|
$this->path = $phpci->buildPath . $options['path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['standard'])) {
|
|
||||||
$this->standard = $options['standard'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($options['ignore'])) {
|
if (!empty($options['ignore'])) {
|
||||||
$this->ignore = $options['ignore'];
|
$this->ignore = $options['ignore'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_LINE_PATTERN = '/^(ok|not ok)(?:\s+\d+)?(?:\s+\-)?\s*(.*?)(?:\s*#\s*(skip|todo)\s*(.*))?\s*$/i';
|
||||||
const TEST_YAML_START = '/^(\s*)---/';
|
const TEST_YAML_START = '/^(\s*)---/';
|
||||||
const TEST_DIAGNOSTIC = '/^#/';
|
const TEST_DIAGNOSTIC = '/^#/';
|
||||||
const TEST_COVERAGE = '/^Generating/';
|
const TEST_COVERAGE = '/(Generating code coverage|The Xdebug extension is not loaded|No code coverage)/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
|
@ -28,14 +28,11 @@ class PosixProcessControl implements ProcessControlInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a TERMINATE or KILL signal to the process using posix_kill.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param int $pid
|
|
||||||
* @param bool $forcefully Whether to send TERMINATE (false) or KILL (true).
|
|
||||||
*/
|
*/
|
||||||
public function kill($pid, $forcefully = false)
|
public function kill($pid, $forcefully = false)
|
||||||
{
|
{
|
||||||
posix_kill($pid, $forcefully ? 9 : 15);
|
return posix_kill($pid, $forcefully ? 9 : 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,8 @@ namespace PHPCensor\ProcessControl;
|
||||||
*/
|
*/
|
||||||
interface ProcessControlInterface
|
interface ProcessControlInterface
|
||||||
{
|
{
|
||||||
/** Checks if a process exists.
|
/**
|
||||||
|
* Checks if a process exists.
|
||||||
*
|
*
|
||||||
* @param int $pid The process identifier.
|
* @param int $pid The process identifier.
|
||||||
*
|
*
|
||||||
|
@ -24,10 +25,13 @@ interface ProcessControlInterface
|
||||||
*/
|
*/
|
||||||
public function isRunning($pid);
|
public function isRunning($pid);
|
||||||
|
|
||||||
/** Terminate a running process.
|
/**
|
||||||
|
* Terminate a running process.
|
||||||
*
|
*
|
||||||
* @param int $pid The process identifier.
|
* @param int $pid The process identifier.
|
||||||
* @param bool $forcefully Whether to gently (false) or forcefully (true) terminate the process.
|
* @param bool $forcefully Whether to gently (false) or forcefully (true) terminate the process.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function kill($pid, $forcefully = false);
|
public function kill($pid, $forcefully = false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,14 +30,16 @@ class UnixProcessControl implements ProcessControlInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a signal using the "kill" command.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param int $pid
|
|
||||||
* @param bool $forcefully
|
|
||||||
*/
|
*/
|
||||||
public function kill($pid, $forcefully = false)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,15 +31,16 @@ class WindowsProcessControl implements ProcessControlInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate the process using the "taskkill" command.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param integer $pid
|
|
||||||
*
|
|
||||||
* @param bool $forcefully
|
|
||||||
*/
|
*/
|
||||||
public function kill($pid, $forcefully = false)
|
public function kill($pid, $forcefully = false)
|
||||||
{
|
{
|
||||||
|
$output = [];
|
||||||
|
$result = 1;
|
||||||
|
|
||||||
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
|
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
|
||||||
|
|
||||||
|
return !$result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,12 +4,12 @@ namespace Tests\b8;
|
||||||
|
|
||||||
use b8\Config, b8\Cache;
|
use b8\Config, b8\Cache;
|
||||||
|
|
||||||
class CacheTest extends PHPUnit_Framework_TestCase
|
class CacheTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testCreateSingleton()
|
public function testCreateSingleton()
|
||||||
{
|
{
|
||||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||||
$this->assertTrue($cache instanceof Cache);
|
self::assertInstanceOf('\b8\Cache\ApcCache', $cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisableCaching()
|
public function testDisableCaching()
|
||||||
|
|
|
@ -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']));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,20 +2,30 @@
|
||||||
|
|
||||||
namespace Tests\b8;
|
namespace Tests\b8;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
use b8\Database;
|
use b8\Database;
|
||||||
|
|
||||||
class DatabaseTest extends \PHPUnit_Framework_TestCase
|
class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $_host = 'localhost';
|
protected function setUp()
|
||||||
protected $_user = 'b8_test';
|
{
|
||||||
protected $_pass = 'b8_test';
|
$config = new Config([
|
||||||
protected $_name = 'b8_test';
|
'b8' => [
|
||||||
|
'database' => [
|
||||||
|
'servers' => [
|
||||||
|
'read' => 'localhost',
|
||||||
|
'write' => 'localhost',
|
||||||
|
],
|
||||||
|
'name' => 'b8_test',
|
||||||
|
'username' => 'root',
|
||||||
|
'password' => 'root',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetReadConnection()
|
public function testGetReadConnection()
|
||||||
{
|
{
|
||||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
|
||||||
Database::setReadServers([$this->_host]);
|
|
||||||
|
|
||||||
$connection = Database::getConnection('read');
|
$connection = Database::getConnection('read');
|
||||||
|
|
||||||
$this->assertInstanceOf('\b8\Database', $connection);
|
$this->assertInstanceOf('\b8\Database', $connection);
|
||||||
|
@ -23,9 +33,6 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetWriteConnection()
|
public function testGetWriteConnection()
|
||||||
{
|
{
|
||||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
|
||||||
Database::setWriteServers([$this->_host]);
|
|
||||||
|
|
||||||
$connection = Database::getConnection('write');
|
$connection = Database::getConnection('write');
|
||||||
|
|
||||||
$this->assertInstanceOf('\b8\Database', $connection);
|
$this->assertInstanceOf('\b8\Database', $connection);
|
||||||
|
@ -33,14 +40,11 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetDetails()
|
public function testGetDetails()
|
||||||
{
|
{
|
||||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
|
||||||
Database::setReadServers(['localhost']);
|
|
||||||
|
|
||||||
$details = Database::getConnection('read')->getDetails();
|
$details = Database::getConnection('read')->getDetails();
|
||||||
$this->assertTrue(is_array($details));
|
$this->assertTrue(is_array($details));
|
||||||
$this->assertTrue(($details['db'] == $this->_name));
|
$this->assertTrue(($details['db'] == 'b8_test'));
|
||||||
$this->assertTrue(($details['user'] == $this->_user));
|
$this->assertTrue(($details['user'] == 'root'));
|
||||||
$this->assertTrue(($details['pass'] == $this->_pass));
|
$this->assertTrue(($details['pass'] == 'root'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +52,22 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConnectionFailure()
|
public function testConnectionFailure()
|
||||||
{
|
{
|
||||||
Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
|
Database::reset();
|
||||||
Database::setReadServers(['localhost']);
|
|
||||||
|
$config = new Config([
|
||||||
|
'b8' => [
|
||||||
|
'database' => [
|
||||||
|
'servers' => [
|
||||||
|
'read' => 'localhost',
|
||||||
|
'write' => 'localhost',
|
||||||
|
],
|
||||||
|
'name' => 'b8_test_2',
|
||||||
|
'username' => '',
|
||||||
|
'password' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
Database::getConnection('read');
|
Database::getConnection('read');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,12 +15,17 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertTrue($f->getAction() == '/');
|
$this->assertTrue($f->getAction() == '/');
|
||||||
$this->assertTrue($f->getMethod() == 'POST');
|
$this->assertTrue($f->getMethod() == 'POST');
|
||||||
|
|
||||||
$config = new Config();
|
$config = new Config([
|
||||||
Config::getInstance()->set('ViewPath', __DIR__ . '/data/view/');
|
'b8' => [
|
||||||
|
'view' => [
|
||||||
|
'path' => __DIR__ . '/data/view/'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertTrue($f->render('form') == '/POST');
|
$this->assertTrue($f->render('form') == '/POST');
|
||||||
|
|
||||||
Config::getInstance()->set('ViewPath', '');
|
Config::getInstance()->set('b8.view.path', '');
|
||||||
$this->assertTrue(strpos((string)$f, '<form') !== false);
|
$this->assertTrue(strpos((string)$f, '<form') !== false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +37,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||||
$f->setClass('element-class');
|
$f->setClass('element-class');
|
||||||
$f->setContainerClass('container-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->getId() == 'element-id');
|
||||||
$this->assertTrue($f->getLabel() == 'element-label');
|
$this->assertTrue($f->getLabel() == 'element-label');
|
||||||
$this->assertTrue($f->getClass() == 'element-class');
|
$this->assertTrue($f->getClass() == 'element-class');
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\b8;
|
namespace Tests\b8;
|
||||||
|
|
||||||
use b8\View, b8\View\UserView;
|
use b8\View;
|
||||||
|
use b8\View\Template;
|
||||||
|
|
||||||
class ViewTest extends \PHPUnit_Framework_TestCase
|
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()
|
public function testInvalidHelper()
|
||||||
{
|
{
|
||||||
$view = new UserView('{@Invalid:test}');
|
$view = new Template('{@Invalid:test}');
|
||||||
$view->render();
|
$view->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleUserView()
|
public function testSimpleUserView()
|
||||||
{
|
{
|
||||||
$view = new UserView('Hello');
|
$view = new Template('Hello');
|
||||||
$this->assertTrue($view->render() == 'Hello');
|
$this->assertTrue($view->render() == 'Hello');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserViewYear()
|
public function testUserViewYear()
|
||||||
{
|
{
|
||||||
$view = new UserView('{@year}');
|
$view = new Template('{@year}');
|
||||||
$this->assertTrue($view->render() == date('Y'));
|
$this->assertTrue($view->render() == date('Y'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserViewVars()
|
public function testUserViewVars()
|
||||||
{
|
{
|
||||||
$view = new UserView('Hello {@who}');
|
$view = new Template('Hello {@who}');
|
||||||
$view->who = 'World';
|
$view->who = 'World';
|
||||||
$this->assertTrue($view->render() == 'Hello World');
|
$this->assertTrue($view->render() == 'Hello World');
|
||||||
|
|
||||||
$view = new UserView('Hello {@who}');
|
$view = new Template('Hello {@who}');
|
||||||
$this->assertTrue($view->render() == 'Hello ');
|
$this->assertTrue($view->render() == 'Hello ');
|
||||||
|
|
||||||
$view = new UserView('Hello {@who.name}');
|
$view = new Template('Hello {@who.name}');
|
||||||
$view->who = ['name' => 'Dan'];
|
$view->who = ['name' => 'Dan'];
|
||||||
$this->assertTrue($view->render() == 'Hello Dan');
|
$this->assertTrue($view->render() == 'Hello Dan');
|
||||||
|
|
||||||
$tmp = new UserView('Hello');
|
$tmp = new Template('Hello');
|
||||||
$tmp->who = 'World';
|
$tmp->who = 'World';
|
||||||
$view = new UserView('Hello {@tmp.who}');
|
$view = new Template('Hello {@tmp.who}');
|
||||||
$view->tmp = $tmp;
|
$view->tmp = $tmp;
|
||||||
|
|
||||||
$this->assertTrue($view->render() == 'Hello World');
|
$this->assertTrue($view->render() == 'Hello World');
|
||||||
|
|
||||||
$tmp = new UserView('Hello');
|
try {
|
||||||
$view = new UserView('Hello {@tmp.who}');
|
$tmp = new Template('Hello');
|
||||||
$view->tmp = $tmp;
|
$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 Template('Hello {@who.toUpperCase}');
|
||||||
|
|
||||||
$view = new UserView('Hello {@who.toUpperCase}');
|
|
||||||
$view->who = 'World';
|
$view->who = 'World';
|
||||||
$this->assertTrue($view->render() == 'Hello WORLD');
|
$this->assertTrue($view->render() == 'Hello WORLD');
|
||||||
|
|
||||||
$view = new UserView('Hello {@who.toLowerCase}');
|
$view = new Template('Hello {@who.toLowerCase}');
|
||||||
$view->who = 'World';
|
$view->who = 'World';
|
||||||
$this->assertTrue($view->render() == 'Hello world');
|
$this->assertTrue($view->render() == 'Hello world');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserViewIf()
|
public function testUserViewIf()
|
||||||
{
|
{
|
||||||
$view = new UserView('Hello{if who} World{/if}');
|
$view = new Template('Hello{if who} World{/if}');
|
||||||
$view->who = true;
|
$view->who = true;
|
||||||
$this->assertTrue($view->render() == 'Hello World');
|
$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;
|
$view->who = false;
|
||||||
$this->assertTrue($view->render() == 'Hello');
|
$this->assertTrue($view->render() == 'Hello');
|
||||||
|
|
||||||
$view = new UserView('Hello{ifnot who} World{/ifnot}');
|
$view = new Template('Hello{ifnot who} World{/ifnot}');
|
||||||
$view->who = true;
|
$view->who = true;
|
||||||
$this->assertTrue($view->render() == 'Hello');
|
$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 ');
|
$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');
|
$this->assertTrue($view->render() == 'Hello World');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserViewLoop()
|
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'];
|
$view->who = ['W', 'o', 'r', 'l', 'd'];
|
||||||
$this->assertTrue($view->render() == 'Hello World');
|
$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 ');
|
$this->assertTrue($view->render() == 'Hello ');
|
||||||
|
|
||||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
$view = new Template('Hello {loop who}{@item}{/loop}');
|
||||||
$view->who = 'World';
|
$view->who = 'World';
|
||||||
$this->assertTrue($view->render() == 'Hello World');
|
$this->assertTrue($view->render() == 'Hello World');
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
namespace Tests\PHPCensor\Plugin\Command;
|
namespace Tests\PHPCensor\Plugin\Command;
|
||||||
|
|
||||||
|
use PHPCensor\Command\CreateAdminCommand;
|
||||||
|
use PHPCensor\Store\UserStore;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
|
@ -26,27 +28,23 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
protected $application;
|
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')
|
$userStoreMock = $this->getMock('PHPCensor\\Store\\UserStore');
|
||||||
->setConstructorArgs([$this->getMock('PHPCensor\\Store\\UserStore')])
|
|
||||||
->setMethods(['reloadConfig'])
|
$this->command = new CreateAdminCommand($userStoreMock);
|
||||||
|
|
||||||
|
$this->helper = $this
|
||||||
|
->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')
|
||||||
|
->setMethods(['ask'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
|
|
||||||
->setMethods([
|
|
||||||
'ask',
|
|
||||||
'askAndValidate',
|
|
||||||
'askHiddenResponse',
|
|
||||||
])->getMock()
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->application = new Application();
|
$this->application = new Application();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,19 +53,18 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
protected function getCommandTester()
|
protected function getCommandTester()
|
||||||
{
|
{
|
||||||
$this->application->getHelperSet()->set($this->dialog, 'dialog');
|
$this->application->getHelperSet()->set($this->helper, 'question');
|
||||||
$this->application->add($this->command);
|
$this->application->add($this->command);
|
||||||
$command = $this->application->find('php-censor:create-admin');
|
$commandTester = new CommandTester($this->command);
|
||||||
$commandTester = new CommandTester($command);
|
|
||||||
|
|
||||||
return $commandTester;
|
return $commandTester;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExecute()
|
public function testExecute()
|
||||||
{
|
{
|
||||||
$this->dialog->expects($this->at(0))->method('askAndValidate')->will($this->returnValue('test@example.com'));
|
$this->helper->expects($this->at(0))->method('ask')->will($this->returnValue('test@example.com'));
|
||||||
$this->dialog->expects($this->at(1))->method('ask')->will($this->returnValue('A name'));
|
$this->helper->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(2))->method('ask')->will($this->returnValue('foobar123'));
|
||||||
|
|
||||||
$commandTester = $this->getCommandTester();
|
$commandTester = $this->getCommandTester();
|
||||||
$commandTester->execute([]);
|
$commandTester->execute([]);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
namespace Tests\PHPCensor\Command;
|
namespace Tests\PHPCensor\Command;
|
||||||
|
|
||||||
|
use PHPCensor\Command\CreateBuildCommand;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
|
@ -24,9 +25,9 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
protected $application;
|
protected $application;
|
||||||
|
|
||||||
public function setup()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setup();
|
parent::setUp();
|
||||||
|
|
||||||
$projectMock = $this->getMock('PHPCensor\\Model\\Project');
|
$projectMock = $this->getMock('PHPCensor\\Model\\Project');
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
$buildServiceMock = $this->getMockBuilder('PHPCensor\\Service\\BuildService')
|
$buildServiceMock = $this->getMockBuilder('PHPCensor\\Service\\BuildService')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$buildServiceMock->method('createBuild')
|
$buildServiceMock->method('createBuild')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
[$projectMock, null, null, null, null, null],
|
[$projectMock, null, null, null, null, null],
|
||||||
|
@ -48,10 +50,7 @@ class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
[$projectMock, null, 'master', null, null, null]
|
[$projectMock, null, 'master', null, null, null]
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->command = $this->getMockBuilder('PHPCensor\\Command\\CreateBuildCommand')
|
$this->command = new CreateBuildCommand($projectStoreMock, $buildServiceMock);
|
||||||
->setConstructorArgs([$projectStoreMock, $buildServiceMock])
|
|
||||||
->setMethods(['reloadConfig'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$this->application = new Application();
|
$this->application = new Application();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,36 +18,34 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public $config;
|
public $config;
|
||||||
public $admin;
|
public $admin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
protected $application;
|
protected $application;
|
||||||
|
|
||||||
public function setup()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setup();
|
parent::setUp();
|
||||||
|
|
||||||
$this->application = new Application();
|
$this->application = new Application();
|
||||||
$this->application->setHelperSet(new HelperSet());
|
$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.
|
// We check that there's no interaction with user.
|
||||||
$dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
|
return $this
|
||||||
->setMethods([
|
->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')
|
||||||
'ask',
|
->setMethods(['ask'])
|
||||||
'askConfirmation',
|
->getMock();
|
||||||
'askAndValidate',
|
|
||||||
'askHiddenResponse',
|
|
||||||
'askHiddenResponseAndValidate',
|
|
||||||
])->getMock();
|
|
||||||
|
|
||||||
return $dialog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \PHPUnit_Framework_MockObject_MockBuilder
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
protected function getInstallCommandMock()
|
protected function getInstallCommandMock()
|
||||||
{
|
{
|
||||||
|
@ -84,9 +82,9 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
return $command;
|
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());
|
$this->application->add($this->getInstallCommandMock());
|
||||||
$command = $this->application->find('php-censor:install');
|
$command = $this->application->find('php-censor:install');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
|
@ -98,6 +96,7 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$config = [
|
$config = [
|
||||||
'--db-host' => 'localhost',
|
'--db-host' => 'localhost',
|
||||||
|
'--db-port' => '3306',
|
||||||
'--db-name' => 'php-censor-db',
|
'--db-name' => 'php-censor-db',
|
||||||
'--db-user' => 'php-censor-user',
|
'--db-user' => 'php-censor-user',
|
||||||
'--db-pass' => 'php-censor-password',
|
'--db-pass' => 'php-censor-password',
|
||||||
|
@ -129,26 +128,18 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testAutomaticInstallation()
|
public function testAutomaticInstallation()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
$dialog->expects($this->never())->method('ask');
|
$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);
|
$this->executeWithoutParam(null, $dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDatabaseHostnameConfig()
|
public function testDatabaseHostnameConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
$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);
|
$this->executeWithoutParam('--db-host', $dialog);
|
||||||
|
|
||||||
|
@ -159,14 +150,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testDatabaseNameConfig()
|
public function testDatabaseNameConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
$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);
|
$this->executeWithoutParam('--db-name', $dialog);
|
||||||
|
|
||||||
|
@ -176,14 +163,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testDatabaseUserConfig()
|
public function testDatabaseUserConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
$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);
|
$this->executeWithoutParam('--db-user', $dialog);
|
||||||
|
|
||||||
|
@ -193,14 +176,9 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testDatabasePasswordConfig()
|
public function testDatabasePasswordConfig()
|
||||||
{
|
{
|
||||||
$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('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');
|
|
||||||
|
|
||||||
$this->executeWithoutParam('--db-pass', $dialog);
|
$this->executeWithoutParam('--db-pass', $dialog);
|
||||||
|
|
||||||
|
@ -210,14 +188,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUrlConfig()
|
public function testUrlConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->never())->method('ask');
|
$dialog->expects($this->once())->method('ask')->willReturn('http://testedvalue.com');
|
||||||
$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');
|
|
||||||
|
|
||||||
$this->executeWithoutParam('--url', $dialog);
|
$this->executeWithoutParam('--url', $dialog);
|
||||||
|
|
||||||
|
@ -227,14 +201,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testAdminEmailConfig()
|
public function testAdminEmailConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->never())->method('ask');
|
$dialog->expects($this->once())->method('ask')->willReturn('admin@php-censor.local');
|
||||||
$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');
|
|
||||||
|
|
||||||
$this->executeWithoutParam('--admin-mail', $dialog);
|
$this->executeWithoutParam('--admin-mail', $dialog);
|
||||||
|
|
||||||
|
@ -244,14 +214,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testAdminNameConfig()
|
public function testAdminNameConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// Define expectation for dialog.
|
// Define expectation for dialog.
|
||||||
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
$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);
|
$this->executeWithoutParam('--admin-name', $dialog);
|
||||||
|
|
||||||
|
@ -261,14 +227,10 @@ class InstallCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testAdminPasswordConfig()
|
public function testAdminPasswordConfig()
|
||||||
{
|
{
|
||||||
$dialog = $this->getDialogHelperMock();
|
$dialog = $this->getHelperMock();
|
||||||
|
|
||||||
// We specified an input value for hostname.
|
// We specified an input value for hostname.
|
||||||
$dialog->expects($this->never())->method('ask');
|
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
||||||
$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');
|
|
||||||
|
|
||||||
$this->executeWithoutParam('--admin-pass', $dialog);
|
$this->executeWithoutParam('--admin-pass', $dialog);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase
|
||||||
$config = [
|
$config = [
|
||||||
'smtp_address' => 'mail.example.com',
|
'smtp_address' => 'mail.example.com',
|
||||||
'smtp_port' => 225,
|
'smtp_port' => 225,
|
||||||
'smtp_encryption' => true,
|
'smtp_encryption' => 'tls',
|
||||||
'smtp_username' => 'php-censor-user',
|
'smtp_username' => 'php-censor-user',
|
||||||
'smtp_password' => 'php-censor-password',
|
'smtp_password' => 'php-censor-password',
|
||||||
'default_mailto_address' => 'admin@php-censor.local',
|
'default_mailto_address' => 'admin@php-censor.local',
|
||||||
|
@ -54,7 +54,7 @@ class MailerFactoryTest extends \PHPUnit_Framework_TestCase
|
||||||
$config = [
|
$config = [
|
||||||
'smtp_address' => 'mail.example.com',
|
'smtp_address' => 'mail.example.com',
|
||||||
'smtp_port' => 225,
|
'smtp_port' => 225,
|
||||||
'smtp_encryption' => true,
|
'smtp_encryption' => 'tls',
|
||||||
'smtp_username' => 'php-censor-user',
|
'smtp_username' => 'php-censor-user',
|
||||||
'smtp_password' => 'php-censor-password',
|
'smtp_password' => 'php-censor-password',
|
||||||
'default_mailto_address' => 'admin@php-censor.local',
|
'default_mailto_address' => 'admin@php-censor.local',
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
namespace Tests\PHPCensor\Plugin;
|
namespace Tests\PHPCensor\Plugin;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
use PHPCensor\Plugin\Email as EmailPlugin;
|
use PHPCensor\Plugin\Email as EmailPlugin;
|
||||||
use PHPCensor\Model\Build;
|
use PHPCensor\Model\Build;
|
||||||
|
|
||||||
|
@ -61,6 +62,14 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->mailDelivered = true;
|
$this->mailDelivered = true;
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
|
$config = new Config([
|
||||||
|
'b8' => [
|
||||||
|
'view' => [
|
||||||
|
'path' => SRC_DIR . 'View/'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
$this->mockProject = $this->getMock(
|
$this->mockProject = $this->getMock(
|
||||||
'\PHPCensor\Model\Project',
|
'\PHPCensor\Model\Project',
|
||||||
['getTitle'],
|
['getTitle'],
|
||||||
|
@ -104,7 +113,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
[
|
[
|
||||||
'getSystemConfig',
|
'getSystemConfig',
|
||||||
'getBuild',
|
'getBuild',
|
||||||
'log'
|
'log',
|
||||||
|
'logDebug'
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
"mockBuilder_email",
|
"mockBuilder_email",
|
||||||
|
@ -119,7 +129,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue(['email_settings' => ['from_address' => "test-from-address@example.com"]]));
|
->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;
|
$this->mailDelivered = $mailDelivered;
|
||||||
|
|
||||||
|
@ -147,10 +157,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->testedEmailPlugin->expects($this->any())
|
$this->testedEmailPlugin->expects($this->any())
|
||||||
->method('sendEmail')
|
->method('sendEmail')
|
||||||
->will($this->returnCallback(function ($to, $cc, $subject, $body) use ($self) {
|
->will($this->returnCallback(function ($to, $cc, $subject, $body) use ($self) {
|
||||||
$self->message['to'][] = $to;
|
$self->message['to'][] = $to;
|
||||||
$self->message['cc'] = $cc;
|
$self->message['cc'] = $cc;
|
||||||
$self->message['subject'] = $subject;
|
$self->message['subject'] = $subject;
|
||||||
$self->message['body'] = $body;
|
$self->message['body'] = $body;
|
||||||
|
|
||||||
return $self->mailDelivered;
|
return $self->mailDelivered;
|
||||||
}));
|
}));
|
||||||
|
@ -356,7 +366,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
'addresses' => ['test-receiver@example.com']
|
'addresses' => ['test-receiver@example.com']
|
||||||
],
|
],
|
||||||
Build::STATUS_FAILED,
|
Build::STATUS_FAILED,
|
||||||
true
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
$returnValue = $this->testedEmailPlugin->execute();
|
$returnValue = $this->testedEmailPlugin->execute();
|
||||||
|
@ -374,7 +384,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
'addresses' => ['test-receiver@example.com']
|
'addresses' => ['test-receiver@example.com']
|
||||||
],
|
],
|
||||||
Build::STATUS_FAILED,
|
Build::STATUS_FAILED,
|
||||||
false
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
$returnValue = $this->testedEmailPlugin->execute();
|
$returnValue = $this->testedEmailPlugin->execute();
|
||||||
|
|
|
@ -39,7 +39,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
protected function buildTemp()
|
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);
|
unlink($directory);
|
||||||
return $directory;
|
return $directory;
|
||||||
}
|
}
|
||||||
|
@ -95,13 +95,13 @@ class PharTest extends \PHPUnit_Framework_TestCase
|
||||||
$plugin = $this->getPlugin();
|
$plugin = $this->getPlugin();
|
||||||
$this->assertInstanceOf('PHPCensor\Plugin', $plugin);
|
$this->assertInstanceOf('PHPCensor\Plugin', $plugin);
|
||||||
$this->assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild());
|
$this->assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild());
|
||||||
$this->assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder());
|
$this->assertInstanceOf('PHPCensor\Builder', $plugin->getPHPCI());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDirectory()
|
public function testDirectory()
|
||||||
{
|
{
|
||||||
$plugin = $this->getPlugin();
|
$plugin = $this->getPlugin();
|
||||||
$plugin->getBuilder()->buildPath = 'foo';
|
$plugin->getPHPCI()->buildPath = 'foo';
|
||||||
$this->assertEquals('foo', $plugin->getDirectory());
|
$this->assertEquals('foo', $plugin->getDirectory());
|
||||||
|
|
||||||
$plugin = $this->getPlugin(['directory' => 'dirname']);
|
$plugin = $this->getPlugin(['directory' => 'dirname']);
|
||||||
|
@ -141,7 +141,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$plugin = $this->getPlugin();
|
$plugin = $this->getPlugin();
|
||||||
$path = $this->buildSource();
|
$path = $this->buildSource();
|
||||||
$plugin->getBuilder()->buildPath = $path;
|
$plugin->getPHPCI()->buildPath = $path;
|
||||||
|
|
||||||
$this->assertTrue($plugin->execute());
|
$this->assertTrue($plugin->execute());
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class PharTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']);
|
$plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']);
|
||||||
$path = $this->buildSource();
|
$path = $this->buildSource();
|
||||||
$plugin->getBuilder()->buildPath = $path;
|
$plugin->getPHPCI()->buildPath = $path;
|
||||||
|
|
||||||
$this->assertTrue($plugin->execute());
|
$this->assertTrue($plugin->execute());
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ STUB;
|
||||||
file_put_contents($path . '/stub.php', $content);
|
file_put_contents($path . '/stub.php', $content);
|
||||||
|
|
||||||
$plugin = $this->getPlugin(['stub' => 'stub.php']);
|
$plugin = $this->getPlugin(['stub' => 'stub.php']);
|
||||||
$plugin->getBuilder()->buildPath = $path;
|
$plugin->getPHPCI()->buildPath = $path;
|
||||||
|
|
||||||
$this->assertTrue($plugin->execute());
|
$this->assertTrue($plugin->execute());
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ STUB;
|
||||||
$directory = $this->buildTemp();
|
$directory = $this->buildTemp();
|
||||||
|
|
||||||
$plugin = $this->getPlugin(['directory' => $directory]);
|
$plugin = $this->getPlugin(['directory' => $directory]);
|
||||||
$plugin->getBuilder()->buildPath = $this->buildSource();
|
$plugin->getPHPCI()->buildPath = $this->buildSource();
|
||||||
|
|
||||||
$this->assertFalse($plugin->execute());
|
$this->assertFalse($plugin->execute());
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testExecutePlugin_LogsFailureForNonExistentClasses()
|
public function testExecutePlugin_LogsFailureForNonExistentClasses()
|
||||||
{
|
{
|
||||||
$options = [];
|
$options = [];
|
||||||
$pluginName = 'DOESNTEXIST';
|
$pluginName = 'DOESNTEXIST';
|
||||||
|
|
||||||
$this->mockBuildLogger->logFailure('Plugin does not exist: ' . $pluginName)->shouldBeCalledTimes(1);
|
$this->mockBuildLogger->logFailure('Plugin does not exist: ' . $pluginName)->shouldBeCalledTimes(1);
|
||||||
|
@ -108,7 +108,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testExecutePlugin_LogsFailureWhenExceptionsAreThrownByPlugin()
|
public function testExecutePlugin_LogsFailureWhenExceptionsAreThrownByPlugin()
|
||||||
{
|
{
|
||||||
$options = [];
|
$options = [];
|
||||||
$pluginName = 'PhpUnit';
|
$pluginName = 'PhpUnit';
|
||||||
|
|
||||||
$expectedException = new \RuntimeException("Generic Error");
|
$expectedException = new \RuntimeException("Generic Error");
|
||||||
|
|
|
@ -77,6 +77,21 @@ TAP version 13
|
||||||
|
|
||||||
Generating code coverage report in HTML format ... done
|
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;
|
TAP;
|
||||||
$parser = new TapParser($content);
|
$parser = new TapParser($content);
|
||||||
$result = $parser->parse();
|
$result = $parser->parse();
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Tests\PHPCensor\ProcessControl;
|
||||||
abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var type
|
* @var resource
|
||||||
*/
|
*/
|
||||||
protected $process;
|
protected $process;
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->pipes = [];
|
$this->pipes = [];
|
||||||
|
|
||||||
$this->process = proc_open($this->getTestCommand(), $desc, $this->pipes);
|
$this->process = proc_open($this->getTestCommand(), $desc, $this->pipes);
|
||||||
usleep(500);
|
sleep(1);
|
||||||
|
|
||||||
$this->assertTrue(is_resource($this->process));
|
$this->assertTrue(is_resource($this->process));
|
||||||
$this->assertTrue($this->isRunning());
|
$this->assertTrue($this->isRunning());
|
||||||
|
|
||||||
$status = proc_get_status($this->process);
|
$status = proc_get_status($this->process);
|
||||||
return $status['pid'];
|
return (integer)$status['pid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** End the running process.
|
/** End the running process.
|
||||||
|
@ -65,7 +65,7 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$status = proc_get_status($this->process);
|
$status = proc_get_status($this->process);
|
||||||
return $status['running'];
|
return (boolean)$status['running'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsRunning()
|
public function testIsRunning()
|
||||||
|
@ -94,10 +94,10 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$pid = $this->startProcess();
|
$pid = $this->startProcess();
|
||||||
|
|
||||||
$this->object->kill($pid);
|
self::assertTrue($this->object->kill($pid));
|
||||||
usleep(500);
|
sleep(1);
|
||||||
|
|
||||||
$this->assertFalse($this->isRunning());
|
self::assertFalse($this->isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForcefullyKill()
|
public function testForcefullyKill()
|
||||||
|
@ -109,9 +109,9 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
|
||||||
$pid = $this->startProcess();
|
$pid = $this->startProcess();
|
||||||
|
|
||||||
$this->object->kill($pid, true);
|
$this->object->kill($pid, true);
|
||||||
usleep(500);
|
sleep(1);
|
||||||
|
|
||||||
$this->assertFalse($this->isRunning());
|
self::assertFalse($this->isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function testIsAvailable();
|
abstract public function testIsAvailable();
|
||||||
|
|
|
@ -7,7 +7,7 @@ class WindowsProcessControlTest extends ProcessControlTest
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->object = new WindowsProcessControl;
|
$this->object = new WindowsProcessControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTestCommand()
|
public function getTestCommand()
|
||||||
|
|
|
@ -66,4 +66,4 @@ if (!defined('IS_CONSOLE')) {
|
||||||
define('IS_CONSOLE', false);
|
define('IS_CONSOLE', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
\PHPCensor\Helper\Lang::init($config);
|
\PHPCensor\Helper\Lang::init($config, 'en');
|
||||||
|
|
Loading…
Reference in a new issue