When dealing with PHP, there are multiple ways to sort a collection of items, and sometimes it’s not clear which method we should use and why.
What is the difference between
Before explaining the repercussions of
sort() function, we need to know the very basic concept about lists and maps.
A list is an ordered collection.
The order is sequential starting from 0 and increasing 1 by 1 for each item.
It is also possible to have duplicated items in a list.
$list = ['Croatia', 'Belgium', 'Austria', 'Belgium', 'Denmark'];
Functional Programming is a paradigm where programs are constructed by applying and composing functions. The Functional Programming keys are:
When a function is called with some given arguments, it will always return the same result, and cannot be affected by any mutable state or other side effects.
The main concepts of this paradigm are:
Let’s start with the…
A mutable object can be modified after its creation, an immutable cannot.
An immutable object will remain in the same state as it was created. Design and implementation will be much easier and consistent. In the case of problems, locate a potential bug is faster due that it won’t have side-effects.
Although, creating immutable objects sometimes require more code, and it doesn’t fit in all scenarios (entities need to be mutable for example).
<?php declare(strict_types=1);final class ProductTransfer
public function __construct(
public string $name,
public float $price,
public array $tags,
public \DateTime $releaseDate,
A Test Double is an object that can stand-in for a real object in a test, similar to how a stunt double stands in for an actor in a movie.
As I wrote in “The importance of the Tests in our Software”, there are several types of tests. They are also known as Test Doubles instead of “Mocks”.
TL;DR: No, and let me explain you why.
When we use reflection our tests get too fragile, we are allowing our tests to know so much information about the real implementation.
We need to hard-code the method name and we are coupling our test method to the production code.
Furthermore, we need to write a lot about boilerplate to test a simple method.
Q: I need to get at least an 80% of code coverage, how can I get it without Reflection class?
A: You should test ONLY your public methods and depend on the variables we pass, we should reach…
A test is an empirical assertion that demonstrates the behaviour of an expected functionality from something.
The tests are classified by what they verify, the most important ones are the following:
A software needs all of them, but the most important concerning developers are unit, integration and functional tests.