Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception Cept tests _bootstrap variables

Tags:

codeception

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.

like image 287
Igor Pantović Avatar asked Aug 26 '14 21:08

Igor Pantović


1 Answers

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.

like image 55
Jason Avatar answered Sep 21 '22 11:09

Jason