Install WordPress and plugins with Composer

MacBook avec code sur un bureau

Installing WordPress with Composer used to be painful. Today it is simple and clean. Here is how to manage the WordPress core and its plugins entirely through Composer. The WordPress core The johnpbloch/wordpress project tracks the latest WordPress releases and is still the most used. In composer.json, you set the package and the install directory: … Read more

Nginx – Configuration Error – Connection Refused

MacBook Pro affichant un éditeur de code

When setting up nginx it can happen that afterwards it is not possible to connect to the server and that you receive a “hostname not found” error In the terminal, we start by using curl -v domain.dev The error appears Rebuilt URL to: domain.dev/ * Hostname was NOT found in DNS cache * Trying 127.0.0.1… … Read more

Git doesn’t fetch all branches in remote

MacBook Pro affichant un éditeur de code

Sometimes when you work with git, you don’t find all the remote branches. Even after using git fetch they do not appear. git fetch It is very likely that the origin of the fetch is wrong. We can see, for example, that here only the master branch is updated. $ git config –get remote.origin.fetch +refs/heads/master:refs/remotes/origin/master … Read more

Categories Git

PHP: Create a date/ timestamp with strtotime by setting the time

Code sur écran d'ordinateur

Everyone knows the strtotime function. With it, for example, we can retrieve the date of 2 weeks ago, strtotime(‘-2 week’); or a year ago strtotime(‘-1 year’); What is interesting is that you can retrieve the date of 2 weeks ago while defining the time, for example midnight strtotime(‘-2 week midnight’); or noon: strtotime(‘-2 week noon’); … Read more

Categories PHP

PHPUnit – Set a protected or private property on a mock

MacBook avec code sur un bureau

Using mocks it is often necessary to give a value to a private or protected variable. To do this, just use the Reflection class. $basket = $this->getMockBuilder(‘Basket’) ->disableOriginalConstructor() ->getMock(); $basketReflection = new ReflectionClass($basket); $sessionId = $basketReflection->getProperty(‘sessionId’); $sessionId->setAccessible(true); $sessionId->setValue($basket, ‘abc’); So the sessionId value in our Mock will be ‘abc’. Since PHP 8.1, setAccessible(true) is unnecessary … Read more

Yii – Create a custom relation between two tables

MacBook avec code sur un bureau

To make a custom relationship between two tables in a model, it is possible to add an additional option in the relation in which one indicates which foreign key should be used with which field. public function relations() { return array( ‘nomRelation’ => array( self::HAS_ONE, ‘otherTable, ”, ‘on’=>’thisTable.fk_otherTable = otherTable.id’ ), ); }

Categories yii