Codeception default _bootstrap.php
file states:
<?php
// Here you can initialize variables that will be available to your tests
So I wanted to initialize a variable inside of it:
<?php
$a = 5;
However, when I use it my SomeAcceptanceCept
:
<?php
// ....
$I->fillField('description', $a);
I get: ErrorException: Undefined variable: a
I did var_dump
in _bootstrap.php
and it indeed get's ran once before acceptance tests, but variables from it are not available in my tests.
I can't seem to find any documentation on this.
I'm actually trying to initialize Faker instance to use in my tests.
I find the documentation on this to be quite confusing. I was attempting to do the exact same thing to no avail. So I ended up using Fixtures by putting this in the _bootstrap.php file:
use Codeception\Util\Fixtures;
use Faker\Factory;
$fake = Factory::create();
Fixtures::add('fake', $fake);
(You could also use a separate fixtures.php file and include it in your test.)
Which allows you to get the faker object or anything else like this:
Fixtures::get('fake');
The strange thing is that if you look at the Fixtures docs it actually mentions using the Faker library to create tests data in the bootstrap file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With