Skip to content

Commit

Permalink
Fix responseBody file size verification and copy .phpbenchmarks/comp…
Browse files Browse the repository at this point in the history
…oser.lock.php* to composer.lock
  • Loading branch information
steevanb authored and phpbenchmarks committed Apr 28, 2019
1 parent b69b0da commit 1b39908
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Installation
# you can install it where you want, ~/benchmarkKit used for the example
mkdir ~/benchmarkKit
cd ~/benchmarkKit
echo '{"require": {"phpbenchmarks/benchmark-kit": "^3.0"}}' > composer.json
echo '{"require": {"phpbenchmarks/benchmark-kit": "^3.0.1"}}' > composer.json

# you can use your local composer installation, of the official Docker container
docker run --rm -v $(pwd):/app composer/composer update --no-dev
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### [3.0.1](../../compare/3.0.0...3.0.1) - 2018-04-28

- Fix responseBody file size verification.
- Fix `.phpbenchmarks/composer.lock.php` was not copied to `composer.lock` before composer install.

### [3.0.0](../../compare/2.0.0...3.0.0) - 2018-04-28

- Move `composer.lock.php*` to .phpbenchmarks directory.
Expand Down
7 changes: 7 additions & 0 deletions src/Benchmark/BenchmarkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BenchmarkType
'slug' => 'hello-world',
'defaultBenchmarkUrl' => '/benchmark/helloworld',
'responseBodyFiles' => ['responseBody.txt'],
'responseBodyFileMinSize' => 13,
'sourceCodeUrlIds' => ['route', 'controller']
],
self::REST_API => [
Expand All @@ -28,6 +29,7 @@ class BenchmarkType
'slug' => 'rest-api',
'defaultBenchmarkUrl' => '/benchmark/rest',
'responseBodyFiles' => ['responseBody.en_GB.json', 'responseBody.fr_FR.json', 'responseBody.en.json'],
'responseBodyFileMinSize' => 7621,
'sourceCodeUrlIds' => [
'route',
'controller',
Expand Down Expand Up @@ -116,6 +118,11 @@ public static function getResponseBodyFiles(int $type): array
return static::getConfiguration($type, 'responseBodyFiles');
}

public static function getResponseBodyFileMinSize(int $type): int
{
return static::getConfiguration($type, 'responseBodyFileMinSize');
}

public static function getSourceCodeUrlIds(int $type): array
{
return static::getConfiguration($type, 'sourceCodeUrlIds');
Expand Down
9 changes: 8 additions & 1 deletion src/Command/BenchmarkValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ protected function validateForPhpVersion(string $phpVersion): self
$this
->title('Validation of ' . $urlWithPort)
->definePhpCliVersion($phpVersion)
->exec('cd /var/www/phpbenchmarks && ./.phpbenchmarks/initBenchmark.sh')
->exec(
'cd '
. $this->getInstallationPath()
. ' && cp .phpbenchmarks/composer.lock.php'
. $phpVersion
. ' composer.lock'
)
->exec('cd ' . $this->getInstallationPath() . ' && ./.phpbenchmarks/initBenchmark.sh')
->success('.phpbenchmarks/initBenchmark.sh executed.');

$curl = curl_init();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Configure/ConfigureInitBenchmarkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function doExecute(): AbstractCommand
false,
'File has been created but is very basic. Don\'t forget to edit it.'
)
->exec('chmod +x /var/www/phpbenchmarks/.phpbenchmarks/initBenchmark.sh')
->exec('chmod +x ' . $this->getInstallationPath() . '/.phpbenchmarks/initBenchmark.sh')
->success('Make .phpbenchmarks/initBenchmark.sh executable.')
->runCommand('validate:configuration:initBenchmark');

Expand Down
5 changes: 2 additions & 3 deletions src/Command/Validate/ValidateComposerLockFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function configure(): void

$this
->setName('validate:composer:lock')
->setDescription('Validate dependencies in composer.lock.phpX.Y')
->setDescription('Validate dependencies in .phpbenchmarks/composer.lock.phpX.Y')
->addArgument('phpVersion', null, 'Version of PHP: 5.6, 7.0, 7.1, 7.2 or 7.3');
}

Expand All @@ -41,8 +41,7 @@ private function validateDisabledPhpVersions(): self
foreach ($this->getPhpVersions(ComponentConfiguration::getDisabledPhpVersions()) as $phpVersion) {
$this->title('Validation of .phpbenchmarks/composer.lock.php' . $phpVersion);

$lockFile = 'composer.lock.php' . $phpVersion;
$lockPath = $this->getInstallationPath() . '/' . $lockFile;
$lockPath = $this->getInstallationPath() . '/.phpbenchmarks/composer.lock.php' . $phpVersion;
is_file($lockPath)
?
$this->error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ protected function doExecute(): parent
$filePath = $this->getResponseBodyPath() . '/' . $file;
$fileRelativePath = '.phpbenchmarks/responseBody/' . $file;
$this->assertFileExist($filePath, $fileRelativePath);
// 7,621 is the smallest size possible for the final json, without any space or new line

$minSize = BenchmarkType::getResponseBodyFileMinSize(ComponentConfiguration::getBenchmarkType());
$minSizeFormated = number_format($minSize, 0, '.', ',');
$fileSize = filesize($filePath);
($fileSize < 7621)
? $this->error('File ' . $fileRelativePath . ' size must be at least 7,621 bytes.')
: $this->success('File ' . $fileRelativePath . ' size is >= 7,621 bytes.');
($fileSize < $minSize)
? $this->error('File ' . $fileRelativePath . ' size must be at least ' . $minSizeFormated . ' bytes.')
: $this->success('File ' . $fileRelativePath . ' size is >= ' . $minSizeFormated . ' bytes.');
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/VhostCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getVhostFilePath(string $phpVersionWithoutDot): string

protected function createVhostFile(string $phpVersionWithoutDot): self
{
$source = '/var/www/phpbenchmarks/.phpbenchmarks/vhost.conf';
$source = $this->getInstallationPath() . '/.phpbenchmarks/vhost.conf';
$destination = $this->getVhostFilePath($phpVersionWithoutDot);
$copied = copy($source, $destination);
if ($copied === false) {
Expand Down

0 comments on commit 1b39908

Please sign in to comment.