You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to run Codeception tests within PHP code, using
$codecept = new Codecept();
$codecept->run(
suite : 'Acceptance',
test : 'SampleCest'
);
To run a Codeception Acceptance test at a specific moment (in between two integration tests currently written in PHPUnit).
What do you get instead?
If your PHP version is below 8.3, the call to srand($this->options['seed']); within Codecept::runSuite() fails, as seed is in this scenario not an int. As soon as you upgrade your PHP to 8.3, that error disappears and the Acceptance test completes successfully without any issue (supposingly due to the fact that the signature of srand() accepts null from upon PHP 8.3?).
As I'm new to Codeception, please let me know if I'm misunderstanding something / if it's better to dispatch Acceptance tests from Codeception in another way via PHP.
Codeception version: 5.0.12
PHP Version: 8.3.0 (now, failed with 8.2.12 in above-mentioned way)
Operating System: macOS
Installation type: Composer
List of installed packages (composer show)
Suite configuration:
# Codeception Test Suite Configuration## Suite for acceptance tests.# Perform tests in browser using the WebDriver or PhpBrowser.# If you need both WebDriver and PHPBrowser tests - create a separate suite.actor: AcceptanceTestermodules:
enabled:
- WebDriver:
url: 'https://{uname}:{pword}@mydom.org'browser: chrome# add Codeception\Step\Retry trait to AcceptanceTester to enable retriesstep_decorators:
- Codeception\Step\ConditionalAssertion
- Codeception\Step\TryTo
- Codeception\Step\Retry
When running the code with PHP 8.3, I'm getting the PHP warning:
So it seems to be treated as warning instead of an error now, but at least the test executes. Am I misunderstanding about how to properly execute a Codeception test within PHP code?
POTENTIAL FIX
I've been digging within the docs of the concerned Codecept and related file, and found that srand() is used to initiate the pseudo-random number generator within Codeception. I've not researched why this is done, so my approach may be the wrong solution. So before posting this as an answer, I'd like to know if it's a proper solution.
If I'm properly informed and srand() behaves in PHP as it does in C, srand() will seed the pseudo-random number generator with the current timestamp in PHP if its default value (in PHP that's 0) is provided to its call. According to the Codecept constructor, the options property of a new instance gets initiated via:
$this->options = $this->mergeOptions($options);
The line of code causing the failure when running the Acceptance test via PHP, using the Codecept class, then is:
srand($this->options['seed']);
So I thought by simply providing the default solution for srand() within the Codecept constructor, this should solve the problem. Hence I replaced the line of my code above:
$codecept = new Codecept();
with:
$codecept = new Codecept(['seed' => 0 ]);
This eliminated thrown warnings / errors, but I'd still like to know if it's the proper way to go to dispatch a Codeception acceptance test from within PHP.
The text was updated successfully, but these errors were encountered:
What are you trying to achieve?
I'm trying to run Codeception tests within PHP code, using
To run a Codeception Acceptance test at a specific moment (in between two integration tests currently written in
PHPUnit
).What do you get instead?
If your PHP version is below 8.3, the call to
srand($this->options['seed']);
withinCodecept::runSuite()
fails, asseed
is in this scenario not anint
. As soon as you upgrade your PHP to 8.3, that error disappears and the Acceptance test completes successfully without any issue (supposingly due to the fact that the signature ofsrand()
acceptsnull
from upon PHP8.3
?).As I'm new to Codeception, please let me know if I'm misunderstanding something / if it's better to dispatch Acceptance tests from Codeception in another way via PHP.
composer show
)When running the code with PHP 8.3, I'm getting the PHP warning:
So it seems to be treated as warning instead of an error now, but at least the test executes. Am I misunderstanding about how to properly execute a Codeception test within PHP code?
POTENTIAL FIX
I've been digging within the docs of the concerned Codecept and related file, and found that srand() is used to initiate the pseudo-random number generator within Codeception. I've not researched why this is done, so my approach may be the wrong solution. So before posting this as an answer, I'd like to know if it's a proper solution.
If I'm properly informed and srand() behaves in PHP as it does in C, srand() will seed the pseudo-random number generator with the current timestamp in PHP if its default value (in PHP that's 0) is provided to its call. According to the Codecept constructor, the options property of a new instance gets initiated via:
$this->options = $this->mergeOptions($options);
The line of code causing the failure when running the Acceptance test via PHP, using the Codecept class, then is:
srand($this->options['seed']);
So I thought by simply providing the default solution for srand() within the Codecept constructor, this should solve the problem. Hence I replaced the line of my code above:
$codecept = new Codecept();
with:
$codecept = new Codecept(['seed' => 0 ]);
This eliminated thrown warnings / errors, but I'd still like to know if it's the proper way to go to dispatch a Codeception acceptance test from within PHP.
The text was updated successfully, but these errors were encountered: