Allowing to execute of the original logic of a mock object

Photo by Nadine Shaabana on Unsplash

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. …


Automatic request content deserialization and validation

Photo by Laura Ockel on Unsplash

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.

Behind the scenes

At the base of the workflow principle, there is the extension of ParamConverters of the SensioFrameworkExtraBundle. …


Create a loading component using HOCs for fetching data from your server and have fun!

Photo by kyler trautner on Unsplash

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…


How to use a stream wrapper for a virtual file system and have fun!

Photo by James Pond on Unsplash

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…


Photo by Zach Reiner on Unsplash

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:

  • S: Single-responsibility principle
  • O: Open-closed principle
  • L: Liskov substitution principle
  • I: Interface segregation principle
  • D: Dependency Inversion Principle

Let’s dive in deeper those principles!

Single-responsibility Principle

A class should have one and only one reason to change, meaning that a class should have only one job.

It means that if…


Photo by Caspar Camille Rubin on Unsplash

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…

Normal 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.

Hash Based Url

This url has a unique application endpoint /app/ controlled by one single back-end action…


In this post we will explore the right way to use JWT token in a Single Page Application and HOW to manage it in order to avoid security issues. Read on!

Photo by Kaitlyn Baker on Unsplash

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!

What’s JWT token?

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. …


The cleanest way to deal with JSON form request

Photo by J. Kelly Brito on Unsplash

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:

  • Create an entity with related annotations
  • Decoded JSON data
  • Fill the entity with data
  • Validate entity
  • Throw errors if there are some

But this approach has such limits like the following:

  • You must create an entity class for each JSON data you would validate (YES, even if it has only one field!)
  • If…


Photo by Nate Grant on Unsplash

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…


Photo by Artem Sapegin on Unsplash

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…

Ideneal

Full-stack Developer & Security Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store