A
A
Andrey Pavlenko2017-10-17 21:56:05
Yii
Andrey Pavlenko, 2017-10-17 21:56:05

How to load Global fixtures in Codeception + Yii2?

As I understand it, there used to be other mechanisms, so there is a lot of confusing and old documentation and examples on the Internet that do not work properly with the built-in Codeception module (and not the separate \yii\codeception as before).
Therefore, I have already tried everything, rummaged through the documentation, in the source code, but did not understand: how can I load certain fixtures not during the execution of each test, but only once in the test group file?
And also: is it possible to somehow remove certain unnecessary information from the database with a unit TestCase, that is, some method that will work at the end of a group of tests? How to do it in a better way?
I want to get better and start writing tests, but this fragmented documentation has already eaten all my nerves...
As I understand it, there is also the InitDbFixture class, but it is not at all clear what to do with it - how to load it ...
There seems to be some kind of tests/fixtures/initdb.php file, but I did not find a word about its syntax.
It is also possible that this needs to be loaded using yii fixture/load - but how to automate this and not do it every time you run tests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2017-10-20
@Akdmeh

Total, I write to those who will face the same problem. You just need to put all the necessary fixtures in one place.
And if you need them all the time - just run them with the console once:
yii fixture/load "*" (even though this requires some configuration)
Yii2 and codeception are quite tricky - they start a transaction before each test, and rollback after each test (most importantly, use InnoDB on all tables).
Therefore, fixtures are globally available for all methods and unchanged for each test.
Convenient, but it so happened that this moment somehow turned out to be rather vaguely described for me, and on the site - also with outdated documentation. Well, what can you do, the features of Open Source. Sometimes you have to study and dig it yourself.
And in principle, all the necessary data was in the documentation, it’s just that I somehow missed or didn’t understand the moment with transactions and the immutability of the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question