Giter Club home page Giter Club logo

phpunit's Introduction

PHPUnit Practice

Method Chaining

Method chaining is a programming technique that allows you to call multiple methods on the same object in a single statement. Instead of calling one method at a time and assigning the result to a variable, you can chain method calls together. This can lead to more concise and readable code.
In PHP, method chaining is often facilitated by designing methods in a way that they return the current object ($this) after performing their operations. This allows you to call another method on the same object without needing to store the object in a variable between method calls.

Example:

class Example { private $value;
public function setValue($value) {
    $this->value = $value;
    return $this; // Return the current object
}

public function multiplyBy($factor) {
    $this->value *= $factor;
    return $this; // Return the current object
}

public function getResult() {
    return $this->value;
}

}

// Example usage with method chaining $result = (new Example()) ->setValue(5) ->multiplyBy(3) ->getResult();

echo $result; // Outputs 15

<?php

USE - it took me so much time of troubleshooting and it doesn't appear on the errors

Calling a single test

.vendor/bin/phpunit --filter [test method name] ex : ./vendor/bin/phpunit test_no_routes_when_created

Class Property vs Variable

$this->router = new Router(); vs $router = new Router();

$this : refers to current instance of class while $router is a variable. $this->router is an instance variable (property) of the class, and assigning a new instance of Router to it means you are setting the value of the class property.
$router : This syntax is used outside the context of a class or within a function that is not part of a class. $router is a local variable within the current scope (function, method, or global scope, depending on where it's used). It doesn't have the same visibility as a class property.

phpunit's People

Contributors

7daytheory avatar mattlowese avatar

Watchers

 avatar

phpunit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.