Ep#361 – Interview with Dana Luther – Voices of the ElePHPant

Listen as host Khayrattee Wasseem talks with Dana Luther about her two talks for Longhorn PHP happening in Oct 2021 – docker secrets & exakat using docker.

She explains how she participated in the “School the World” movement to help children in poor countries. She also talks about her passion for singing.

This episode is sponsored by
RingCentral Developers

The post Ep#361 – Interview with Dana Luther appeared first on Voices of the ElePHPant.

Xdebug Update: August 2021 – Derick Rethans

Xdebug Update: August 2021

In this monthly update I explain what happened with Xdebug development in this past month. These will be published on the first Tuesday after the 5th of each month.

Patreon and GitHub supporters will get it earlier, around the first of each month.

You can become a patron or support me through GitHub Sponsors. I am currently 58% towards my $2,000 per month goal. If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In August, I worked on Xdebug for about 50 hours, with funding being around 25 hours, which is only half.

Xdebug Videos

I have published two more videos on how to use Xdebug on my YouTube channel.

These are part of a series to explain how to use Xdebug:

  • Xdebug 3 Profiling: 3. Analysing Data, where I show how to use KCacheGrind to read and analyse profiling files to find bottlenecks in code.

  • Xdebug 3: Activation and Triggers, where I explain how to activate Xdebug’s myriad of features with different methods, including cookies, GET/POST parameters, environment variables, and with a browser extension.

I will create more videos in the upcoming month, and if you would like to suggest a topic for a 5 to 10 minute long video, feel free to request them through this Google Form.

PHP on the road to the 8.1.0 release – Remi Collet

Version 8.1.0 Release Candidate 1 is released. It’s now enter the stabilisation phase for the developers, and the test phase for the users.

RPM are available in the remi-php81 repository for Fedora  33 and Enterprise Linux  7 (RHEL, CentOS), or in the php:remi-8.1 stream, and as Software Collection in the remi-safe repository (or remi for Fedora)

 

emblem-important-4-24.pngThe repository provides development versions which are not suitable for production usage.

Also read: PHP 8.1 as Software Collection

emblem-notice-24.pngInstallation : read the Repository configuration and choose installation mode.

Replacement of default PHP by version 8.1 installation, module way (simplest way on Fedora and EL-8):

dnf module reset php
dnf module install php:remi-8.1
dnf update

Replacement of default PHP by version 8.1 installation, repository way (simplest way on EL-7):

yum-config-manager --enable remi-php81
yum update php\*

Parallel installation of version 8.1 as Software Collection (recommended for tests):

yum install php81

emblem-important-2-24.pngTo be noticed :

  • EL8 rpm are build using RHEL-8.4
  • EL7 rpm are build using RHEL-7.9
  • lot of extensions are also available, see the PHP extension RPM status page and PHP version 8.1 tracker
  • follow the comments on this page for update until final version
  • should be proposed for Fedora 36

emblem-notice-24.pngInformation, read:

Base packages (php)

Software Collections (php81)

PHP 8.1.0 RC 1 available for testing – PHP: Hypertext Preprocessor

The PHP team is pleased to announce the release of PHP 8.1.0, RC 1. This is the first release candidate, continuing the PHP 8.1 release cycle, the rough outline of which is specified in the PHP Wiki. For source downloads of PHP 8.1.0, RC 1 please visit the download page. Please carefully test this version and report any issues found in the bug reporting system. Please DO NOT use this version in production, it is an early test version. For more information on the new features and other changes, you can read the NEWS file or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. The next release will be the second release candidate (RC 2), planned for 16 September 2021. The signatures for the release can be found in the manifest or on the QA site. Thank you for helping us make PHP better.

Advanced PHPUnit shenanigans – Larry Garfield

Advanced PHPUnit shenanigans

In my last post, we talked about PHPUnit’s data providers, and how to leverage them to write more maintainable tests. Today, I want to talk about two more test-writing techniques that I’ve found to be very helpful.

Continue reading this post on PeakD.

Larry
1 September 2021 – 11:27am

Quick Testing Tips: Self-Contained Tests – Matthias Noback

Whenever I read a test method I want to understand it without having to jump around in the test class (or worse, in dependencies). If I want to know more, I should be able to “click” on one of the method calls and find out more.

I’ll explain later why I want this, but first I’ll show you how to get to this point.

As an example, here is a test I encountered recently:

public function testGetUsernameById(): void
{ $userRepository = $this->createUserRepository(); $username = $userRepository->getUsernameById(1); self::assertSame('alice', $username);
}

The way I read this:

/* * Ah, we're testing the UserRepository, so we instantiate it. * The factory method probably injects a connection to the test * database or something: */
$userRepository = $this->createUserRepository(); /* * Now we fetch a username by its ID. The ID is 1. That's the * first time I see it in this test. This probably means that * there is no user with this ID and the method will throw * an exception or return a default name or something: */
$username = $userRepository->getUsernameById(1); /* * Wait, the username is supposed to be "alice"? * Where did that come from? */
self::assertSame('alice', $username);

So while trying to understand this test that last line surprised me. Where does Alice come from?

As it turns out there is a setupTables() function which is called during the setup phase. This method populates the database with some user data that is used in various ways by one of the test methods in the class.

private function setupTables(): void
{ $this->connection->table('users') ->insert( [ ['user_id' => 1, 'username' => 'alice', 'password' => 'alicepassword'], ['user_id' => 2, 'username' => 'bob', 'password' => 'bobpassword'], ['user_id' => 3, 'username' => 'john', 'password' => 'johnpassword'], ['user_id' => 4, 'username' => 'peter', 'password' => 'peterpassword'], ] ); // ...
}

There are some problems with this approach:

  • It’s not clear which tests rely on which database records (a common issue with shared database fixtures). So it’s hard to change or remove tests, or the test data, when needed. As an example, if we remove one test, maybe some test data could also be removed but we don’t really know. If we change some test data, one of the tests may break.
  • It’s not clear which of the values is actually relevant. For example, we’re interested in user 1, 'alice', but is the password relevant? Most likely not.

The first thing we need to do is ensure that each test only creates the database records that it really needs, e.g.

public function testGetUsernameById(): void
{ $this->connection->table('users') ->insert( [ 'user_id' => 1, 'username' => 'alice', 'password' => 'alicepassword' ] ); $userRepository = $this->createUserRepository(); $username = $userRepository->getUsernameById(1); self::assertSame('alice', $username);
}

At this point the test is already much easier to understand on its own. You can clearly see where the number 1 and the string 'alice' come from. There’s only that 'alicepassword' string that is irrelevant for this test. Leaving it out gives us an SQL constraint error. But we can still get rid of it here by extracting a method for creating a user record, moving the insert() out of sight:

public function testGetUsernameById(): void
{ $this->createUser(1, 'alice'); $userRepository = $this->createUserRepository(); $username = $userRepository->getUsernameById(1); self::assertSame('alice', $username);
} private function createUser(int $id, string $username): void
{ $this->connection->table('users') ->insert( [ 'user_id' => $id, 'username' => $username, 'password' => 'a-password' ] );
}

Going back to the beginning of this post:

  • When I read a test method I want to understand it without having to jump around in the test class (or worse, in dependencies).
  • If I want to know more, I should be able to “click” on one of the method calls and find out more.

With just a few simple refactoring steps we’ve been able to achieve these things. As a consequence we achieve th

Truncated by Planet PHP, read more at the original (another 1692 bytes)