Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Symfony 6 compatibility remove Symfony 2-3-4 #127

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
{
"name": "easycorp/easy-deploy-bundle",
"name": "reconnect/easy-deploy-bundle",
"type": "symfony-bundle",
"description": "The easiest way to deploy Symfony applications",
"keywords": ["deploy", "deployment", "deployer"],
"homepage": "https://github.com/EasyCorp/easy-deploy-bundle",
"homepage": "https://github.com/reconnect/easy-deploy-bundle",
"license": "MIT",
"authors": [
{
"name": "Javier Eguiluz",
"email": "javiereguiluz@gmail.com"
"name": "Thibaut Cheymol",
"email": "thibaut.cheymol@gmail.com"
}
],
"require": {
"php": ">=7.2.0",
"symfony/console": "~2.3|~3.0|~4.0|~5.0",
"symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0",
"symfony/expression-language": "~2.4|~3.0|~4.0|~5.0",
"symfony/filesystem": "~2.3|~3.0|~4.0|~5.0",
"symfony/http-foundation": "~2.3|~3.0|~4.0|~5.0",
"symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0",
"symfony/config": "~5.0|~6.0|~7.0",
"symfony/console": "~5.0|~6.0|~7.0",
"symfony/dependency-injection": "~5.0|~6.0|~7.0",
"symfony/expression-language": "~5.0|~6.0|~7.0",
"symfony/filesystem": "~5.0|~6.0|~7.0",
"symfony/http-foundation": "~5.0|~6.0|~7.0",
"symfony/http-kernel": "~5.0|~6.0|~7.0",
"symfony/polyfill-mbstring": "^1.3",
"symfony/process": "~2.3|~3.0|~4.0|~5.0"
"symfony/process": "~5.0|~6.0|~7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.1"
"phpunit/phpunit": "9.5.*"
},
"config": {
"sort-packages": true
Expand Down
14 changes: 9 additions & 5 deletions src/Command/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(FileLocator $fileLocator, string $projectDir, string
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('deploy')
Expand All @@ -50,26 +50,30 @@ protected function configure()
;
}

protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$customConfigPath = $input->getOption('configuration');
if (null !== $customConfigPath && !is_readable($customConfigPath)) {
throw new \RuntimeException(sprintf("The given configuration file ('%s') does not exist or it's not readable.", $customConfigPath));
}

if (null !== $customConfigPath && is_readable($customConfigPath)) {
return $this->configFilePath = $customConfigPath;
$this->configFilePath = $customConfigPath;

return;
}

$defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage'));
if (is_readable($defaultConfigPath)) {
return $this->configFilePath = $defaultConfigPath;
$this->configFilePath = $defaultConfigPath;

return;
}

$this->createDefaultConfigFile($input, $output, $defaultConfigPath, $input->getArgument('stage'));
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
Expand Down
14 changes: 9 additions & 5 deletions src/Command/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(string $projectDir, string $logDir)
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('rollback')
Expand All @@ -45,26 +45,30 @@ protected function configure()
;
}

protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$customConfigPath = $input->getOption('configuration');
if (null !== $customConfigPath && !is_readable($customConfigPath)) {
throw new \RuntimeException(sprintf("The given configuration file ('%s') does not exist or it's not readable.", $customConfigPath));
}

if (null !== $customConfigPath && is_readable($customConfigPath)) {
return $this->configFilePath = $customConfigPath;
$this->configFilePath = $customConfigPath;

return;
}

$defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage'));
if (is_readable($defaultConfigPath)) {
return $this->configFilePath = $defaultConfigPath;
$this->configFilePath = $defaultConfigPath;

return;
}

throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath));
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/EasyDeployExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class EasyDeployExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
Expand Down
5 changes: 4 additions & 1 deletion src/Deployer/DefaultDeployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ private function findConsoleBinaryPath(Server $server): string
if (null === $server->get(Property::console_bin)) {
throw new InvalidConfigurationException(sprintf('The "console" binary of your Symfony application is not available in any of the following directories: %s. Configure the "binDir" option and set it to the directory that contains the "console" binary.', implode(', ', $symfonyConsoleBinaries)));
}

return $server->resolveProperties('{{ project_dir }}/bin/console');
}

private function createRemoteDirectoryLayout(): void
Expand Down Expand Up @@ -261,7 +263,8 @@ private function doUpdateCode(): void
$this->runRemote(sprintf('if [ -d {{ deploy_dir }}/repo ]; then cd {{ deploy_dir }}/repo && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard %s && git clean -q -d -x -f; else git clone -q -b %s %s {{ deploy_dir }}/repo && cd {{ deploy_dir }}/repo && git checkout -q -b deploy %s; fi', $repositoryRevision, $this->getConfig(Option::repositoryBranch), $this->getConfig(Option::repositoryUrl), $repositoryRevision));

$this->log('<h3>Copying the updated code to the new release directory</>');
$this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/* {{ project_dir }}'));
$this->runRemote(sprintf('cp -pPR {{ deploy_dir }}/repo/* {{ project_dir }}'));
$this->runRemote(sprintf('cp -p {{ deploy_dir }}/repo/.env* {{ project_dir }}'));
}

private function doCreateCacheDir(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Configuration/ConfigurationAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigurationAdapterTest extends TestCase
/** @var DefaultConfiguration */
private $config;

protected function setUp()
protected function setUp(): void
{
$this->config = (new DefaultConfiguration(__DIR__))
->sharedFilesAndDirs([])
Expand Down
15 changes: 8 additions & 7 deletions tests/Configuration/DefaultConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
namespace EasyCorp\Bundle\EasyDeployBundle\Tests;

use EasyCorp\Bundle\EasyDeployBundle\Configuration\DefaultConfiguration;
use EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException;
use PHPUnit\Framework\TestCase;

class DefaultConfigurationTest extends TestCase
{
/**
* @dataProvider provideHttpRepositoryUrls
* @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException
* @expectedExceptionMessageRegExp /The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https?:\/\/.*\/symfony\/symfony-demo.git" by "git@.*:symfony\/symfony-demo.git"/
*/
public function test_repository_url_protocol(string $url)
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessageMatches('/The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https?:\/\/.*\/symfony\/symfony-demo.git" by "git@.*:symfony\/symfony-demo.git"/');

(new DefaultConfiguration(__DIR__))
->repositoryUrl($url)
;
}

/**
* @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException
* @expectedExceptionMessage The value of resetOpCacheFor option must be the valid URL of your homepage (it must start with http:// or https://).
*/
public function test_reset_opcache_for()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value of resetOpCacheFor option must be the valid URL of your homepage (it must start with http:// or https://).');

(new DefaultConfiguration(__DIR__))
->resetOpCacheFor('symfony.com')
;
}

public function provideHttpRepositoryUrls()
public function provideHttpRepositoryUrls(): \Generator
{
yield ['http://github.com/symfony/symfony-demo.git'];
yield ['https://github.com/symfony/symfony-demo.git'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Server/ServerRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ServerRepositoryTest extends TestCase
/** @var ServerRepository */
private $servers;

protected function setUp()
protected function setUp(): void
{
$repository = new ServerRepository();
$repository->add(new Server('host0'));
Expand Down
23 changes: 11 additions & 12 deletions tests/Server/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace EasyCorp\Bundle\EasyDeployBundle\EasyDeployBundle\Tests;

use EasyCorp\Bundle\EasyDeployBundle\Exception\ServerConfigurationException;
use EasyCorp\Bundle\EasyDeployBundle\Server\Property;
use EasyCorp\Bundle\EasyDeployBundle\Server\Server;
use PHPUnit\Framework\TestCase;
Expand All @@ -27,12 +28,10 @@ public function test_dsn_parsing(string $dsn, string $expectedHost, ?string $exp
$this->assertSame($expectedPort, $server->getPort());
}

/**
* @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\ServerConfigurationException
* @expectedExceptionMessage The host is missing (define it as an IP address or a host name)
*/
public function test_dsn_parsing_error()
{
$this->expectException(ServerConfigurationException::class);
$this->expectExceptionMessage('The host is missing (define it as an IP address or a host name)');
new Server('deployer@');
}

Expand Down Expand Up @@ -115,16 +114,16 @@ public function test_resolve_properties(array $properties, string $expression, s

/**
* @dataProvider wrongExpressionProvider
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The ".*" property in ".*" expression is not a valid server property./
*/
public function test_resolve_unknown_properties(array $properties, string $expression)
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/The ".*" property in ".*" expression is not a valid server property./');
$server = new Server('host', [], $properties);
$server->resolveProperties($expression);
}

public function dsnProvider()
public function dsnProvider(): \Generator
{
yield ['123.123.123.123', '123.123.123.123', null, null];
yield ['[email protected]', '123.123.123.123', 'deployer', null];
Expand All @@ -143,7 +142,7 @@ public function dsnProvider()
yield ['ssh://deployer@host:22001', 'host', 'deployer', 22001];
}

public function localDsnProvider()
public function localDsnProvider(): \Generator
{
yield ['local'];
yield ['deployer@local'];
Expand All @@ -158,23 +157,23 @@ public function localDsnProvider()
yield ['[email protected]:22001'];
}

public function serverRolesProvider()
public function serverRolesProvider(): \Generator
{
yield [[], []];
yield [[Server::ROLE_APP], [Server::ROLE_APP]];
yield [['custom_role'], ['custom_role']];
yield [['custom_role_1', 'custom_role_2'], ['custom_role_1', 'custom_role_2']];
}

public function sshConnectionStringProvider()
public function sshConnectionStringProvider(): \Generator
{
yield ['localhost', ''];
yield ['123.123.123.123', 'ssh 123.123.123.123'];
yield ['[email protected]', 'ssh [email protected]'];
yield ['[email protected]:22001', 'ssh [email protected] -p 22001'];
}

public function expressionProvider()
public function expressionProvider(): \Generator
{
yield [['prop1' => 'aaa'], '{{ prop1 }}', 'aaa'];
yield [['prop.1' => 'aaa'], '{{ prop.1 }}', 'aaa'];
Expand All @@ -188,7 +187,7 @@ public function expressionProvider()
yield [['prop1' => 'aaa', 'prop2' => 'bbb'], 'cd {{ prop1 }}{{ prop2 }}', 'cd aaabbb'];
}

public function wrongExpressionProvider()
public function wrongExpressionProvider(): \Generator
{
yield [[], '{{ prop1 }}'];
yield [['prop1' => 'aaa'], '{{ prop 1 }}'];
Expand Down