Skip to content

Commit

Permalink
Merge pull request #1488 from phalcon/review-tests
Browse files Browse the repository at this point in the history
Review tests
  • Loading branch information
Jeckerson authored Mar 14, 2021
2 parents bb1c795 + 56c27d9 commit 94d96c9
Show file tree
Hide file tree
Showing 33 changed files with 186 additions and 136 deletions.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
},
"autoload-dev": {
"psr-4": {
"Phalcon\\Test\\": "tests/unit",
"Phalcon\\Test\\Models\\": "tests/_data/models",
"Phalcon\\Test\\Module\\": "tests/_support/Module"
"Phalcon\\DevTools\\Tests\\Acceptance\\": "tests/acceptance/",
"Phalcon\\DevTools\\Tests\\Console\\": "tests/console/",
"Phalcon\\DevTools\\Tests\\Functional\\": "tests/functional/",
"Phalcon\\DevTools\\Tests\\Unit\\": "tests/unit/",
"Phalcon\\DevTools\\Tests\\Support\\Module\\": "tests/_support/Module"
},
"files": [
"tests/_support/helpers.php"
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/Options/OptionsAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class OptionsAware implements FactoryOptions
/**
* @param array $options
*/
public function __construct(array $options = null)
public function __construct(array $options = [])
{
if (!empty($options)) {
$this->options = $options;
}
$this->options = $options;
}

/**
Expand Down Expand Up @@ -110,7 +108,7 @@ public function getOptions(): array
public function getOption($key)
{
if (!isset($this->options[$key])) {
throw new InvalidArgumentException("Option " . $key . " has't been defined");
throw new InvalidArgumentException("Option " . $key . " hasn't been defined");
}

return $this->options[$key];
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/AnnotationsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AnnotationsProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new AnnotationsMemory;
return new AnnotationsMemory();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/AssetsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AssetsProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new AssetsManager;
return new AssetsManager();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/AssetsResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AssetsResourceProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new AssetsResource;
return new AssetsResource();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/DatabaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function register(DiInterface $di): void
if ($this->getShared('config')->offsetExists('database')) {
$config = $this->getShared('config')->get('database')->toArray();
} else {
$dbname = sys_get_temp_dir() . DS . 'phalcon.sqlite';
$dbname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phalcon.sqlite';
$this->getShared('logger')->warning(
'Unable to initialize "db" service. Used Sqlite adapter at path: {path}',
['path' => $dbname]
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/DbUtilsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DbUtilsProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new DbUtils;
return new DbUtils();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/DispatcherProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function register(DiInterface $di): void
$access = $di->getShared('access');

$di->setShared($this->providerName, function () use ($eventsManager, $access) {
$dispatcher = new MvcDispatcher;
$dispatcher = new MvcDispatcher();
$dispatcher->setDefaultNamespace('Phalcon\DevTools\Web\Tools\Controllers');

$eventsManager->attach('dispatch', $access, 1000);
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/EventsManagerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EventsManagerProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
$em = new EventsManager;
$em = new EventsManager();
$em->enablePriorities(true);

return $em;
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/FileSystemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FileSystemProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new FsUtils;
return new FsUtils();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/LoggerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function register(DiInterface $di): void
$basePath = $application->getBasePath();

$di->setShared($this->providerName, function () use ($hostName, $basePath) {
$ptoolsPath = $basePath . DS . '.phalcon' . DS;
$ptoolsPath = $basePath . DIRECTORY_SEPARATOR . '.phalcon' . DIRECTORY_SEPARATOR;
if (is_dir($ptoolsPath) && is_writable($ptoolsPath)) {
$formatter = new LineFormatter("%date% {$hostName} php: [%type%] %message%", 'D j H:i:s');
$adapter = new FileLogger($ptoolsPath . 'devtools.log');
Expand Down
3 changes: 2 additions & 1 deletion src/Providers/SessionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class SessionProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
$session = new Manager();
$files = new SessionStream([
'savePath' => sys_get_temp_dir(),
]);

$session = new Manager();
$session->setAdapter($files);
$session->start();

Expand Down
2 changes: 1 addition & 1 deletion src/Providers/SystemInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SystemInfoProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
return new SystemInfo;
return new SystemInfo();
});
}
}
2 changes: 1 addition & 1 deletion src/Providers/TagProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TagProvider implements ServiceProviderInterface
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
$tag = new Tag;
$tag = new Tag();

$tag->setDocType(Tag::HTML5);
$tag->setTitleSeparator(' :: ');
Expand Down
14 changes: 7 additions & 7 deletions src/Providers/UrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ public function register(DiInterface $di): void
/** @var DiInterface $this */
$config = $this->getShared('config');

$url = new UrlResolver;
$url = new UrlResolver();

if ($config->get('application', new Config)->offsetExists('baseUri')) {
$baseUri = $config->get('application', new Config)->get('baseUri');
if ($config->get('application', new Config())->offsetExists('baseUri')) {
$baseUri = $config->get('application', new Config())->get('baseUri');
} elseif ($config->offsetExists('baseUri')) {
$baseUri = $config->get('baseUri');
} else {
// @todo Log notice here
// TODO: Log notice here
$baseUri = '/';
}

if ($config->get('application', new Config)->offsetExists('staticUri')) {
$staticUri = $config->get('application', new Config)->get('staticUri');
if ($config->get('application', new Config())->offsetExists('staticUri')) {
$staticUri = $config->get('application', new Config())->get('staticUri');
} elseif ($config->offsetExists('staticUri')) {
$staticUri = $config->get('staticUri');
} else {
// @todo Log notice here
// TODO: Log notice here
$staticUri = '/';
}

Expand Down
6 changes: 3 additions & 3 deletions src/Providers/ViewProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function register(DiInterface $di): void

$view->registerEngines([
'.volt' => $this->getShared('volt', [$view, $this]),
'.phtml' => Php::class
'.phtml' => Php::class,
]);

$view->setViewsDir($registry->offsetGet('directories')->webToolsViews . DS)
->setLayoutsDir('layouts' . DS)
$view->setViewsDir($registry->offsetGet('directories')->webToolsViews . DIRECTORY_SEPARATOR)
->setLayoutsDir('layouts' . DIRECTORY_SEPARATOR)
->setRenderLevel(View::LEVEL_AFTER_TEMPLATE);

$em = $this->getShared('eventsManager');
Expand Down
12 changes: 6 additions & 6 deletions src/Providers/VoltProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function register(DiInterface $di): void
$config = $this->getShared('config');

$appCacheDir = $config->get('application', new Config)->get('cacheDir');
$defaultCacheDir = sys_get_temp_dir() . DS . 'phalcon' . DS . 'volt';
$defaultCacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phalcon' . DIRECTORY_SEPARATOR . 'volt';

/** @var Config $voltConfig */
$voltConfig = null;
Expand Down Expand Up @@ -80,8 +80,8 @@ public function register(DiInterface $di): void
*/
if (0 === strpos($templatePath, $basePath)) {
$templatePath = substr($templatePath, strlen($basePath));
} elseif (0 === strpos($templatePath, $ptoolsPath . DS . 'src')) {
$templatePath = substr($templatePath, strlen($ptoolsPath . DS . 'src'));
} elseif (0 === strpos($templatePath, $ptoolsPath . DIRECTORY_SEPARATOR . 'src')) {
$templatePath = substr($templatePath, strlen($ptoolsPath . DIRECTORY_SEPARATOR . 'src'));
}

$templatePath = trim($templatePath, '\\/');
Expand All @@ -90,7 +90,7 @@ public function register(DiInterface $di): void

$cacheDir = $that->getCacheDir($voltConfig);

return rtrim($cacheDir, '\\/') . DS . $filename;
return rtrim($cacheDir, '\\/') . DIRECTORY_SEPARATOR . $filename;
};

$options = [
Expand All @@ -112,11 +112,11 @@ public function register(DiInterface $di): void
*
* @return string
*/
protected function getCacheDir(Config $voltConfig)
protected function getCacheDir(Config $voltConfig): string
{
$appCacheDir = $this->di->getShared('config')->path('application.cacheDir');
$cacheDir = $voltConfig->get('cacheDir', $appCacheDir);
$defaultCacheDir = sys_get_temp_dir() . DS . 'phalcon' . DS . 'volt';
$defaultCacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phalcon' . DIRECTORY_SEPARATOR . 'volt';

if ($cacheDir && is_dir($cacheDir) && is_writable($cacheDir)) {
return $cacheDir;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/AssetsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class AssetsResource extends Injectable
*/
public function path(string $path): string
{
return PTOOLSPATH . DS . 'resources' . DS . $this->fs->normalize($path);
return PTOOLSPATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . $this->fs->normalize($path);
}
}
6 changes: 3 additions & 3 deletions src/Scanners/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public function __construct($basePath)
* @param string $filename The config basename.
* @return null|PhConfig
*/
public function scan($filename): ?PhConfig
public function scan(string $filename): ?PhConfig
{
$config = null;
$filename = pathinfo($filename, PATHINFO_FILENAME);

foreach ($this->getConfigPaths() as $probablyPath) {
foreach ($this->configAdapters as $ext => $adapter) {
$probablyConfig = $probablyPath . DS . "{$filename}.{$ext}";
$probablyConfig = $probablyPath . DIRECTORY_SEPARATOR . "{$filename}.{$ext}";

if (is_file($probablyConfig) && is_readable($probablyConfig)) {
if (in_array($ext, ['php', 'php5', 'inc'])) {
Expand Down Expand Up @@ -102,7 +102,7 @@ public function scan($filename): ?PhConfig
* @return PhConfig
* @throws Exception
*/
public function load($filename): PhConfig
public function load(string $filename): PhConfig
{
$config = $this->scan($filename);

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/DbUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public function resolveDbSchema(): ?string
return $config->get('schema');
}

if ('Postgresql' == $config->get('adapter')) {
if ('Postgresql' === $config->get('adapter')) {
return 'public';
}

if ('Sqlite' == $config->get('adapter')) {
if ('Sqlite' === $config->get('adapter')) {
// SQLite only supports the current database, unless one is
// attached. This is not the case, so don't return a schema.
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validator/Namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function validate(Validation $validation, $field): bool

$re = '#^(?:(?:\\\)?[a-z](?:[a-z0-9_]+)?)+(?:\\\\(?:[a-z](?:[a-z0-9_]+)?)+)*$#i';
if (false === (bool)preg_match($re, $value)) {
if (!preg_match($re, $value)) {
$label = $this->getOption('label') ?: $validation->getLabel($field);
$message = $this->getOption('message') ?: 'Invalid namespace syntax!';
$replacePairs = array(':field' => $label);
Expand Down
22 changes: 11 additions & 11 deletions src/Web/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class Tools
public static function install(string $path): void
{
$fsUtils = new FsUtils();
$path = $fsUtils->normalize(realpath($path)) . DS;
$publicPath = $path . self::PROJECT_PUBLIC_FOLDER . DS;
$path = $fsUtils->normalize(realpath($path)) . DIRECTORY_SEPARATOR;
$publicPath = $path . self::PROJECT_PUBLIC_FOLDER . DIRECTORY_SEPARATOR;

$root = new SplFileInfo($publicPath);
$fsUtils->setDirectoryPermission($root, ['js' => 0777, 'css' => 0777]);

$tools = rtrim(str_replace(["\\", '/'], DS, PTOOLSPATH), DS);
$tools = rtrim(str_replace(["\\", '/'], DIRECTORY_SEPARATOR, PTOOLSPATH), DIRECTORY_SEPARATOR);

copy($tools . DS . self::WEB_TOOLS_FILE, $publicPath . self::WEB_TOOLS_FILE);
copy($tools . DIRECTORY_SEPARATOR . self::WEB_TOOLS_FILE, $publicPath . self::WEB_TOOLS_FILE);

if (!file_exists($configPath = $publicPath . self::WEB_TOOLS_CONFIG_FILE)) {
$template = file_get_contents(TEMPLATE_PATH . DS . self::WEB_TOOLS_CONFIG_FILE);
$template = file_get_contents(TEMPLATE_PATH . DIRECTORY_SEPARATOR . self::WEB_TOOLS_CONFIG_FILE);
$code = str_replace('@@PATH@@', $tools, $template);

file_put_contents($configPath, $code);
Expand All @@ -59,16 +59,16 @@ public static function install(string $path): void
* @return void
* @throws Exception
*/
public static function uninstall($path): void
public static function uninstall(string $path): void
{
$fsUtils = new FsUtils();
$path = $fsUtils->normalize(realpath($path)) . DS;
$path = $fsUtils->normalize(realpath($path)) . DIRECTORY_SEPARATOR;

$root = new SplFileInfo($path . self::PROJECT_PUBLIC_FOLDER . DS);
$root = new SplFileInfo($path . self::PROJECT_PUBLIC_FOLDER . DIRECTORY_SEPARATOR);
$fsUtils->deleteFilesFromDirectory($root, [
'css' . DS . 'webtools.css',
'js' . DS . 'webtools.js',
'js' . DS . 'webtools-ie.js',
'css' . DIRECTORY_SEPARATOR . 'webtools.css',
'js' . DIRECTORY_SEPARATOR . 'webtools.js',
'js' . DIRECTORY_SEPARATOR . 'webtools-ie.js',
self::WEB_TOOLS_CONFIG_FILE,
self::WEB_TOOLS_FILE,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Module/UnitTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Phalcon\Test\Module;
namespace Phalcon\DevTools\Tests\Support\Module;

use Codeception\Specify;
use Codeception\Test\Unit;
Expand Down
Loading

0 comments on commit 94d96c9

Please sign in to comment.