Removed hacks for Windows OS (Because it isn't work fine all the same)

This commit is contained in:
Dmitry Khomutov 2017-02-01 22:27:47 +07:00
parent 7e735bbb3b
commit 8779880a8f
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
23 changed files with 36 additions and 240 deletions

View file

@ -15,6 +15,19 @@ PHP Censor
More [screenshots](docs/en/screenshots.md).
System requirements
-------------------
* Unix-like OS (**Windows isn't supported**)
* PHP 5.6+ (with OpenSSL support and enabled functions: `exec()`, `shell_exec()` and `proc_open()`)
* Web-server (Nginx or Apache2)
* Database (MySQL/MariaDB or PostgreSQL)
* Beanstalkd queue (Optional)
Features
--------
@ -72,9 +85,6 @@ More details about [configuring project](docs/en/config.md).
Installing
----------
You will need PHP 5.6+ (with OpenSSL support and enabled functions: `exec()`, `shell_exec()` and `proc_open()`)
with web-server (Nginx or Apache2), DB (MySQL/MariaDB or PostgreSQL) database and Composer.
* Go to the directory in which you want to install PHP Censor, for example: `/var/www`;
* Download PHP Censor from this repository and unzip it (to `/var/www/php-censor.local` for example);

View file

@ -31,10 +31,6 @@ if (!defined('RUNTIME_DIR')) {
define('RUNTIME_DIR', ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR);
}
if (!defined('IS_WIN')) {
define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false));
}
require_once(ROOT_DIR . 'vendor/autoload.php');
// Load configuration if present:

View file

@ -113,11 +113,7 @@ class Builder implements LoggerAwareInterface
$pluginFactory = $this->buildPluginFactory($build);
$this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger);
$executorClass = 'PHPCensor\Helper\UnixCommandExecutor';
if (IS_WIN) {
$executorClass = 'PHPCensor\Helper\WindowsCommandExecutor';
}
$executorClass = 'PHPCensor\Helper\UnixCommandExecutor';
$this->commandExecutor = new $executorClass(
$this->buildLogger,
ROOT_DIR,

View file

@ -22,16 +22,7 @@ class SshKey
public function generate()
{
$tempPath = sys_get_temp_dir() . '/';
// FastCGI fix for Windows machines, where temp path is not available to
// PHP, and defaults to the unwritable system directory. If the temp
// path is pointing to the system directory, shift to the 'TEMP'
// sub-folder, which should also exist, but actually be writable.
if (IS_WIN && $tempPath == getenv("SystemRoot") . '/') {
$tempPath = getenv("SystemRoot") . '/TEMP/';
}
$keyFile = $tempPath . md5(microtime(true));
$keyFile = $tempPath . md5(microtime(true));
if (!is_dir($tempPath)) {
mkdir($tempPath);

View file

@ -1,30 +0,0 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCensor\Helper;
/**
* Windows-specific extension of the CommandExecutor class.
* @package PHPCensor\Helper
*/
class WindowsCommandExecutor extends BaseCommandExecutor
{
/**
* Use 'where' on Windows to find a binary, rather than 'which'
* @param string $binary
* @return null|string
*/
protected function findGlobalBinary($binary)
{
$command = sprintf('where %s', $binary);
$result = shell_exec($command);
return trim($result);
}
}

View file

@ -272,9 +272,9 @@ class Build extends BuildBase
if (is_link($buildPath)) {
// Remove the symlink without using recursive.
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm "%s"', $buildPath));
exec(sprintf('rm "%s"', $buildPath));
} else {
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath));
exec(sprintf('rm -Rf "%s"', $buildPath));
}
}

View file

@ -47,9 +47,6 @@ class LocalBuild extends Build
return $this->handleSymlink($builder, $reference, $buildPath);
} else {
$cmd = 'cp -Rf "%s" "%s/"';
if (IS_WIN) {
$cmd = 'xcopy /E /Y "%s" "%s/*"';
}
$builder->executeCommand($cmd, $reference, $buildPath);
}

View file

@ -77,11 +77,8 @@ class RemoteGitBuild extends Build
*/
protected function cloneBySsh(Builder $builder, $cloneTo)
{
$keyFile = $this->writeSshKey($cloneTo);
if (!IS_WIN) {
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
}
$keyFile = $this->writeSshKey($cloneTo);
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
// Do the git clone:
$cmd = 'git clone --recursive ';
@ -93,10 +90,7 @@ class RemoteGitBuild extends Build
}
$cmd .= ' -b %s %s "%s"';
if (!IS_WIN) {
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
}
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
$success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo);
@ -106,9 +100,7 @@ class RemoteGitBuild extends Build
// Remove the key file and git wrapper:
unlink($keyFile);
if (!IS_WIN) {
unlink($gitSshWrapper);
}
unlink($gitSshWrapper);
return $success;
}
@ -122,9 +114,8 @@ class RemoteGitBuild extends Build
protected function postCloneSetup(Builder $builder, $cloneTo)
{
$success = true;
$commit = $this->getCommitId();
$chdir = IS_WIN ? 'cd /d "%s"' : 'cd "%s"';
$commit = $this->getCommitId();
$chdir = 'cd "%s"';
if (!empty($commit) && $commit != 'Manual') {
$cmd = $chdir . ' && git checkout %s --quiet';

View file

@ -119,19 +119,15 @@ class SubversionBuild extends Build
{
$cmd = $this->svnCommand . ' %s "%s"';
if (!IS_WIN) {
$keyFile = $this->writeSshKey($cloneTo);
$sshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
$cmd = 'export SVN_SSH="' . $sshWrapper . '" && ' . $cmd;
}
$keyFile = $this->writeSshKey($cloneTo);
$sshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
$cmd = 'export SVN_SSH="' . $sshWrapper . '" && ' . $cmd;
$success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo);
if (!IS_WIN) {
// Remove the key file and svn wrapper:
unlink($keyFile);
unlink($sshWrapper);
}
// Remove the key file and svn wrapper:
unlink($keyFile);
unlink($sshWrapper);
return $success;
}

View file

@ -49,9 +49,7 @@ class CleanBuild extends Plugin
public function execute()
{
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.phar');
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.lock');

View file

@ -129,10 +129,6 @@ class Codeception extends Plugin implements ZeroConfigPluginInterface
$cmd = 'cd "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
if (IS_WIN) {
$cmd = 'cd /d "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
}
$configPath = $this->builder->buildPath . $configPath;
$success = $this->builder->executeCommand($cmd, $this->builder->buildPath, $configPath);

View file

@ -104,14 +104,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface
public function execute()
{
$composerLocation = $this->builder->findBinary(['composer', 'composer.phar']);
$cmd = '';
if (IS_WIN) {
$cmd = 'php ';
}
$cmd .= $composerLocation . ' --no-ansi --no-interaction ';
$cmd = $composerLocation . ' --no-ansi --no-interaction ';
if ($this->preferDist) {
$this->builder->log('Using --prefer-dist flag');

View file

@ -62,9 +62,6 @@ class CopyBuild extends Plugin
$this->wipeExistingDirectory();
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
if (IS_WIN) {
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
}
$success = $this->builder->executeCommand($cmd, $this->directory, $build, $this->directory);
@ -97,9 +94,6 @@ class CopyBuild extends Plugin
if ($this->ignore) {
foreach ($this->builder->ignore as $file) {
$cmd = 'rm -Rf "%s/%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s\%s"';
}
$this->builder->executeCommand($cmd, $this->directory, $file);
}
}

View file

@ -74,18 +74,12 @@ class Grunt extends Plugin
{
// if npm does not work, we cannot use grunt, so we return false
$cmd = 'cd %s && npm install';
if (IS_WIN) {
$cmd = 'cd /d %s && npm install';
}
if (!$this->builder->executeCommand($cmd, $this->directory)) {
return false;
}
// build the grunt command
$cmd = 'cd %s && ' . $this->grunt;
if (IS_WIN) {
$cmd = 'cd /d %s && ' . $this->grunt;
}
$cmd .= ' --no-color';
$cmd .= ' --gruntfile %s';
$cmd .= ' %s'; // the task that will be executed

View file

@ -74,18 +74,12 @@ class Gulp extends Plugin
{
// if npm does not work, we cannot use gulp, so we return false
$cmd = 'cd %s && npm install';
if (IS_WIN) {
$cmd = 'cd /d %s && npm install';
}
if (!$this->builder->executeCommand($cmd, $this->directory)) {
return false;
}
// build the gulp command
$cmd = 'cd %s && ' . $this->gulp;
if (IS_WIN) {
$cmd = 'cd /d %s && ' . $this->gulp;
}
$cmd .= ' --no-color';
$cmd .= ' --gulpfile %s';
$cmd .= ' %s'; // the task that will be executed

View file

@ -55,11 +55,10 @@ class Wipe extends Plugin
}
if (is_dir($this->directory)) {
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
return $this->builder->executeCommand($cmd, $this->directory);
}
return true;
}
}

View file

@ -42,18 +42,14 @@ class Factory
* Check PosixProcessControl, WindowsProcessControl and UnixProcessControl, in that order.
*
* @return ProcessControlInterface
*
* @internal
*
* @throws \Exception
*/
public static function createProcessControl()
{
switch (true) {
case PosixProcessControl::isAvailable():
return new PosixProcessControl();
case WindowsProcessControl::isAvailable():
return new WindowsProcessControl();
case UnixProcessControl::isAvailable():
return new UnixProcessControl();
}

View file

@ -1,56 +0,0 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCensor\ProcessControl;
/**
* Control processes using the "tasklist" and "taskkill" commands.
*
* @author Adirelle <adirelle@gmail.com>
*/
class WindowsProcessControl implements ProcessControlInterface
{
/**
* Check if the process is running using the "tasklist" command.
*
* @param integer $pid
*
* @return bool
*/
public function isRunning($pid)
{
$lastLine = exec(sprintf('tasklist /fi "PID eq %d" /nh /fo csv 2>nul:', $pid));
$record = str_getcsv($lastLine);
return isset($record[1]) && intval($record[1]) === $pid;
}
/**
* {@inheritdoc}
*/
public function kill($pid, $forcefully = false)
{
$result = 1;
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
return !$result;
}
/**
* Check whether the commands "tasklist" and "taskkill" are available.
*
* @return bool
*
* @internal
*/
public static function isAvailable()
{
return DIRECTORY_SEPARATOR === '\\' && exec("where tasklist") && exec("where taskkill");
}
}

View file

@ -21,17 +21,11 @@ class CommandExecutorTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
if (IS_WIN) {
$this->markTestSkipped("Cannot test UnixCommandExecutor on ".PHP_OS);
return;
}
parent::setUp();
$mockBuildLogger = $this->prophesize('PHPCensor\Logging\BuildLogger');
$class = IS_WIN
? 'PHPCensor\Helper\WindowsCommandExecutor'
: 'PHPCensor\Helper\UnixCommandExecutor';
$class = 'PHPCensor\Helper\UnixCommandExecutor';
$this->testedExecutor = new $class($mockBuildLogger->reveal(), __DIR__);
}

View file

@ -1,22 +0,0 @@
<?php
namespace Tests\PHPCensor\ProcessControl;
use PHPCensor\ProcessControl\WindowsProcessControl;
class WindowsProcessControlTest extends ProcessControlTest
{
protected function setUp()
{
$this->object = new WindowsProcessControl();
}
public function getTestCommand()
{
return "pause";
}
public function testIsAvailable()
{
$this->assertEquals(DIRECTORY_SEPARATOR === '\\', WindowsProcessControl::isAvailable());
}
}

View file

@ -14,17 +14,11 @@ use PHPCensor\Security\Authentication\Service;
class ServiceTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Service::getInstance
*/
public function testGetInstance()
{
$this->assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance());
}
/**
* @covers Service::buildProvider
*/
public function testBuildBuiltinProvider()
{
$provider = Service::buildProvider('test', ['type' => 'internal']);
@ -32,9 +26,6 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider);
}
/**
* @covers Service::buildProvider
*/
public function testBuildAnyProvider()
{
$config = ['type' => '\Tests\PHPCensor\Security\Authentication\DummyProvider'];
@ -45,9 +36,6 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($config, $provider->config);
}
/**
* @covers Service::getProviders
*/
public function testGetProviders()
{
$a = $this->prophesize('\PHPCensor\Security\Authentication\UserProviderInterface')->reveal();
@ -59,9 +47,6 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($providers, $service->getProviders());
}
/**
* @covers Service::getLoginPasswordProviders
*/
public function testGetLoginPasswordProviders()
{
$a = $this->prophesize('\PHPCensor\Security\Authentication\UserProviderInterface')->reveal();

View file

@ -27,9 +27,6 @@ class InternalTest extends \PHPUnit_Framework_TestCase
]);
}
/**
* @covers Internal::verifyPassword
*/
public function testVerifyPassword()
{
$user = new User();
@ -39,9 +36,6 @@ class InternalTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->provider->verifyPassword($user, $password));
}
/**
* @covers Internal::verifyPassword
*/
public function testVerifyInvaldPassword()
{
$user = new User();
@ -51,17 +45,11 @@ class InternalTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->provider->verifyPassword($user, 'bar'));
}
/**
* @covers Internal::checkRequirements
*/
public function testCheckRequirements()
{
$this->provider->checkRequirements();
}
/**
* @covers Internal::provisionUser
*/
public function testProvisionUser()
{
$this->assertNull($this->provider->provisionUser('john@doe.com'));

View file

@ -33,10 +33,6 @@ if (!defined('RUNTIME_DIR')) {
define('RUNTIME_DIR', ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR);
}
if (!defined('IS_WIN')) {
define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false));
}
require_once(ROOT_DIR . 'vendor/autoload.php');
// Load configuration if present: