D
D
Denis Ogurtsov2014-05-16 11:19:34
PHP
Denis Ogurtsov, 2014-05-16 11:19:34

How to test methods that work with large datasets?

I am working with large datasets in php. I write scripts with mathematical calculations. For each script (for a set of methods in a class) I write unit tests (phpunit), mainly to compare manual miscalculations (in tests) and automatic miscalculations (in a script).
Due to the fact that large variables are formed, for example, several arrays for 1 data, I try to free up memory and delete them as soon as they are not needed.
But for tests, I need the method to return them so that I can compare the results.
I solved the problem by setting constants in the environment, if the test environment, then return the result (small in size), if the combat one, then delete it.
As for me, not a very good solution, since the method returns different (by type) results depending on the environment. How to decide? Who will advise what? Or leave it like that?
Clarification: During the tests, I need the class method to return data, since I will check them for correctness. The tests work with a small test base. In combat conditions, with a real database, there is a lot of data, large arrays are obtained, and the method should not store / return them. There is only one way out, to change the logic of the method, depending on the environment. And this is not gud. How else can you do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Solovyov, 2014-05-16
@DenisOgr

In any case, changing the logic of the method depending on the environment is a bad decision, I would make such an option, I would break the main method in which the data is generated into submethods, and take the data generation into a separate method, for example generateData and test it in phpunit, would call its main method $data = $this->generateData() and then delete the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question