Set of Unit Tests for the previous SOLID Examples post. Single Responsibility Principle (SRP) Open/Closed Principle (OCP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP) Single Responsibility Principle (SRP) Unit tests for the Authenticator class from the Single Responsibility Principle example from the previous post. use PHPUnit\Framework\TestCase; class AuthenticatorTest extends TestCase { public function testAuthenticateWithValidCredentials() { // Arrange $credentialsValidator = $this->createMock(CredentialsValidator::class); ...
Read MoreSingle Responsibility Principle (SRP) Open/Closed Principle (OCP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP) Single Responsibility Principle (SRP) Suppose you are building a web application that allows users to sign up and log in to their accounts. To handle user authentication, you might create a class called Authenticator that has the following responsibilities: Validate the user's login credentials.Generate a session token if the credentials are valid.Store the session token in a cookie.Redirect ...
Read MoreAs a PHP developer, you can benefit from using SOLID principles to write better, more maintainable code. SOLID stands for: Single Responsibility Principle (SRP) Open/Closed Principle (OCP) Liskov Substitution Principle (LSP)Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP) Here's a brief explanation of each principle and how they can be applied in PHP development: Single Responsibility Principle (SRP) This principle states that a class should have only one responsibility. In other words, a ...
Read More