diff --git a/README.md b/README.md index 700f5915..7f6c7415 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/bootstrap.php b/bootstrap.php index d1af2f40..13222634 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -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: diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 2eda61ac..868b138e 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -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, diff --git a/src/PHPCensor/Helper/SshKey.php b/src/PHPCensor/Helper/SshKey.php index 3379148d..a8c946e7 100644 --- a/src/PHPCensor/Helper/SshKey.php +++ b/src/PHPCensor/Helper/SshKey.php @@ -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); diff --git a/src/PHPCensor/Helper/WindowsCommandExecutor.php b/src/PHPCensor/Helper/WindowsCommandExecutor.php deleted file mode 100644 index fb3128b4..00000000 --- a/src/PHPCensor/Helper/WindowsCommandExecutor.php +++ /dev/null @@ -1,30 +0,0 @@ -handleSymlink($builder, $reference, $buildPath); } else { $cmd = 'cp -Rf "%s" "%s/"'; - if (IS_WIN) { - $cmd = 'xcopy /E /Y "%s" "%s/*"'; - } $builder->executeCommand($cmd, $reference, $buildPath); } diff --git a/src/PHPCensor/Model/Build/RemoteGitBuild.php b/src/PHPCensor/Model/Build/RemoteGitBuild.php index 3ce2391b..fea49cee 100644 --- a/src/PHPCensor/Model/Build/RemoteGitBuild.php +++ b/src/PHPCensor/Model/Build/RemoteGitBuild.php @@ -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'; diff --git a/src/PHPCensor/Model/Build/SubversionBuild.php b/src/PHPCensor/Model/Build/SubversionBuild.php index b74570c7..9eb5586f 100644 --- a/src/PHPCensor/Model/Build/SubversionBuild.php +++ b/src/PHPCensor/Model/Build/SubversionBuild.php @@ -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; } diff --git a/src/PHPCensor/Plugin/CleanBuild.php b/src/PHPCensor/Plugin/CleanBuild.php index 37b01fc9..30c33616 100644 --- a/src/PHPCensor/Plugin/CleanBuild.php +++ b/src/PHPCensor/Plugin/CleanBuild.php @@ -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'); diff --git a/src/PHPCensor/Plugin/Codeception.php b/src/PHPCensor/Plugin/Codeception.php index c4cf0d5e..8bd31519 100644 --- a/src/PHPCensor/Plugin/Codeception.php +++ b/src/PHPCensor/Plugin/Codeception.php @@ -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); diff --git a/src/PHPCensor/Plugin/Composer.php b/src/PHPCensor/Plugin/Composer.php index 3cfe0980..1d34fdc6 100644 --- a/src/PHPCensor/Plugin/Composer.php +++ b/src/PHPCensor/Plugin/Composer.php @@ -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'); diff --git a/src/PHPCensor/Plugin/CopyBuild.php b/src/PHPCensor/Plugin/CopyBuild.php index 9716ab5a..38afbe32 100644 --- a/src/PHPCensor/Plugin/CopyBuild.php +++ b/src/PHPCensor/Plugin/CopyBuild.php @@ -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); } } diff --git a/src/PHPCensor/Plugin/Grunt.php b/src/PHPCensor/Plugin/Grunt.php index 6cdf8256..6810a614 100644 --- a/src/PHPCensor/Plugin/Grunt.php +++ b/src/PHPCensor/Plugin/Grunt.php @@ -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 diff --git a/src/PHPCensor/Plugin/Gulp.php b/src/PHPCensor/Plugin/Gulp.php index 72110921..adb88c2f 100644 --- a/src/PHPCensor/Plugin/Gulp.php +++ b/src/PHPCensor/Plugin/Gulp.php @@ -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 diff --git a/src/PHPCensor/Plugin/Wipe.php b/src/PHPCensor/Plugin/Wipe.php index 4da96a95..7dc3f7cb 100644 --- a/src/PHPCensor/Plugin/Wipe.php +++ b/src/PHPCensor/Plugin/Wipe.php @@ -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; } } diff --git a/src/PHPCensor/ProcessControl/Factory.php b/src/PHPCensor/ProcessControl/Factory.php index 32d263aa..4ccd57ef 100644 --- a/src/PHPCensor/ProcessControl/Factory.php +++ b/src/PHPCensor/ProcessControl/Factory.php @@ -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(); } diff --git a/src/PHPCensor/ProcessControl/WindowsProcessControl.php b/src/PHPCensor/ProcessControl/WindowsProcessControl.php deleted file mode 100644 index 24b3868a..00000000 --- a/src/PHPCensor/ProcessControl/WindowsProcessControl.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ -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"); - } -} diff --git a/tests/PHPCensor/Helper/CommandExecutorTest.php b/tests/PHPCensor/Helper/CommandExecutorTest.php index 0439ffa2..d719622d 100644 --- a/tests/PHPCensor/Helper/CommandExecutorTest.php +++ b/tests/PHPCensor/Helper/CommandExecutorTest.php @@ -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__); } diff --git a/tests/PHPCensor/ProcessControl/WindowsProcessControlTest.php b/tests/PHPCensor/ProcessControl/WindowsProcessControlTest.php deleted file mode 100644 index 91d3d2eb..00000000 --- a/tests/PHPCensor/ProcessControl/WindowsProcessControlTest.php +++ /dev/null @@ -1,22 +0,0 @@ -object = new WindowsProcessControl(); - } - - public function getTestCommand() - { - return "pause"; - } - - public function testIsAvailable() - { - $this->assertEquals(DIRECTORY_SEPARATOR === '\\', WindowsProcessControl::isAvailable()); - } -} diff --git a/tests/PHPCensor/Security/Authentication/ServiceTest.php b/tests/PHPCensor/Security/Authentication/ServiceTest.php index 7e628e93..793f8c66 100644 --- a/tests/PHPCensor/Security/Authentication/ServiceTest.php +++ b/tests/PHPCensor/Security/Authentication/ServiceTest.php @@ -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(); diff --git a/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php b/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php index a8984e9f..08241db7 100644 --- a/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php +++ b/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php @@ -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')); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b36266f6..beb32935 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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: