8. Jan 2022 |

How to prepare for the TestDome php assessment – my mistakes and tips

3rd year IT student in search of an internship

5th semester at school is pretty much over by now. Only one small assignment to do on upcoming Tuesday Thursday. Hopefully, I will write about the semester at some point.

On Monday I am going to do PHP tests for the internship that I applied for. I am preparing for it at the moment by solving Testdome PHP exercises and PHP interview questions. If I succeed it would be a huge step for me to become a sufficient Magento developer one day.

I lost test points here and there

Now, two days later, I have the internship assignment done. TestDome tests it was. My result was above the threshold so not the worst outcome at the moment and I got the invitation to the interview. Even though I have been feeling myself quite convenient with PHP there were still a few surprises.

I had never used $GLOBALS variable to access data that is outside the function. The task was to write a function that would add an integer to the first position of an array that is outside the function scope. Simple task but tricky if you don’t know the syntax – use variable name (as a string) as key to $GLOBALS associative array. For example you can add an item to $array = []; with $GLOBALS['array'][] = 1;

I had never actually used $_SESSION variable to store data. The task was to start a session and use $_SESSION for data storage. So probably it is reasonable to learn to use cookies and sessions as data storage before starting the assignment.

One task was to implement pagination by using SQL. I did not manage to figure out how to calculate OFFSET in the query. It would need multiplication of page and pageSize to get the right starting point but just adding pageSize * page to the query does not work 🙂

SELECT id, name FROM customers ORDER BY name LIMIT pageSize OFFSET (pageSize * page); ← this query does not work. And using OFFSET for a large number of rows would anyway be a poorly performing solution. A few hours later, when I opened the task again, I found a solution and this works well:

Declare variable in MariaDB, set value to it and use the variable as a part of query. Though, as said, usage of OFFSET is not the best solution because you ask all the rows until OFFSET + LIMIT and just throw away everything that is before the OFFSET.

I did not know how to dynamically get Class from a string in PHP. Yes, it is simple if you have done it. $dragonString = "Dragon"$dragonClass = new $dragon(); I probably even tried it during the test but it looked too weird to me.

The last time I wrote React (and also Vue3) was during the JavaScript course last semester, at the end of May, 7 months ago. Therefore the multiple-choice questions about the behaviour of React (like 3 or 4 questions out of 14) were… tricky.

Tips

Have MySQL database available somewhere. For SQL tasks TestDome does not provide tests to run. Those you can only submit. Yet, it provides the SQL script (which you can copy) for creating the necessary table + a little bit of seed data. So it is good if you have any kind of MySQL database ready to use (for example in localhost or running somewhere). I luckily had MariaDB instance running in Digital Ocean that I had immediate access to. This allowed me to quickly create the table and test my solution in phpStorm (they have a built in database tool with console) before submitting it.

Have an IDE that is capable of running JavaScript. phpStorm is perfect because I can use it for PHP, JS and SQL/database tasks. No need to jump around between different programs.

Solve Testdome PHP exercises and PHP interview questions before starting the test. You will probably enjoy those and learn something new.

I would also suggest not to hurry but I am not sure how using all the time provided is evaluated 🙂 In one of the SQL tasks (grouping rows by order number and… concatenating order weights, delimited by commas), I thought I solved it in a few minutes (though, 30 mins were allowed). So I used the minutes left over for a break to study some things I did not know in previous tasks (mentioned above) because “curiosity was killing me”. When the time was about to get over (I used a smartphone timer for notification) I took a careful look at the task once again and noticed this “concatenating order weights, delimited by commas” part. What a weird thing to ask from the database because what else would you usually want than just a sum of weights. So I changed sum(weight)group_concat(weight) and got it right. Huh.

If it is a multiple-choice question about some kind of specific behaviour of a built-in PHP function (that you are not familiar with), you have plenty of time at hand and the sample code is just 20 lines, then just type it into IDE and run 🙂 It is better than guessing what a thing may do. In TestDome you can not copy but… you can type.

Leave a Reply

Your email address will not be published. Required fields are marked *