Merge branch 'code-style-refactoring'

This commit is contained in:
Dmitry Khomutov 2018-04-09 20:42:25 +07:00
commit 1acd3dc9b9
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
46 changed files with 263 additions and 249 deletions

View file

@ -57,9 +57,7 @@ class Application
$this->router = new Router($this, $this->request, $this->config);
if (method_exists($this, 'init')) {
$this->init();
}
$this->init();
}
/**

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Command;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Service\UserService;
use PHPCensor\Store\UserStore;
use Symfony\Component\Console\Command\Command;
@ -58,7 +59,7 @@ class CreateAdminCommand extends Command
// Function to validate email address.
$mailValidator = function ($answer) {
if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException('Must be a valid email address.');
throw new InvalidArgumentException('Must be a valid email address.');
}
return $answer;

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Command;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Model\Build;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\ProjectStore;
@ -71,7 +72,7 @@ class CreateBuildCommand extends Command
$project = $this->projectStore->getById($projectId);
if (empty($project) || $project->getArchived()) {
throw new \InvalidArgumentException('Project does not exist: ' . $projectId);
throw new InvalidArgumentException('Project does not exist: ' . $projectId);
}
try {

View file

@ -6,6 +6,7 @@ use Exception;
use PDO;
use PHPCensor\Config;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Store\Factory;
use PHPCensor\Model\ProjectGroup;
use PHPCensor\Store\UserStore;
@ -185,7 +186,7 @@ class InstallCommand extends Command
// Function to validate email address.
$mailValidator = function ($answer) {
if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException('Must be a valid email address.');
throw new InvalidArgumentException('Must be a valid email address.');
}
return $answer;

View file

@ -1,18 +0,0 @@
<?php
namespace PHPCensor\Exception\HttpException;
use PHPCensor\Exception\HttpException;
class ValidationException extends HttpException
{
/**
* @var integer
*/
protected $errorCode = 400;
/**
* @var string
*/
protected $statusMessage = 'Bad Request';
}

View file

@ -0,0 +1,7 @@
<?php
namespace PHPCensor\Exception;
class InvalidArgumentException extends \InvalidArgumentException
{
}

View file

@ -54,16 +54,6 @@ class Lang
return $string;
}
/**
* Output a specific string from the language file.
*
* @param array ...$params
*/
public static function out(...$params)
{
print call_user_func_array(['PHPCensor\Helper\Lang', 'get'], $params);
}
/**
* Get the currently active language.
*

View file

@ -4,6 +4,7 @@ namespace PHPCensor\Http;
use PHPCensor\Application;
use PHPCensor\Config;
use PHPCensor\Exception\InvalidArgumentException;
class Router
{
@ -40,15 +41,16 @@ class Router
}
/**
* @param string $route Route definition
* @param array $options
* @param string $route Route definition
* @param array $options
* @param callable $callback
* @throws \InvalidArgumentException
*
* @throws InvalidArgumentException
*/
public function register($route, $options = [], $callback = null)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('$callback must be callable.');
throw new InvalidArgumentException('$callback must be callable.');
}
array_unshift($this->routes, ['route' => $route, 'callback' => $callback, 'defaults' => $options]);

View file

@ -2,7 +2,7 @@
namespace PHPCensor;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Exception\InvalidArgumentException;
class Model
{
@ -29,7 +29,7 @@ class Model
if (is_array($initialData)) {
foreach ($initialData as $index => $item) {
if (!array_key_exists($index, $this->data)) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Model "%s" doesn\'t have field "%s"',
get_called_class(),
$index
@ -81,12 +81,12 @@ class Model
* @param string $name
* @param mixed $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*/
protected function validateString($name, $value)
{
if (!is_string($value) && !is_null($value)) {
throw new ValidationException('Column "' . $name . '" must be a string.');
throw new InvalidArgumentException('Column "' . $name . '" must be a string.');
}
}
@ -94,12 +94,12 @@ class Model
* @param string $name
* @param mixed $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*/
protected function validateInt($name, $value)
{
if (!is_integer($value) && !is_null($value)) {
throw new ValidationException('Column "' . $name . '" must be an integer.');
throw new InvalidArgumentException('Column "' . $name . '" must be an integer.');
}
}
@ -107,12 +107,12 @@ class Model
* @param string $name
* @param mixed $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*/
protected function validateBoolean($name, $value)
{
if (!is_bool($value) && !is_null($value)) {
throw new ValidationException('Column "' . $name . '" must be a boolean.');
throw new InvalidArgumentException('Column "' . $name . '" must be a boolean.');
}
}
@ -120,12 +120,12 @@ class Model
* @param string $name
* @param mixed $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*/
protected function validateNotNull($name, $value)
{
if (is_null($value)) {
throw new ValidationException('Column "' . $name . '" must not be null.');
throw new InvalidArgumentException('Column "' . $name . '" must not be null.');
}
}
}

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Model\Base;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Model;
class Build extends Model
@ -155,7 +155,7 @@ class Build extends Model
/**
* @param integer $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*
* @return boolean
*/
@ -165,7 +165,7 @@ class Build extends Model
$this->validateInt('status', $value);
if (!in_array($value, $this->allowedStatuses, true)) {
throw new ValidationException(
throw new InvalidArgumentException(
'Column "status" must be one of: ' . join(', ', $this->allowedStatuses) . '.'
);
}
@ -474,7 +474,7 @@ class Build extends Model
/**
* @param integer $value
*
* @throws ValidationException
* @throws InvalidArgumentException
*
* @return boolean
*/
@ -483,7 +483,7 @@ class Build extends Model
$this->validateInt('source', $value);
if (!in_array($value, $this->allowedSources, true)) {
throw new ValidationException(
throw new InvalidArgumentException(
'Column "source" must be one of: ' . join(', ', $this->allowedSources) . '.'
);
}

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Model\Base;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Model;
class Project extends Model
@ -274,7 +274,7 @@ class Project extends Model
*
* @return boolean
*
* @throws ValidationException
* @throws InvalidArgumentException
*/
public function setType($value)
{
@ -282,7 +282,7 @@ class Project extends Model
$this->validateString('type', $value);
if (!in_array($value, $this->allowedTypes, true)) {
throw new ValidationException(
throw new InvalidArgumentException(
'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.'
);
}

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Plugin\Util;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Plugin;
use Pimple\Container;
@ -68,11 +69,9 @@ class Factory
* Builds an instance of plugin of class $className. $options will
* be passed along with any resources registered with the factory.
*
* @param $className
* @param string $className
* @param array|null $options
*
* @throws \InvalidArgumentException if $className doesn't represent a valid plugin
*
* @return \PHPCensor\Plugin
*/
public function buildPlugin($className, $options = [])
@ -103,10 +102,12 @@ class Factory
}
/**
* @param callable $loader
* @param callable $loader
* @param string|null $name
* @param string|null $type
* @throws \InvalidArgumentException
*
* @throws InvalidArgumentException
*
* @internal param mixed $resource
*/
public function registerResource(
@ -115,13 +116,13 @@ class Factory
$type = null
) {
if ($name === null && $type === null) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
"Type or Name must be specified"
);
}
if (!($loader instanceof \Closure)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'$loader is expected to be a function'
);
}

View file

@ -2,6 +2,8 @@
namespace PHPCensor;
use PHPCensor\Exception\InvalidArgumentException;
abstract class Store
{
/**
@ -110,15 +112,14 @@ abstract class Store
* @param Model $obj
* @param boolean $saveAllColumns
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*
* @return Model|null
*/
public function save(Model $obj, $saveAllColumns = false)
{
if (!($obj instanceof $this->modelName)) {
throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.');
throw new InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.');
}
$data = $obj->getDataArray();
@ -207,15 +208,14 @@ abstract class Store
/**
* @param Model $obj
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*
* @return boolean
*/
public function delete(Model $obj)
{
if (!($obj instanceof $this->modelName)) {
throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.');
throw new InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.');
}
$data = $obj->getDataArray();
@ -230,14 +230,14 @@ abstract class Store
/**
* @param string $field
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*
* @return string
*/
protected function fieldCheck($field)
{
if (empty($field)) {
throw new \InvalidArgumentException('You cannot have an empty field name.');
throw new InvalidArgumentException('You cannot have an empty field name.');
}
if (strpos($field, '.') === false) {

View file

@ -8,24 +8,40 @@ use PHPCensor\Store\UserStore;
class View
{
protected $vars = [];
protected $isContent = false;
/**
* @var array
*/
protected $data = [];
/**
* @var string
*/
protected $viewFile;
/**
* @var string
*/
protected static $extension = 'phtml';
/**
* @param string $file
* @param string|null $path
*/
public function __construct($file, $path = null)
{
if ('{@content}' === $file) {
$this->isContent = true;
} else {
if (!self::exists($file, $path)) {
throw new \RuntimeException('View file does not exist: ' . $file);
}
$this->viewFile = self::getViewFile($file, $path);
if (!self::exists($file, $path)) {
throw new \RuntimeException('View file does not exist: ' . $file);
}
$this->viewFile = self::getViewFile($file, $path);
}
/**
* @param string $file
* @param string|null $path
*
* @return string
*/
protected static function getViewFile($file, $path = null)
{
$viewPath = is_null($path) ? (SRC_DIR . 'View/') : $path;
@ -34,6 +50,12 @@ class View
return $fullPath;
}
/**
* @param string $file
* @param string|null $path
*
* @return boolean
*/
public static function exists($file, $path = null)
{
if (!file_exists(self::getViewFile($file, $path))) {
@ -43,37 +65,50 @@ class View
return true;
}
public function __isset($var)
/**
* @param string $key
*
* @return boolean
*/
public function __isset($key)
{
return isset($this->vars[$var]);
return isset($this->data[$key]);
}
public function __get($var)
/**
* @param string $key
*
* @return mixed
*/
public function __get($key)
{
return $this->vars[$var];
return $this->data[$key];
}
public function __set($var, $val)
/**
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
$this->vars[$var] = $val;
$this->data[$key] = $value;
}
/**
* @return string
*/
public function render()
{
if ($this->isContent) {
return $this->vars['content'];
} else {
extract($this->vars);
extract($this->data);
ob_start();
ob_start();
require($this->viewFile);
require($this->viewFile);
$html = ob_get_contents();
ob_end_clean();
$html = ob_get_contents();
ob_end_clean();
return $html;
}
return $html;
}
/**

View file

@ -1,9 +1,16 @@
<?php
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
/**
* @var Build $build
* @var BuildError[] $errors
*/
$linkTemplate = $build->getFileLinkTemplate();
/** @var \PHPCensor\Model\BuildError[] $errors */
foreach ($errors as $error):
$link = str_replace('{BASEFILE}', basename($error->getFile()), $linkTemplate);
@ -11,7 +18,6 @@ foreach ($errors as $error):
$link = str_replace('{LINE}', $error->getLineStart(), $link);
$link = str_replace('{LINE_END}', $error->getLineEnd(), $link);
?>
<tr>
<td>
<?php if ($error->getIsNew()): ?>
@ -37,7 +43,5 @@ foreach ($errors as $error):
</a>
</td>
<td class="visible-line-breaks"><?= htmlspecialchars(trim($error->getMessage())); ?></td>
</tr>
<?php endforeach; ?>

View file

@ -19,12 +19,18 @@ use PHPCensor\Model\Build;
<h4>
<?= $build->getProject()->getTitle(); ?>
<?php if ($build->getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?>
<small class="pull-right"><?php Lang::out('created_x', $build->getCreateDate()->format('H:i')); ?></small>
<?php elseif ($build->getStatus() == \PHPCensor\Model\Build::STATUS_RUNNING): ?>
<small class="pull-right"><?php Lang::out('started_x', $build->getStartDate()->format('H:i')); ?></small>
<?php if ($build->getStatus() == Build::STATUS_PENDING): ?>
<small class="pull-right">
<?= Lang::get('created_x', $build->getCreateDate()->format('H:i')); ?>
</small>
<?php elseif ($build->getStatus() == Build::STATUS_RUNNING): ?>
<small class="pull-right">
<?= Lang::get('started_x', $build->getStartDate()->format('H:i')); ?>
</small>
<?php endif; ?>
</h4>
<p><?php Lang::out('branch_x', $build->getBranch()); ?></p>
<p>
<?= Lang::get('branch_x', $build->getBranch()); ?>
</p>
</a>
</li>

View file

@ -15,14 +15,14 @@ use PHPCensor\Model\BuildError;
<div class="box">
<div class="box-header">
<h3 class="box-title">
<?php Lang::out('build_details'); ?>
<?= Lang::get('build_details'); ?>
</h3>
</div>
<div class="box-body no-padding">
<table class="table">
<tr>
<th><?php Lang::out('project'); ?></th>
<th><?= Lang::get('project'); ?></th>
<td style="text-align: right">
<a href="<?= APP_URL . 'project/view/' . $build->getProjectId(); ?>">
<i class="fa fa-<?= $build->getProject()->getIcon(); ?>"></i>
@ -32,7 +32,7 @@ use PHPCensor\Model\BuildError;
</tr>
<tr>
<th><?php Lang::out('branch'); ?></th>
<th><?= Lang::get('branch'); ?></th>
<td style="text-align: right">
<?php if (Build::SOURCE_WEBHOOK_PULL_REQUEST === $build->getSource()): ?>
<a href="<?= $build->getRemoteBranchLink(); ?>">
@ -53,7 +53,7 @@ use PHPCensor\Model\BuildError;
</tr>
<tr>
<th><?php Lang::out('environment'); ?></th>
<th><?= Lang::get('environment'); ?></th>
<td style="text-align: right">
<?php
$environment = $build->getEnvironment();
@ -63,7 +63,7 @@ use PHPCensor\Model\BuildError;
</tr>
<tr>
<th><?php Lang::out('merged_branches'); ?></th>
<th><?= Lang::get('merged_branches'); ?></th>
<td style="text-align: right">
<a href="<?= $build->getBranchLink(); ?>">
<i class="fa fa-code-fork"></i> <?= $build->getBranch(); ?>
@ -89,20 +89,20 @@ use PHPCensor\Model\BuildError;
<div class="box">
<div class="box-header">
<h3 class="box-title">
<?php Lang::out('commit_details'); ?>
<?= Lang::get('commit_details'); ?>
</h3>
</div>
<div class="box-body no-padding">
<table class="table">
<tr>
<th><?php Lang::out('build_source'); ?></th>
<th><?= Lang::get('build_source'); ?></th>
<td style="text-align: right">
<?php Lang::out($build->getSourceHumanize()); ?>
<?= Lang::get($build->getSourceHumanize()); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('commit'); ?></th>
<th><?= Lang::get('commit'); ?></th>
<td style="text-align: right">
<a href="<?= $build->getCommitLink(); ?>">
<?= substr($build->getCommitId(), 0, 7); ?>
@ -111,14 +111,14 @@ use PHPCensor\Model\BuildError;
</tr>
<tr>
<th><?php Lang::out('committer'); ?></th>
<th><?= Lang::get('committer'); ?></th>
<td style="text-align: right">
<?= $build->getCommitterEmail(); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('commit_message'); ?></th>
<th><?= Lang::get('commit_message'); ?></th>
<td style="text-align: right">
<?= htmlspecialchars($build->getCommitMessage()); ?>
</td>
@ -132,35 +132,35 @@ use PHPCensor\Model\BuildError;
<div class="box">
<div class="box-header">
<h3 class="box-title">
<?php Lang::out('timing'); ?>
<?= Lang::get('timing'); ?>
</h3>
</div>
<div class="box-body no-padding">
<table class="table">
<tr>
<th><?php Lang::out('created'); ?></th>
<th><?= Lang::get('created'); ?></th>
<td style="text-align: right" class="build-created datetime">
<?= ($build->getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('started'); ?></th>
<th><?= Lang::get('started'); ?></th>
<td style="text-align: right" class="build-started datetime">
<?= ($build->getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('finished'); ?></th>
<th><?= Lang::get('finished'); ?></th>
<td style="text-align: right" class="build-finished datetime">
<?= ($build->getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('duration'); ?></th>
<th><?= Lang::get('duration'); ?></th>
<td style="text-align: right" class="build-duration duration">
<?= $build->getDuration(); ?> <?= Lang::get('seconds'); ?>
</td>
@ -289,12 +289,12 @@ use PHPCensor\Model\BuildError;
<table class="errors-table table table-hover">
<thead>
<tr>
<th><?php Lang::out('is_new'); ?></th>
<th><?php Lang::out('severity'); ?></th>
<th><?php Lang::out('plugin'); ?></th>
<th><?php Lang::out('file'); ?></th>
<th data-orderable="false"><?php Lang::out('line'); ?></th>
<th data-orderable="false"><?php Lang::out('message'); ?></th>
<th><?= Lang::get('is_new'); ?></th>
<th><?= Lang::get('severity'); ?></th>
<th><?= Lang::get('plugin'); ?></th>
<th><?= Lang::get('file'); ?></th>
<th data-orderable="false"><?= Lang::get('line'); ?></th>
<th data-orderable="false"><?= Lang::get('message'); ?></th>
</tr>
</thead>
<tbody>

View file

@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang;
?>
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('group_add_edit'); ?></h3>
<h3 class="box-title"><?= Lang::get('group_add_edit'); ?></h3>
</div>
<div class="box-body">

View file

@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang;
?>
<div class="clearfix" style="margin-bottom: 20px;">
<a class="btn btn-success pull-right" href="<?= (APP_URL . 'group/edit'); ?>">
<?php Lang::out('group_add'); ?>
<?= Lang::get('group_add'); ?>
</a>
</div>
@ -13,8 +13,8 @@ use PHPCensor\Helper\Lang;
<table class="table table-hover">
<thead>
<tr>
<th><?php Lang::out('group_title'); ?></th>
<th><?php Lang::out('group_count'); ?></th>
<th><?= Lang::get('group_title'); ?></th>
<th><?= Lang::get('group_count'); ?></th>
<th></th>
</tr>
</thead>
@ -25,13 +25,13 @@ use PHPCensor\Helper\Lang;
<td><?= count($group['projects']); ?></td>
<td>
<div class="btn-group btn-group-right">
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>group/edit/<?= $group['id']; ?>"><?php Lang::out('group_edit'); ?></a>
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>group/edit/<?= $group['id']; ?>"><?= Lang::get('group_edit'); ?></a>
<?php if($this->getUser()->getIsAdmin() && (!count($group['projects']))): ?>
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="<?= APP_URL; ?>group/delete/<?= $group['id']; ?>" class="delete-group"><?php Lang::out('group_delete'); ?></a></li>
<li><a href="<?= APP_URL; ?>group/delete/<?= $group['id']; ?>" class="delete-group"><?= Lang::get('group_delete'); ?></a></li>
</ul>
<?php endif; ?>
</div>

View file

@ -11,7 +11,7 @@ use PHPCensor\Model\Build;
<?php if(empty($builds) || !count($builds)): ?>
<tr class="">
<td colspan="6"><?php Lang::out('no_builds_yet'); ?></td>
<td colspan="6"><?= Lang::get('no_builds_yet'); ?></td>
</tr>
<?php endif; ?>
@ -52,7 +52,7 @@ $branches = $build->getExtra('branches');
<td><a href="<?= APP_URL ?>build/view/<?= $build->getId(); ?>">#<?= str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
<td><span class='label label-<?= $subcls ?>'><?= $status ?></span></td>
<td><?= $build->getCreateDate()->format('Y-m-d H:i:s'); ?></td>
<td><?php Lang::out($build->getSourceHumanize()); ?></td>
<td><?= Lang::get($build->getSourceHumanize()); ?></td>
<td class="hidden-md hidden-sm hidden-xs">
<?php
if (!empty($build->getCommitId())) {
@ -100,13 +100,13 @@ $branches = $build->getExtra('branches');
</td>
<td>
<div class="btn-group btn-group-right">
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>"><?php Lang::out('view'); ?></a>
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>"><?= Lang::get('view'); ?></a>
<?php if($this->getUser()->getIsAdmin()): ?>
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="<?= APP_URL; ?>build/delete/<?= $build->getId(); ?>" class="delete-build"><?php Lang::out('delete_build'); ?></a></li>
<li><a href="<?= APP_URL; ?>build/delete/<?= $build->getId(); ?>" class="delete-build"><?= Lang::get('delete_build'); ?></a></li>
</ul>
<?php endif; ?>
</div>

View file

@ -24,7 +24,7 @@
<div class="col-sm-8">
<div class="box ">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('project_details'); ?></h3>
<h3 class="box-title"><?= Lang::get('project_details'); ?></h3>
</div>
<div class="box-body">
@ -37,7 +37,7 @@
<div class="col-sm-4">
<div class="box">
<div class="box-body">
<p><?php Lang::out('public_key_help'); ?></p>
<p><?= Lang::get('public_key_help'); ?></p>
<textarea style="width: 90%; height: 150px;"><?= $key; ?></textarea>
</div>
</div>

View file

@ -17,11 +17,11 @@ use PHPCensor\Helper\Lang;
<div class="clearfix" style="margin-bottom: 20px;">
<a class="btn btn-default" href="<?= APP_URL . 'project/edit/' . $project->getId(); ?>">
<?php Lang::out('edit_project'); ?>
<?= Lang::get('edit_project'); ?>
</a>
<a class="btn btn-danger" id="delete-project">
<?php Lang::out('delete_project'); ?>
<?= Lang::get('delete_project'); ?>
</a>
<?php
@ -32,30 +32,30 @@ use PHPCensor\Helper\Lang;
<?php if ($this->getUser()->getIsAdmin()): ?>
<?php if (!empty($environment)): ?>
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment, 'debug' => 1]); ?>">
<?php Lang::out('build_now_debug'); ?>
<?= Lang::get('build_now_debug'); ?>
</a>
<?php elseif (!empty($branch)): ?>
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'branch', 'id' => $branch, 'debug' => 1]); ?>">
<?php Lang::out('build_now_debug'); ?>
<?= Lang::get('build_now_debug'); ?>
</a>
<?php else: ?>
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['debug' => 1]); ?>">
<?php Lang::out('build_now_debug'); ?>
<?= Lang::get('build_now_debug'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
<?php if (!empty($environment)): ?>
<a class="btn btn-success" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment]); ?>">
<?php Lang::out('build_now'); ?>
<?= Lang::get('build_now'); ?>
</a>
<?php elseif (!empty($branch)): ?>
<a class="btn btn-success" href="<?= $build_url . '?' . http_build_query(['type' => 'branch', 'id' => $branch]); ?>">
<?php Lang::out('build_now'); ?>
<?= Lang::get('build_now'); ?>
</a>
<?php else: ?>
<a class="btn btn-success" href="<?= $build_url; ?>">
<?php Lang::out('build_now'); ?>
<?= Lang::get('build_now'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
@ -63,16 +63,16 @@ use PHPCensor\Helper\Lang;
<div class="btn-group branch-btn pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<?php if (!empty($environment)) {
Lang::out('environment_x', $environment);
echo Lang::get('environment_x', $environment);
} elseif (!empty($branch)) {
Lang::out('branch_x', $branch);
echo Lang::get('branch_x', $branch);
} else {
Lang::out('all');
echo Lang::get('all');
} ?>&nbsp;&nbsp;<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>"><?php Lang::out('all'); ?></a></li>
<li><a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>"><?= Lang::get('all'); ?></a></li>
<li class="divider"></li>
<?php if(!empty($environments)): ?>
@ -103,20 +103,20 @@ use PHPCensor\Helper\Lang;
<div class="col-lg-9 col-md-8 col-sm-8">
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('builds'); ?> (<?= $total; ?>)</h3>
<h3 class="box-title"><?= Lang::get('builds'); ?> (<?= $total; ?>)</h3>
</div>
<table class="table table-hover">
<thead>
<tr>
<th><?php Lang::out('id'); ?></th>
<th><?php Lang::out('status'); ?></th>
<th><?php Lang::out('date'); ?></th>
<th><?php Lang::out('build_source'); ?></th>
<th class="hidden-md hidden-sm hidden-xs"><?php Lang::out('commit'); ?></th>
<th><?php Lang::out('branch'); ?></th>
<th><?php Lang::out('environment'); ?></th>
<th><?php Lang::out('duration'); ?></th>
<th><?php Lang::out('new_errors'); ?></th>
<th><?= Lang::get('id'); ?></th>
<th><?= Lang::get('status'); ?></th>
<th><?= Lang::get('date'); ?></th>
<th><?= Lang::get('build_source'); ?></th>
<th class="hidden-md hidden-sm hidden-xs"><?= Lang::get('commit'); ?></th>
<th><?= Lang::get('branch'); ?></th>
<th><?= Lang::get('environment'); ?></th>
<th><?= Lang::get('duration'); ?></th>
<th><?= Lang::get('new_errors'); ?></th>
<th></th>
</tr>
</thead>
@ -162,7 +162,7 @@ use PHPCensor\Helper\Lang;
<?php if (in_array($project->getType(), ['github', 'gitlab', 'bitbucket'])): ?>
<div class="box">
<div class="box-header">
<h4 class="box-title"><?php Lang::out('webhooks'); ?></h4>
<h4 class="box-title"><?= Lang::get('webhooks'); ?></h4>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i>
@ -174,18 +174,18 @@ use PHPCensor\Helper\Lang;
<?php switch($project->getType()) {
case 'github':
$url = APP_URL . 'webhook/github/' . $project->getId();
Lang::out('webhooks_help_github', $project->getReference());
echo Lang::get('webhooks_help_github', $project->getReference());
break;
case 'gitlab':
$url = APP_URL. 'webhook/gitlab/' . $project->getId();
Lang::out('webhooks_help_gitlab');
echo Lang::get('webhooks_help_gitlab');
break;
case 'bitbucket':
case 'bitbucket-hg':
$url = APP_URL . 'webhook/bitbucket/' . $project->getId();
Lang::out('webhooks_help_bitbucket', $project->getReference());
echo Lang::get('webhooks_help_bitbucket', $project->getReference());
break;
} ?>
<br><br><strong style="word-wrap: break-word;"><?= $url; ?></strong>
@ -196,7 +196,7 @@ use PHPCensor\Helper\Lang;
<?php if ($project->getSshPublicKey()): ?>
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('public_key'); ?></h3>
<h3 class="box-title"><?= Lang::get('public_key'); ?></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i>

View file

@ -1,12 +1,12 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php if (isset($emailed)): ?>
<p class="alert alert-success" style="margin-bottom: 0">
<?php Lang::out('reset_emailed'); ?>
<?= Lang::get('reset_emailed'); ?>
</p>
<?php else: ?>
<?php if (empty($error)): ?>
<div class="" style="margin-bottom: 15px;">
<?php Lang::out('reset_header'); ?>
<?= Lang::get('reset_header'); ?>
</div>
<?php else: ?>
<div class="alert alert-danger">
@ -16,12 +16,12 @@
<div class="">
<form class="form" action="<?= APP_URL; ?>session/forgot-password" method="POST">
<div class="form-group">
<label for="email"><?php Lang::out('reset_email_address'); ?></label>
<label for="email"><?= Lang::get('reset_email_address'); ?></label>
<input id="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" value="<?php Lang::out('reset_send_email'); ?>">
<input class="btn btn-success" type="submit" value="<?= Lang::get('reset_send_email'); ?>">
</div>
</form>
</div>

View file

@ -1,9 +1,9 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php if($failed): ?>
<p class="alert alert-danger"><?php Lang::out('login_error'); ?></p>
<p class="alert alert-danger"><?= Lang::get('login_error'); ?></p>
<?php endif; ?>
<?= $form; ?>
<a style="margin-top: -22px;" class="pull-right" href="<?= APP_URL; ?>session/forgot-password">
<?php Lang::out('forgotten_password_link'); ?>
<?= Lang::get('forgotten_password_link'); ?>
</a>

View file

@ -1,18 +1,18 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php if (empty($error)): ?>
<div class="box-header">
<?php Lang::out('reset_enter_password'); ?>
<?= Lang::get('reset_enter_password'); ?>
</div>
<div class="box-body">
<form class="form" action="<?= APP_URL; ?>session/reset-password/<?= $id; ?>/<?= $key; ?>" method="POST">
<div class="form-group">
<label for="password"><?php Lang::out('reset_new_password'); ?></label>
<label for="password"><?= Lang::get('reset_new_password'); ?></label>
<input type="password" id="password" name="password" class="form-control" required>
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" value="<?php Lang::out('reset_change_password'); ?>">
<input class="btn btn-success" type="submit" value="<?= Lang::get('reset_change_password'); ?>">
</div>
</form>
</div>

View file

@ -7,7 +7,7 @@ $user = $this->getUser();
?>
<div class="clearfix" style="margin-bottom: 20px;">
<div class="pull-right btn-group">
<a class="btn btn-success" href="<?= APP_URL; ?>user/add"><?php Lang::out('add_user'); ?></a>
<a class="btn btn-success" href="<?= APP_URL; ?>user/add"><?= Lang::get('add_user'); ?></a>
</div>
</div>
@ -18,9 +18,9 @@ $user = $this->getUser();
<table class="table table-hover">
<thead>
<tr>
<th><?php Lang::out('email_address'); ?></th>
<th><?php Lang::out('name'); ?></th>
<th><?php Lang::out('is_admin'); ?></th>
<th><?= Lang::get('email_address'); ?></th>
<th><?= Lang::get('name'); ?></th>
<th><?= Lang::get('is_admin'); ?></th>
<th></th>
</tr>
</thead>
@ -47,12 +47,12 @@ $user = $this->getUser();
<td>
<?php if($user->getIsAdmin()): ?>
<div class="btn-group btn-group-right">
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>user/edit/<?= $user->getId(); ?>"><?php Lang::out('edit'); ?></a>
<a class="btn btn-default btn-sm" href="<?= APP_URL; ?>user/edit/<?= $user->getId(); ?>"><?= Lang::get('edit'); ?></a>
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="<?= APP_URL; ?>user/delete/<?= $user->getId(); ?>" class="delete-user"><?php Lang::out('delete_user'); ?></a></li>
<li><a href="<?= APP_URL; ?>user/delete/<?= $user->getId(); ?>" class="delete-user"><?= Lang::get('delete_user'); ?></a></li>
</ul>
</div>
<?php endif; ?>

View file

@ -4,12 +4,12 @@ use PHPCensor\Helper\Lang;
?>
<?php if (isset($updated)): ?>
<p class="alert alert-success"><?php Lang::out('your_details_updated'); ?></p>
<p class="alert alert-success"><?= Lang::get('your_details_updated'); ?></p>
<?php endif; ?>
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('update_your_details'); ?></h3>
<h3 class="box-title"><?= Lang::get('update_your_details'); ?></h3>
</div>
<div class="box-body">
<?= $form; ?>

View file

@ -112,7 +112,7 @@ foreach($projects as $project):
<i class="fa fa-lock"></i>
<?php endif; ?>
</div>
<?php Lang::out('view_project'); ?> (<?= $counts[$project->getId()]; ?>) <i class="fa fa-arrow-circle-right"></i>
<?= Lang::get('view_project'); ?> (<?= $counts[$project->getId()]; ?>) <i class="fa fa-arrow-circle-right"></i>
</a>
<?php for ($idx=0; $idx < 5; $idx++) {

View file

@ -111,7 +111,7 @@ if ($buildCount > 0) {
<i class="fa fa-lock"></i>
<?php endif; ?>
</div>
<?php Lang::out('view_project'); ?> (<?= $counts; ?>) <i class="fa fa-arrow-circle-right"></i>
<?= Lang::get('view_project'); ?> (<?= $counts; ?>) <i class="fa fa-arrow-circle-right"></i>
</a>
<?php for ($idx=0; $idx < 5; $idx++) {

View file

@ -2,4 +2,4 @@
use PHPCensor\Helper\Lang;
?><div class=""><?= Lang::out('no_build_errors') ?></div>
?><div class=""><?= Lang::get('no_build_errors') ?></div>

View file

@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang;
?>
<div class="box">
<div class="box-header">
<h3 class="box-title"><?= Lang::out('projects_with_build_errors') ?></h3>
<h3 class="box-title"><?= Lang::get('projects_with_build_errors') ?></h3>
</div>
<div class="box-body" id="dashboard-build-errors">
<?= $projects ?>

View file

@ -99,7 +99,7 @@ foreach($builds as $project_id => $project_envs):
<?= $project->getTitle(); ?>
</a>
<?php if (!empty($environment)) { ?>
<sup title="<?php Lang::out('environment'); ?>"><?= $environment ?></sup>
<sup title="<?= Lang::get('environment'); ?>"><?= $environment ?></sup>
<?php } ?>
</h3>
@ -119,7 +119,7 @@ foreach($builds as $project_id => $project_envs):
<i class="fa fa-lock"></i>
<?php endif; ?>
</div>
<?php Lang::out('view_project'); ?> <i class="fa fa-arrow-circle-right"></i>
<?= Lang::get('view_project'); ?> <i class="fa fa-arrow-circle-right"></i>
</a>
<?php for ($idx=0; $idx < 5; $idx++) {

View file

@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang;
?>
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php Lang::out('latest_builds'); ?></h3>
<h3 class="box-title"><?= Lang::get('latest_builds'); ?></h3>
</div>
<div class="box-body" id="timeline-box">
<?= $timeline ?>

View file

@ -75,13 +75,13 @@ use PHPCensor\Model\Build;
<span><?= $environment; ?></span>
&mdash;
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>">
<?php Lang::out('build'); ?> #<?= $build->getId(); ?>
<?= Lang::get('build'); ?> #<?= $build->getId(); ?>
</a>
&mdash;
<?php Lang::out($build->getSourceHumanize()); ?>
<?= Lang::get($build->getSourceHumanize()); ?>
<?php if ($newErrorsCount = $build->getNewErrorsCount()): ?>
&mdash;
<?php Lang::out('new_errors'); ?>:
<?= Lang::get('new_errors'); ?>:
<?= $newErrorsCount; ?>
<?php endif; ?>
</h3>

View file

@ -39,9 +39,9 @@ $user = $this->getUser();
var LANGUAGE = '<?= Lang::getLanguage(); ?>';
<?php if (defined('JSON_UNESCAPED_UNICODE')): ?>
var STRINGS = <?= json_encode(Lang::getStrings(), JSON_UNESCAPED_UNICODE); ?>;
var STRINGS = <?= json_encode(Lang::getStrings(), JSON_UNESCAPED_UNICODE); ?>;
<?php else: ?>
var STRINGS = <?= json_encode(Lang::getStrings()); ?>;
var STRINGS = <?= json_encode(Lang::getStrings()); ?>;
<?php endif; ?>
</script>
@ -58,7 +58,7 @@ $user = $this->getUser();
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only"><?php Lang::out('toggle_navigation'); ?></span>
<span class="sr-only"><?= Lang::get('toggle_navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@ -72,7 +72,7 @@ $user = $this->getUser();
<span class="label label-info app-pending-count"></span>
</a>
<ul class="dropdown-menu">
<li class="header"><?php Lang::out('n_builds_pending', 0); ?></li>
<li class="header"><?= Lang::get('n_builds_pending', 0); ?></li>
<li>
<ul class="menu app-pending-list">
</ul>
@ -86,7 +86,7 @@ $user = $this->getUser();
<span class="label label-warning app-running-count"></span>
</a>
<ul class="dropdown-menu">
<li class="header"><?php Lang::out('n_builds_running', 0); ?></li>
<li class="header"><?= Lang::get('n_builds_running', 0); ?></li>
<li>
<ul class="menu app-running-list">
</ul>
@ -113,10 +113,10 @@ $user = $this->getUser();
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">
<a href="<?= APP_URL; ?>user/profile" class="btn btn-default btn-flat"><?php Lang::out('edit_profile'); ?></a>
<a href="<?= APP_URL; ?>user/profile" class="btn btn-default btn-flat"><?= Lang::get('edit_profile'); ?></a>
</div>
<div class="pull-right">
<a href="<?= APP_URL; ?>session/logout" class="btn btn-default btn-flat"><?php Lang::out('sign_out'); ?></a>
<a href="<?= APP_URL; ?>session/logout" class="btn btn-default btn-flat"><?= Lang::get('sign_out'); ?></a>
</div>
</li>
</ul>
@ -138,7 +138,7 @@ $user = $this->getUser();
<img src="https://www.gravatar.com/avatar/<?= md5($user->getEmail()); ?>?d=mm" class="img-circle" alt="<?= $user->getName(); ?>" />
</div>
<div class="pull-left info">
<p><?php Lang::out('hello_name', $user->getName()); ?></p>
<p><?= Lang::get('hello_name', $user->getName()); ?></p>
</div>
</div>
<?php endif; ?>
@ -147,7 +147,7 @@ $user = $this->getUser();
<ul class="sidebar-menu">
<li<?= (array_key_exists('archived', $_GET) ? '' : ' class="active"'); ?>>
<a href="<?= APP_URL; ?>">
<i class="fa fa-dashboard"></i> <span><?php Lang::out('dashboard'); ?></span>
<i class="fa fa-dashboard"></i> <span><?= Lang::get('dashboard'); ?></span>
</a>
</li>
@ -155,23 +155,23 @@ $user = $this->getUser();
<li class="treeview">
<a href="#">
<i class="fa fa-edit"></i>
<span><?php Lang::out('admin_options'); ?></span>
<span><?= Lang::get('admin_options'); ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="<?= APP_URL; ?>project/add">
<i class="fa fa-angle-double-right"></i> <?php Lang::out('add_project'); ?>
<i class="fa fa-angle-double-right"></i> <?= Lang::get('add_project'); ?>
</a>
</li>
<li>
<a href="<?= APP_URL; ?>group">
<i class="fa fa-angle-double-right"></i> <?php Lang::out('project_groups'); ?>
<i class="fa fa-angle-double-right"></i> <?= Lang::get('project_groups'); ?>
</a>
</li>
<li>
<a href="<?= APP_URL; ?>user">
<i class="fa fa-angle-double-right"></i> <?php Lang::out('manage_users'); ?>
<i class="fa fa-angle-double-right"></i> <?= Lang::get('manage_users'); ?>
</a>
</li>
</ul>
@ -204,7 +204,7 @@ $user = $this->getUser();
<li class="treeview">
<a href="#">
<i class="fa fa-archive"></i> <span><?php Lang::out('archived_menu'); ?></span>
<i class="fa fa-archive"></i> <span><?= Lang::get('archived_menu'); ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>

View file

@ -2,7 +2,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php Lang::out('log_in_to_app'); ?></title>
<title><?= Lang::get('log_in_to_app'); ?></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View file

@ -3,6 +3,7 @@
namespace Tests\PHPCensor\Command;
use PHPCensor\Command\CreateBuildCommand;
use PHPCensor\Exception\InvalidArgumentException;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
@ -68,7 +69,7 @@ class CreateBuildCommandTest extends \PHPUnit\Framework\TestCase
}
/**
* @expectedException \InvalidArgumentException
* @expectedException InvalidArgumentException
*/
public function testExecuteWithUnknownProjectId()
{

View file

@ -73,14 +73,4 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
self::assertTrue($ex->getStatusMessage() == 'Internal Server Error');
}
}
public function testValidationException()
{
try {
throw new HttpException\ValidationException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 400);
self::assertTrue($ex->getStatusMessage() == 'Bad Request');
}
}
}

View file

@ -81,7 +81,7 @@ class BuildTest extends TestCase
$result = $build->setStatus(Build::STATUS_FAILED);
self::assertEquals(false, $result);
self::expectException('\PHPCensor\Exception\HttpException\ValidationException');
self::expectException('\PHPCensor\Exception\InvalidArgumentException');
$build->setStatus(10);
}
@ -230,7 +230,7 @@ class BuildTest extends TestCase
$result = $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST);
self::assertEquals(false, $result);
self::expectException('\PHPCensor\Exception\HttpException\ValidationException');
self::expectException('\PHPCensor\Exception\InvalidArgumentException');
$build->setSource(20);
}

View file

@ -138,7 +138,7 @@ class ProjectTest extends TestCase
$result = $project->setType('git');
self::assertEquals(false, $result);
self::expectException('\PHPCensor\Exception\HttpException\ValidationException');
self::expectException('\PHPCensor\Exception\InvalidArgumentException');
$project->setType('invalid-type');
}

View file

@ -2,7 +2,7 @@
namespace Tests\PHPCensor\Model;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Model\Build;
/**
@ -49,7 +49,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase
'branch' => 'dev',
'unknown' => 'unknown',
]);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'Model "PHPCensor\Model\Build" doesn\'t have field "unknown"',
$e->getMessage()
@ -65,7 +65,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase
try {
$build->setLog([]);
} catch (ValidationException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'Column "log" must be a string.',
$e->getMessage()
@ -77,7 +77,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase
try {
$build->setSource('5');
} catch (ValidationException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'Column "source" must be an integer.',
$e->getMessage()
@ -86,7 +86,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase
try {
$build->setId(null);
} catch (ValidationException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'Column "id" must not be null.',
$e->getMessage()

View file

@ -2,7 +2,7 @@
namespace Tests\PHPCensor\Model;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Model\Project;
use PHPCensor\Model;
@ -20,7 +20,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
try {
$project->setArchived('true');
} catch (ValidationException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'Column "archived" must be a boolean.',
$e->getMessage()

View file

@ -34,13 +34,15 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
public function testRegisterResourceThrowsExceptionWithoutTypeAndName()
{
$this->setExpectedException('InvalidArgumentException', 'Type or Name must be specified');
self::expectException('\PHPCensor\Exception\InvalidArgumentException');
self::expectExceptionMessage('Type or Name must be specified');
$this->testedFactory->registerResource($this->resourceLoader, null, null);
}
public function testRegisterResourceThrowsExceptionIfLoaderIsntFunction()
{
$this->setExpectedException('InvalidArgumentException', '$loader is expected to be a function');
self::expectException('\PHPCensor\Exception\InvalidArgumentException');
self::expectExceptionMessage('$loader is expected to be a function');
$this->testedFactory->registerResource(["dummy"], "TestName", "TestClass");
}
@ -53,10 +55,8 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
public function testBuildPluginThrowsExceptionIfMissingResourcesForRequiredArg()
{
$this->setExpectedException(
'DomainException',
'Unsatisfied dependency: requiredArgument'
);
self::expectException('\DomainException');
self::expectExceptionMessage('Unsatisfied dependency: requiredArgument');
$pluginClass = $this->getFakePluginClassName('ExamplePluginWithSingleRequiredArg');
$plugin = $this->testedFactory->buildPlugin($pluginClass);

View file

@ -4,6 +4,7 @@ namespace Tests\PHPCensor;
use PHPCensor\Config;
use PHPCensor\Database;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Store\Factory;
use PHPCensor\Model\Project;
use PHPCensor\Model\ProjectGroup;
@ -177,7 +178,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase
try {
$data = $testStore->getWhere(['' => 0], 100, 0, ['id' => 'ASC']);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals('You cannot have an empty field name.', $e->getMessage());
}
@ -233,7 +234,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase
$model->setId(1);
$testStore->save($model);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'PHPCensor\Model\Project is an invalid model type for this store.',
$e->getMessage()
@ -258,7 +259,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase
$model->setId(1);
$testStore->delete($model);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'PHPCensor\Model\Project is an invalid model type for this store.',
$e->getMessage()

View file

@ -4,6 +4,7 @@ namespace Tests\PHPCensor;
use PHPCensor\Config;
use PHPCensor\Database;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Store\Factory;
use PHPCensor\Model\Project;
use PHPCensor\Model\ProjectGroup;
@ -164,7 +165,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase
try {
$data = $testStore->getWhere(['' => 0], 100, 0, ['id' => 'ASC']);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals('You cannot have an empty field name.', $e->getMessage());
}
@ -228,7 +229,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase
$model->setId(1);
$testStore->save($model);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'PHPCensor\Model\Project is an invalid model type for this store.',
$e->getMessage()
@ -253,7 +254,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase
$model->setId(1);
$testStore->delete($model);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
self::assertEquals(
'PHPCensor\Model\Project is an invalid model type for this store.',
$e->getMessage()

View file

@ -29,11 +29,4 @@ class ViewTest extends \PHPUnit\Framework\TestCase
self::assertFalse(isset($view->what));
self::assertTrue($view->render() == 'Hello World');
}
public function testUserViewVars()
{
$view = new View('{@content}');
$view->content = 'World';
self::assertTrue($view->render() == 'World');
}
}