Skip to content

Commit 1b39908

Browse files
steevanbphpbenchmarks
authored andcommitted
Fix responseBody file size verification and copy .phpbenchmarks/composer.lock.php* to composer.lock
1 parent b69b0da commit 1b39908

8 files changed

+31
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Installation
2626
# you can install it where you want, ~/benchmarkKit used for the example
2727
mkdir ~/benchmarkKit
2828
cd ~/benchmarkKit
29-
echo '{"require": {"phpbenchmarks/benchmark-kit": "^3.0"}}' > composer.json
29+
echo '{"require": {"phpbenchmarks/benchmark-kit": "^3.0.1"}}' > composer.json
3030

3131
# you can use your local composer installation, of the official Docker container
3232
docker run --rm -v $(pwd):/app composer/composer update --no-dev

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### [3.0.1](../../compare/3.0.0...3.0.1) - 2018-04-28
2+
3+
- Fix responseBody file size verification.
4+
- Fix `.phpbenchmarks/composer.lock.php` was not copied to `composer.lock` before composer install.
5+
16
### [3.0.0](../../compare/2.0.0...3.0.0) - 2018-04-28
27

38
- Move `composer.lock.php*` to .phpbenchmarks directory.

src/Benchmark/BenchmarkType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BenchmarkType
2020
'slug' => 'hello-world',
2121
'defaultBenchmarkUrl' => '/benchmark/helloworld',
2222
'responseBodyFiles' => ['responseBody.txt'],
23+
'responseBodyFileMinSize' => 13,
2324
'sourceCodeUrlIds' => ['route', 'controller']
2425
],
2526
self::REST_API => [
@@ -28,6 +29,7 @@ class BenchmarkType
2829
'slug' => 'rest-api',
2930
'defaultBenchmarkUrl' => '/benchmark/rest',
3031
'responseBodyFiles' => ['responseBody.en_GB.json', 'responseBody.fr_FR.json', 'responseBody.en.json'],
32+
'responseBodyFileMinSize' => 7621,
3133
'sourceCodeUrlIds' => [
3234
'route',
3335
'controller',
@@ -116,6 +118,11 @@ public static function getResponseBodyFiles(int $type): array
116118
return static::getConfiguration($type, 'responseBodyFiles');
117119
}
118120

121+
public static function getResponseBodyFileMinSize(int $type): int
122+
{
123+
return static::getConfiguration($type, 'responseBodyFileMinSize');
124+
}
125+
119126
public static function getSourceCodeUrlIds(int $type): array
120127
{
121128
return static::getConfiguration($type, 'sourceCodeUrlIds');

src/Command/BenchmarkValidateCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ protected function validateForPhpVersion(string $phpVersion): self
5959
$this
6060
->title('Validation of ' . $urlWithPort)
6161
->definePhpCliVersion($phpVersion)
62-
->exec('cd /var/www/phpbenchmarks && ./.phpbenchmarks/initBenchmark.sh')
62+
->exec(
63+
'cd '
64+
. $this->getInstallationPath()
65+
. ' && cp .phpbenchmarks/composer.lock.php'
66+
. $phpVersion
67+
. ' composer.lock'
68+
)
69+
->exec('cd ' . $this->getInstallationPath() . ' && ./.phpbenchmarks/initBenchmark.sh')
6370
->success('.phpbenchmarks/initBenchmark.sh executed.');
6471

6572
$curl = curl_init();

src/Command/Configure/ConfigureInitBenchmarkCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function doExecute(): AbstractCommand
2626
false,
2727
'File has been created but is very basic. Don\'t forget to edit it.'
2828
)
29-
->exec('chmod +x /var/www/phpbenchmarks/.phpbenchmarks/initBenchmark.sh')
29+
->exec('chmod +x ' . $this->getInstallationPath() . '/.phpbenchmarks/initBenchmark.sh')
3030
->success('Make .phpbenchmarks/initBenchmark.sh executable.')
3131
->runCommand('validate:configuration:initBenchmark');
3232

src/Command/Validate/ValidateComposerLockFilesCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function configure(): void
1818

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

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

44-
$lockFile = 'composer.lock.php' . $phpVersion;
45-
$lockPath = $this->getInstallationPath() . '/' . $lockFile;
44+
$lockPath = $this->getInstallationPath() . '/.phpbenchmarks/composer.lock.php' . $phpVersion;
4645
is_file($lockPath)
4746
?
4847
$this->error(

src/Command/Validate/ValidateConfigurationResponseBodyCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ protected function doExecute(): parent
3232
$filePath = $this->getResponseBodyPath() . '/' . $file;
3333
$fileRelativePath = '.phpbenchmarks/responseBody/' . $file;
3434
$this->assertFileExist($filePath, $fileRelativePath);
35-
// 7,621 is the smallest size possible for the final json, without any space or new line
35+
36+
$minSize = BenchmarkType::getResponseBodyFileMinSize(ComponentConfiguration::getBenchmarkType());
37+
$minSizeFormated = number_format($minSize, 0, '.', ',');
3638
$fileSize = filesize($filePath);
37-
($fileSize < 7621)
38-
? $this->error('File ' . $fileRelativePath . ' size must be at least 7,621 bytes.')
39-
: $this->success('File ' . $fileRelativePath . ' size is >= 7,621 bytes.');
39+
($fileSize < $minSize)
40+
? $this->error('File ' . $fileRelativePath . ' size must be at least ' . $minSizeFormated . ' bytes.')
41+
: $this->success('File ' . $fileRelativePath . ' size is >= ' . $minSizeFormated . ' bytes.');
4042
}
4143

4244
return $this;

src/Command/VhostCreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function getVhostFilePath(string $phpVersionWithoutDot): string
4343

4444
protected function createVhostFile(string $phpVersionWithoutDot): self
4545
{
46-
$source = '/var/www/phpbenchmarks/.phpbenchmarks/vhost.conf';
46+
$source = $this->getInstallationPath() . '/.phpbenchmarks/vhost.conf';
4747
$destination = $this->getVhostFilePath($phpVersionWithoutDot);
4848
$copied = copy($source, $destination);
4949
if ($copied === false) {

0 commit comments

Comments
 (0)