When you are testing with PHPUnit you could be the need to use the real objects or mock objects, depending on what you want to test.
The mocked objects know in advance what is supposed to happen during the test and which methods will be invoked.
In most cases, you have a clear understanding of when you should use them but sometimes happens that you want to have more control over what you are testing, want to mock only a part of the original object, and use the rest of the methods with the unmocked logic. …
Do you ever felt like a monkey by repeating your code over and over again?
This was my situation using Symfony 5 without the support of FOSRestBundle. Decoding JSON request content and validate each field for each action of my controllers…was so frustrating!
So in the meanwhile FOSRestBundle making the support for the newer version of Symfony, I’ve decided to create a simple but useful bundle to automatically deserialize and validate the request content: IdenealRequestContentConverterBundle.
At the base of the workflow principle, there is the extension of ParamConverters of the SensioFrameworkExtraBundle. …
If you have worked with React, you have probably come across High Order Components (HOC).
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per se. They are a pattern that emerges from React’s compositional nature.
A HOC is just a simple function that takes a component as an argument and returns another component. The main purpose is to share the same logic between components. You can learn more about them here.
Now imagine you are into a situation where you have a React Redux application, and…
You could be in that situation where you have to test the creation of a file or something else operation into the file system but you don’t want to mess up it.
Suppose you have to test a command that generates a CSV report file, you should make a test class like this one:
In the example above, you need to check always in the tearDown method if the file exists and remove it if yes.
In this case, the vfsStream library cames in handy! vfsStream is a stream wrapper for a virtual file system that may be helpful…
SOLID is an acronym for the first five object-oriented design (OOD) principles and is a series of guidelines that developers can use to build software in an easy way to maintain and extend. Understanding these concepts will make you a better developer and enable you to avoid code smells.
SOLID stands for:
Let’s dive in deeper those principles!
A class should have one and only one reason to change, meaning that a class should have only one job.
It means that if…
When you are developing your Single Page Application there is a moment when you need design the url structure too.
Usually developers use 2 types of url…
This is the url that we are used to seeing, with normal path, like this:
https://myspa.com/app/login
https://myspa.com/app/dashboard
This kind of url has the advantage of SEO, but you have to create much back-end endpoint as many as application routes in order to avoid the 404 error code message while reloading the url or pass the url to other people.
This url has a unique application endpoint /app/
controlled by one single back-end action…
Single Page Applications are become the standard of the web development architecture. One of the best methods to authenticate a user is by using JWT web token, so first of all, let’s see a general view of what is it and when you should use it!
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. …
Most of times we are dealing with Ajax forms, so we need to manipulate JSON data and send it to the server. There are several ways to handle JSON requests and validate data.
I’ve seen many developers using the Validator component and their process was the following:
But this approach has such limits like the following:
There are many ways to handle exceptions and put them in your response, especially if you are developing a REST API for your project.
In most cases, when you are creating an API interface, you could need to design a JSON response structure in order to use the same format for all clients, like the following:
{
"message": "",
"data": [],
"errors": {}
}
There are two types of errors: the simple message error that is usually given by the exception message and it will be display in the message key and the fields errors that is represented by a…
As you probably know if you are developing a well design project you might need to use Webpack Encore which is the simpler way to integrate Webpack in your Symfony application. In some cases you might need to use some environment variables from your back-end to your front-end logic, for instance for an api key.
To solve this problem I’ve used the dotenv library, so the first step is to install it.
yarn add dotenv
After that load dotenv in your webpack.config.js file, import the library and use the Encore’s method configureDefinePlugin to define the new environment variables:
Now…
Full-stack Developer & Security Enthusiast