Skip to content

Commit

Permalink
Merge pull request #212 from lemberg/feature/204-revise-php-config
Browse files Browse the repository at this point in the history
#204 Revise PHP configuration
  • Loading branch information
T2L committed Aug 12, 2020
2 parents b1d4604 + a673b46 commit bdf73af
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## Draft Environment (Unreleased)

Fixes:
Updates:

- [GH-204](https://github.com/lemberg/draft-environment/issues/204) - Revise PHP settings:
* `max_execution_time` is set to 300 seconds for a web server, and unlimited (0) for the CLI
* PHP CLI now able to send emails via the Mailhog
* Disabled `output_buffering` for the CLI
- [GH-203](https://github.com/lemberg/draft-environment/issues/203) - Allow connecting to the MySQL instance from any host, i.e. allow direct connection from the host OS to the MySQL instance in the guest OS (no SSH tunnel anymore). Side effect - tests can be run from the host OS, which speeds them up to 3-5x.

Fixes:

- [GH-205](https://github.com/lemberg/draft-environment/issues/205) - Fix PHP fatal error upon package removal (i.e. when running `composer remove lemberg/draft-environment`
- [GH-208](https://github.com/lemberg/draft-environment/issues/208) - Fix broken provisioning by adding `/vagrant` mount

Expand Down
7 changes: 7 additions & 0 deletions default.vm-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ php_configuration:
display_errors: 'On'
display_startup_errors: 'On'
memory_limit: 256M
max_execution_time: 300
output_buffering: 'Off'
upload_max_filesize: 64M
post_max_size: 512M
Expand All @@ -281,7 +282,13 @@ php_configuration:
# Configure PHP CLI.
php_cli_configuration:
PHP:
error_reporting: E_ALL
error_log: /var/log/draft/php_error.log
memory_limit: -1
max_execution_time: 0
output_buffering: 'Off'
# Requires MailHog.
sendmail_path: '{{ mailhog_install_dir }}/mhsendmail'

# PHP extensions to install.
php_extensions:
Expand Down
52 changes: 52 additions & 0 deletions src/Config/Update/Step/RevisePhpConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Lemberg\Draft\Environment\Config\Update\Step;

use Lemberg\Draft\Environment\Config\Update\UpdateStepInterface;

/**
* Updates PHP configuration.
*
* @link https://github.com/lemberg/draft-environment/issues/204
*/
final class RevisePhpConfiguration extends AbstractUpdateStep implements UpdateStepInterface {

/**
* {@inheritdoc}
*/
public function getWeight(): int {
return 7;
}

/**
* {@inheritdoc}
*/
public function update(array &$config): void {
if (array_key_exists('php_configuration', $config)) {
$updates = [
'max_execution_time' => 300,
];

foreach ($updates as $option => $value) {
$config['php_configuration']['PHP'][$option] = $config['php_configuration']['PHP'][$option] ?? $value;
}
}

if (array_key_exists('php_cli_configuration', $config)) {
$updates = [
'error_reporting' => 'E_ALL',
'error_log' => '/var/log/draft/php_error.log',
'max_execution_time' => 0,
'output_buffering' => 'Off',
'sendmail_path' => '{{ mailhog_install_dir }}/mhsendmail',
];

foreach ($updates as $option => $value) {
$config['php_cli_configuration']['PHP'][$option] = $config['php_cli_configuration']['PHP'][$option] ?? $value;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final protected function assertComposerLockContainsPackageExtra(): void {
$key = array_search(App::PACKAGE_NAME, array_column($decoded_composer_lock['packages-dev'], 'name'), TRUE);

self::assertTrue($decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['already-installed']);
self::assertSame(6, $decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['last-update-weight']);
self::assertSame(7, $decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['last-update-weight']);
}

}
2 changes: 1 addition & 1 deletion tests/Unit/Config/Manager/UpdateManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testGetAndSetLastAppliedUpdateWeight(): void {
* Tests the last available update weight getter.
*/
public function testGetLastAvailableUpdateWeight(): void {
self::assertSame(6, $this->configUpdateManager->getLastAvailableUpdateWeight());
self::assertSame(7, $this->configUpdateManager->getLastAvailableUpdateWeight());
}

}
135 changes: 135 additions & 0 deletions tests/Unit/Config/Update/Step/RevisePhpConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

declare(strict_types=1);

namespace Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step;

use Composer\Composer;
use Composer\Config as ComposerConfig;
use Composer\IO\IOInterface;
use Lemberg\Draft\Environment\Config\Config;
use Lemberg\Draft\Environment\Config\Manager\UpdateManager;
use Lemberg\Draft\Environment\Config\Update\Step\RevisePhpConfiguration;
use Lemberg\Draft\Environment\Utility\Filesystem;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;

/**
* Tests updating PHP configuration.
*
* @link https://github.com/lemberg/draft-environment/issues/204
*
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AbstractUpdateStep
* @covers \Lemberg\Draft\Environment\Config\Update\Step\RevisePhpConfiguration
*/
final class RevisePhpConfigurationTest extends TestCase {

/**
* @var \Composer\Composer
*/
private $composer;

/**
* @var \Composer\IO\IOInterface
*/
private $io;

/**
* @var string
*/
private $root;

/**
* @var \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface
*/
private $configUpdateManager;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
$this->composer = new Composer();
$this->composer->setConfig(new ComposerConfig());
$this->io = $this->createMock(IOInterface::class);

// Mock source and target configuration directories.
$this->root = vfsStream::setup()->url();
$fs = new Filesystem();
$fs->mkdir(["$this->root/source", "$this->root/target"]);

$configObject = new Config("$this->root/source", "$this->root/target");
$this->configUpdateManager = new UpdateManager($this->composer, $this->io, $configObject);
}

/**
* Tests step weight getter.
*/
final public function testGetWeight(): void {
$step = new RevisePhpConfiguration($this->composer, $this->io, $this->configUpdateManager);
self::assertSame(7, $step->getWeight());
}

/**
* Tests update step execution.
*
* @param array<string,mixed> $config
* @param array<string,mixed> $expectedConfig
*
* @dataProvider updateDataProvider
*/
final public function testUpdate(array $config, array $expectedConfig): void {
$step = new RevisePhpConfiguration($this->composer, $this->io, $this->configUpdateManager);

$step->update($config);
self::assertSame($config, $expectedConfig);
}

/**
* Data provider for the ::testUpdate().
*
* @return array<int,array<int,string|array<string,mixed>>>
*/
final public function updateDataProvider(): array {
return [
[
[],
[],
],
[
[
'php_configuration' => [
'PHP' => [
'display_errors' => 'On',
'display_startup_errors' => 'On',
],
],
'php_cli_configuration' => [
'PHP' => [
'memory_limit' => -1,
],
],
],
[
'php_configuration' => [
'PHP' => [
'display_errors' => 'On',
'display_startup_errors' => 'On',
'max_execution_time' => 300,
],
],
'php_cli_configuration' => [
'PHP' => [
'memory_limit' => -1,
'error_reporting' => 'E_ALL',
'error_log' => '/var/log/draft/php_error.log',
'max_execution_time' => 0,
'output_buffering' => 'Off',
'sendmail_path' => '{{ mailhog_install_dir }}/mhsendmail',
],
],
],
],
];
}

}

0 comments on commit bdf73af

Please sign in to comment.