diff --git a/Player/Extension/BlackfireExtension.php b/Player/Extension/BlackfireExtension.php index e216d00..a2de230 100644 --- a/Player/Extension/BlackfireExtension.php +++ b/Player/Extension/BlackfireExtension.php @@ -216,8 +216,6 @@ private function createBuildProfileConfig(Step $step, StepContext $stepContext, { $config = new ProfileConfiguration(); - $config->setSamples($this->language->evaluate($stepContext->getSamples(), $context->getVariableValues($stepContext, true))); - $path = parse_url($request->uri, \PHP_URL_PATH) ?: '/'; $config->setTitle($this->language->evaluate($step->getName() ?: Json::encode(sprintf('%s resource', $path)), $context->getVariableValues($stepContext, true))); @@ -323,9 +321,7 @@ private function warmupCount(StepContext $stepContext, string $requestMethod, ar return 0; } - $samples = (int) $this->language->evaluate($stepContext->getSamples(), $contextVariables); - - if (\in_array($requestMethod, ['GET', 'HEAD'], true) || $samples > 1) { + if (\in_array($requestMethod, ['GET', 'HEAD'], true)) { return true === $value ? 3 : (int) $value; } diff --git a/Player/Parser.php b/Player/Parser.php index 6667c76..1c8258f 100644 --- a/Player/Parser.php +++ b/Player/Parser.php @@ -553,11 +553,7 @@ private function parseStepConfig(Input $input, AbstractStep $step, int $expected } elseif ('json' === $keyword) { $step->json(null !== $arguments ? $this->checkExpression($input, $arguments) : 'true'); } elseif ('samples' === $keyword) { - if (null === $arguments) { - throw new SyntaxErrorException(sprintf('A "samples" takes a number as a required argument %s.', $input->getContextString())); - } - - $step->samples($this->checkExpression($input, $arguments)); + $step->addDeprecation('The "samples" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration.'); } elseif ('warmup' === $keyword) { $step->warmup(null !== $arguments ? $this->checkExpression($input, $arguments) : 'true'); } elseif ('body' === $keyword) { diff --git a/Player/Step/ConfigurableStep.php b/Player/Step/ConfigurableStep.php index c0ac06a..e84521d 100644 --- a/Player/Step/ConfigurableStep.php +++ b/Player/Step/ConfigurableStep.php @@ -76,6 +76,8 @@ public function blackfire(string|null $env): self public function samples(string|null $samples): self { + @trigger_error(sprintf('The method "%s" is deprecated since player 2.6 and will be removed in 3.0.', __METHOD__), \E_USER_DEPRECATED); + $this->samples = $samples; return $this; @@ -135,7 +137,9 @@ public function isBlackfireEnabled(): bool|null public function getSamples(): string|null { - return $this->samples; + @trigger_error(sprintf('The method "%s" is deprecated since player 2.6 and will be removed in 3.0.', __METHOD__), \E_USER_DEPRECATED); + + return null !== $this->samples ? 1 : null; } public function getWarmup(): string|null diff --git a/Player/Step/ReloadStep.php b/Player/Step/ReloadStep.php index 44b59f8..9cb9bbe 100644 --- a/Player/Step/ReloadStep.php +++ b/Player/Step/ReloadStep.php @@ -30,7 +30,6 @@ public function configureFromStep(AbstractStep $step): void { if ($step instanceof ConfigurableStep) { $this - ->samples($step->getSamples()) ->blackfire($step->getBlackfire()) ->wait($step->getWait()) ->json($step->isJson()) diff --git a/Player/Step/StepContext.php b/Player/Step/StepContext.php index 81cfe6a..996c144 100644 --- a/Player/Step/StepContext.php +++ b/Player/Step/StepContext.php @@ -28,7 +28,6 @@ final class StepContext /** @var mixed[] */ private array $variables = []; private string|null $blackfire = null; - private string|null $samples = null; private string|null $warmup = null; private string|null $workingDir = null; @@ -60,10 +59,6 @@ public function update(ConfigurableStep $step, array $variables): void $this->blackfire = $step->getBlackfire(); } - if (null !== $step->getSamples()) { - $this->samples = $step->getSamples(); - } - if (null !== $step->getWarmup()) { $this->warmup = $step->getWarmup(); } @@ -130,11 +125,6 @@ public function getBlackfireEnv(): string|null return $this->blackfire; } - public function getSamples(): string - { - return null === $this->samples ? '1' : $this->samples; - } - public function getWarmup(): string { return null === $this->warmup ? 'true' : $this->warmup; diff --git a/Player/Tests/Extension/BlackfireExtensionTest.php b/Player/Tests/Extension/BlackfireExtensionTest.php index 6454296..cc7b365 100644 --- a/Player/Tests/Extension/BlackfireExtensionTest.php +++ b/Player/Tests/Extension/BlackfireExtensionTest.php @@ -534,45 +534,22 @@ public function getPreviousStepsProvider() new HttpRequest('HEAD', 'https://app.lan'), [], ]; - $visitStepWith2WarmupsNoSamplesAndPostRequest = new VisitStep('https://app.lan'); - $visitStepWith2WarmupsNoSamplesAndPostRequest->blackfire('true'); - $visitStepWith2WarmupsNoSamplesAndPostRequest->name('"Visit page"'); - $visitStepWith2WarmupsNoSamplesAndPostRequest->method('"POST"'); - $visitStepWith2WarmupsNoSamplesAndPostRequest->warmup(2); + $visitStepWith2WarmupsAndPostRequest = new VisitStep('https://app.lan'); + $visitStepWith2WarmupsAndPostRequest->blackfire('true'); + $visitStepWith2WarmupsAndPostRequest->name('"Visit page"'); + $visitStepWith2WarmupsAndPostRequest->method('"POST"'); + $visitStepWith2WarmupsAndPostRequest->warmup(2); // no warmup are expected here as it is a POST request without having set sample > 1 yield 'VisitStep with POST request and 2 warmups' => [ - $visitStepWith2WarmupsNoSamplesAndPostRequest, + $visitStepWith2WarmupsAndPostRequest, [], new HttpRequest('POST', 'https://app.lan'), [], ]; - $visitStepWith2Warmups5SamplesAndPostRequest = new VisitStep('https://app.lan'); - $visitStepWith2Warmups5SamplesAndPostRequest->blackfire('true'); - $visitStepWith2Warmups5SamplesAndPostRequest->name('"Visit page"'); - $visitStepWith2Warmups5SamplesAndPostRequest->method('"POST"'); - $visitStepWith2Warmups5SamplesAndPostRequest->warmup(2); - $visitStepWith2Warmups5SamplesAndPostRequest->samples(5); // edge case - yield 'VisitStep with POST request and 2 warmups and 5 samples' => [ - $visitStepWith2Warmups5SamplesAndPostRequest, - [ - [ - 'name' => '"[Warmup] Visit page"', - ], - [ - 'name' => '"[Warmup] Visit page"', - ], - [ - 'name' => '"[Reference] Visit page"', - ], - ], - new HttpRequest('POST', 'https://app.lan'), [], - ]; - $visitStepWithoutBlackfire = new VisitStep('https://app.lan'); $visitStepWithoutBlackfire->blackfire('false'); $visitStepWithoutBlackfire->name('"Visit page"'); $visitStepWithoutBlackfire->warmup(2); - $visitStepWithoutBlackfire->samples(5); yield 'VisitStep without blackfire' => [ $visitStepWithoutBlackfire, [], diff --git a/Player/Tests/Mock/mockedProbeEndpoint.php b/Player/Tests/Mock/mockedProbeEndpoint.php index dc5b6bf..583e96e 100644 --- a/Player/Tests/Mock/mockedProbeEndpoint.php +++ b/Player/Tests/Mock/mockedProbeEndpoint.php @@ -14,31 +14,11 @@ const HEADER_BLACKFIRE_QUERY = 'x-blackfire-query'; const HEADER_BLACKFIRE_RESPONSE = 'x-blackfire-response'; -function buildBkfResponseHeader(array &$mockState, array $blackfireQuery, string $endpoint): string +function buildBkfResponseHeader(): string { - // let's mock the fact that we correctly computed one sample - ++$mockState['endpoints'][$endpoint]['performed_samples']; - $performedSamples = $mockState['endpoints'][$endpoint]['performed_samples']; - - $aggregSamples = $blackfireQuery['aggreg_samples'] ?? 1; - $completion = (100 * $performedSamples) / $aggregSamples; - - $profileContinues = 'true'; - - if ($performedSamples >= $aggregSamples) { - $profileContinues = 'false'; - } - - $blackfireResponse = [ - 'continue' => $profileContinues, - ]; - - if ('true' === $profileContinues) { - $blackfireResponse['progress'] = $completion; - $blackfireResponse['wait'] = 0; - } - - return http_build_query($blackfireResponse); + return http_build_query([ + 'continue' => 'false', + ]); } function mockedProbeEndpoint(callable $responseFactory) @@ -60,7 +40,6 @@ function mockedProbeEndpoint(callable $responseFactory) if (!isset($mockState['endpoints'][$endpoint])) { $mockState['endpoints'][$endpoint] = [ 'called_times' => 0, - 'performed_samples' => 0, ]; } @@ -71,7 +50,7 @@ function mockedProbeEndpoint(callable $responseFactory) parse_str($headers[HEADER_BLACKFIRE_QUERY], $blackfireQuery); // compute a blackfire response header - $blackfireResponse = buildBkfResponseHeader($mockState, $blackfireQuery, $endpoint); + $blackfireResponse = buildBkfResponseHeader(); // append it to the response header(HEADER_BLACKFIRE_RESPONSE.': '.$blackfireResponse); diff --git a/Player/Tests/ParserTest.php b/Player/Tests/ParserTest.php index 70f0282..644a0ed 100644 --- a/Player/Tests/ParserTest.php +++ b/Player/Tests/ParserTest.php @@ -94,7 +94,6 @@ public function testParsingGlobalConfiguration() $this->assertEquals([ '"Accept-Language: en-US"', ], $scenario->getBlockStep()->getHeaders()); - $this->assertEquals(10, $scenario->getBlockStep()->getSamples()); /** @var Scenario $scenario */ $scenario = $scenarioSet->getIterator()[1]; @@ -179,9 +178,9 @@ public function warmupConfigProvider() } /** - * @dataProvider provideDocSamples + * @dataProvider provideDocExamples */ - public function testDocSamples($input) + public function testDocExamples($input) { $parser = new Parser(new ExpressionLanguage(null, [new LanguageProvider()])); $scenarioSet = $parser->parse($input); @@ -189,7 +188,7 @@ public function testDocSamples($input) $this->assertInstanceOf(ScenarioSet::class, $scenarioSet); } - public function provideDocSamples() + public function provideDocExamples() { yield [<<<'EOF' scenario diff --git a/Player/Tests/Serializer/fixtures/serialized_for_jsonview_with_failures_and_exceptions.json b/Player/Tests/Serializer/fixtures/serialized_for_jsonview_with_failures_and_exceptions.json index eaa58f7..a0a34ae 100644 --- a/Player/Tests/Serializer/fixtures/serialized_for_jsonview_with_failures_and_exceptions.json +++ b/Player/Tests/Serializer/fixtures/serialized_for_jsonview_with_failures_and_exceptions.json @@ -9,6 +9,10 @@ { "status": "todo", "name": "/competitions", + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], + "type": "visit", "failing_expectations": [ { "reason": "An expectation failed", @@ -23,8 +27,7 @@ } ] } - ], - "type": "visit" + ] } ] }, @@ -38,6 +41,9 @@ "errors": [ "Something exploded" ], + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "type": "visit" } ] diff --git a/Player/Tests/Serializer/fixtures/test4.json b/Player/Tests/Serializer/fixtures/test4.json index e3c5064..52daf06 100644 --- a/Player/Tests/Serializer/fixtures/test4.json +++ b/Player/Tests/Serializer/fixtures/test4.json @@ -13,10 +13,12 @@ "method": "'GET'", "uri": "url('https://api.dreamcargiveaways.co.uk/competitions')", "status": "todo", - "samples": "10", "warmup": "true", "is_blackfire_enabled": true, "name": "/competitions", + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "line": 5, "type": "visit" } diff --git a/Player/Tests/Serializer/fixtures/test5_1.json b/Player/Tests/Serializer/fixtures/test5_1.json index 7097511..337b1ef 100644 --- a/Player/Tests/Serializer/fixtures/test5_1.json +++ b/Player/Tests/Serializer/fixtures/test5_1.json @@ -13,10 +13,12 @@ "method": "'GET'", "uri": "url('https://api.dreamcargiveaways.co.uk/competitions')", "status": "todo", - "samples": "10", "warmup": "true", "is_blackfire_enabled": true, "name": "/competitions", + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "line": 5, "type": "visit" } @@ -31,10 +33,12 @@ "method": "'GET'", "uri": "url('https://api.dreamcargiveaways.co.uk/competitions')", "status": "todo", - "samples": "10", "warmup": "true", "is_blackfire_enabled": true, "name": "/competitions", + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "line": 13, "type": "visit" } @@ -42,4 +46,4 @@ "line": 11 } ] -} +} \ No newline at end of file diff --git a/Player/Tests/Serializer/fixtures/test5_2.json b/Player/Tests/Serializer/fixtures/test5_2.json index 4d67f32..52daf06 100644 --- a/Player/Tests/Serializer/fixtures/test5_2.json +++ b/Player/Tests/Serializer/fixtures/test5_2.json @@ -13,10 +13,12 @@ "method": "'GET'", "uri": "url('https://api.dreamcargiveaways.co.uk/competitions')", "status": "todo", - "samples": "10", "warmup": "true", "is_blackfire_enabled": true, "name": "/competitions", + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "line": 5, "type": "visit" } @@ -24,4 +26,4 @@ "line": 3 } ] -} +} \ No newline at end of file diff --git a/Player/Tests/fixtures-run-with-env/sampling/output-next-full-report.txt b/Player/Tests/fixtures-run-with-env/sampling/output-next-full-report.txt index 3a24d6b..5642bb3 100644 --- a/Player/Tests/fixtures-run-with-env/sampling/output-next-full-report.txt +++ b/Player/Tests/fixtures-run-with-env/sampling/output-next-full-report.txt @@ -6,18 +6,10 @@ GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" GET http://0:8399/sampling/index.php?id=8399 OK - OK Scenarios 1 - Steps 5 + OK Scenarios 1 - Steps 1 { "name": null, "results": [ @@ -54,8 +46,10 @@ GET http://0:8399/sampling/index.php?id=8399 { "uri": "\"sampling/index.php?id=\"~id", "status": "done", - "samples": "5", "is_blackfire_enabled": true, + "deprecations": [ + "The \"samples\" attribute has no effect, is deprecated and will be removed in version 3. Remove it from your configuration." + ], "uuid": "%x-%x-%x-%x-%x", "file": "%s/Player/Tests/Console/../fixtures-run-with-env/sampling/scenario.bkf", "line": 6, @@ -109,84 +103,6 @@ GET http://0:8399/sampling/index.php?id=8399 "name": "[Reference] anonymous", "uuid": "%x-%x-%x-%x-%x", "type": "request" - }, - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "is_blackfire_enabled": true, - "name": "Reloading for Blackfire", - "uuid": "%x-%x-%x-%x-%x", - "type": "reload", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "follow_redirects": "false", - "is_blackfire_enabled": true, - "uuid": "%x-%x-%x-%x-%x", - "type": "request", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "is_blackfire_enabled": true, - "name": "Reloading for Blackfire", - "uuid": "%x-%x-%x-%x-%x", - "type": "reload", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "follow_redirects": "false", - "is_blackfire_enabled": true, - "uuid": "%x-%x-%x-%x-%x", - "type": "request", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "is_blackfire_enabled": true, - "name": "Reloading for Blackfire", - "uuid": "%x-%x-%x-%x-%x", - "type": "reload", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "follow_redirects": "false", - "is_blackfire_enabled": true, - "uuid": "%x-%x-%x-%x-%x", - "type": "request", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "is_blackfire_enabled": true, - "name": "Reloading for Blackfire", - "uuid": "%x-%x-%x-%x-%x", - "type": "reload", - "steps": [ - { - "status": "done", - "initiator_uuid": "%x-%x-%x-%x-%x", - "follow_redirects": "false", - "is_blackfire_enabled": true, - "uuid": "%x-%x-%x-%x-%x", - "type": "request" - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] } ] } diff --git a/Player/Tests/fixtures-run-with-env/sampling/output-next.txt b/Player/Tests/fixtures-run-with-env/sampling/output-next.txt index 384bb47..cdc672c 100644 --- a/Player/Tests/fixtures-run-with-env/sampling/output-next.txt +++ b/Player/Tests/fixtures-run-with-env/sampling/output-next.txt @@ -6,15 +6,7 @@ GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 GET http://0:8399/sampling/index.php?id=8399 -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" -GET http://0:8399/sampling/index.php?id=8399 - "Reloading for Blackfire" GET http://0:8399/sampling/index.php?id=8399 OK - OK Scenarios 1 - Steps 5 + OK Scenarios 1 - Steps 1 diff --git a/Player/Tests/fixtures-run-with-env/without-name/output-next.txt b/Player/Tests/fixtures-run-with-env/without-name/output-next.txt index e137844..d3327a1 100644 --- a/Player/Tests/fixtures-run-with-env/without-name/output-next.txt +++ b/Player/Tests/fixtures-run-with-env/without-name/output-next.txt @@ -6,9 +6,7 @@ GET http://0:8399/without-name/index.php GET http://0:8399/without-name/index.php GET http://0:8399/without-name/index.php GET http://0:8399/without-name/index.php -GET http://0:8399/without-name/index.php - "Reloading for Blackfire" GET http://0:8399/without-name/index.php OK - OK Scenarios 1 - Steps 2 + OK Scenarios 1 - Steps 1