"I'm not a great programmer; I'm just a good programmer with great habits." ~ K. Beck
The inspiration to create the following set of questions and answers was Test your admin skills repository. The developer version has been prepared by @patrykwozinski. Any suggestions for changes, new questions or additions of answers are very welcome.
Available language versions:
Β Β π¬π§ English version
Β Β π΅π± Polish version
π‘ Β Questions are only examples and initial implementation to the topic. Completely exhausting the topic is possible after searching for materials on your own.
***
do not have answers or they are incomplete. It is nice to see in such cases pull requests with the suggested problem solution.
π¦ Β In a situation where you find a question that does not make much sense or contains incorrect answers - please do a pull request with suggested changes and become a project contributor.
The project was created to support programmers who intend to go on recruitment interviews in the near future, as well as people who carry them out from the technical side.
What ways of inheriting in PHP do you know?
In a PHP exists inheriting by extends
keyword from one class. We can also inherit from many places by Trait
.
What is the difference between setUp()
and setUpBeforeClass()
in unit tests?
setUp()
method called before every unit test in class, everytime after testtearDown()
is calledsetUpBeforeClass()
method called once before all tests in testing class, after all teststearDownAfterClass()
is called
Do you know example of good place to use an anonymous class in PHP?
A great place to use an anonymous class are Stubs and other test doubles where we are not interrested which object is returned. For example StubRepository
which implements interface of concrete repository depending on provided parameters can create specific needed anonymous class.
What is the difference between isset()
, array_key_exists()
and empty()
?
isset()
checks if element exists and has value including:0
, empty string,false
; returnfalse
when value isnull
empty()
checks if element exists and is not empty and not zero value; returntrue
fornull
,0
,false
, empty strings etcarray_key_exists()
checks only if array has specific key
isset()
and empty()
are language constructions. array_key_exists()
is a function.
What is the difference between language native function and language construction? What is faster?
Native language functions are written in a specific programming language and are definitely slower than language constructs that are written in the language in which the language itself was created. For PHP this is C.
Do you know any tools for static code analysis? How they helps you in your projects?
Tools for static code analysis in PHP examples:
- PHPstan
- PHPMetrics
Thanks to them, you can find many errors that do not even require the launch of applications or tests. They detect problems in the code and indicate ways to improve them. Static code analysis tools also help in learning new languages.
What types of Test Doubles do you know?
Dummy, Fake, Stub, Spy, Mock. They are used to plug the implementation.
Do the rules related to the quality of the software also apply to tests?
Yes, the quality of the tests is as important as the quality of the application. It is also worth putting a lot of effort into their proper preparation, because poor quality tests are expensive to maintain and cause many problems.
You use your repository of users with oneByUsername(username)
which is to find a user with the given name. What will you do when no results are returned?
The best way is to throw an exception, because the user's search assumption is not really met. Another way is returning null
value. Anwers like: empty user object, empty list, empty array or false
are incorrect.
When is it worth to mark the class as final and how does it help?
At the moment when the class is already concrete - it inherits from the abstract or implements the interface. This blocks unnecessary levels of inheritance and forces the composition.
What are the advantages of using NullObject
pattern?
NullObject pattern is a great tool to fight with ubiquitous nulls, NullPointerException
and creating useless if statements.
What is encapsulation and and how does it help in obtaining Value Objects?
Value Objects hides implementation of native language functions by using behaviors. They give a higher level of abstraction. Thanks to Value Objects, we are able to determine the specific level of natural language that we will use during application development.
Do you know patterns which help in writing object oriented code?
One of the sets of principles related to OOP is GRASP - General Responsibility Assignment Software Principles, which consists of nine rules about how to design a code and answer the questions: where to put some responsibility, who to assign responsibility to, how to manage dependencies and many more.
What types of design patterns do you know?
Design patterns are divided into three types:
- creational patterns
- structural patterns
- behavioral patterns
What is CQRS and what are the benefits of using it?
Command-Query Responsibility Segregation is a separation of the model into read model and write model. Using CQRS we create Commands
and Queries
. Command is never returns anything and query only ask for something - it never modifies data.
What is the difference between Active Records and ORM? What are the pros and cons of using these approaches? ***
What is behavior of an object?
Behavior of an object is a thing possible to the living creature. For example document->reassign(owner)
- we can reassign new owner of a document. Getting and setting this information is not a behavior.
What are the cons of adding get
/ set
prefixes in public object methods?
Adding prefixes such as get
or set
blocks us from being able to read the responsibility of classes and their characteristics. Getters and setters are procedural approach and are an incorrect habit that results in too much information being sent out of the class. Public methods should describe available interactions with an object and present his features.