This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "DummyAuthorizer.php"; | |
require_once "System.php"; | |
function test_system_has_no_loggedin_users() { | |
/* | |
* In this test I want to test loginCount() method and we don't need to provide any real authorizer to create the system object | |
* So we are passing a DummyAuthorizer whose authorize method would never be called from this test | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "AuthorizerInterface.php"; | |
class System { | |
public function __construct(AuthorizerInterface $authorizer) { | |
$this->authorizer = $authorizer; | |
} | |
public function loginCount() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// define a curry function | |
$make_adder = function ($num1) { | |
return function ($num2) use ($num1) { | |
return $num1 + $num2; | |
}; | |
}; | |
$five_adder = $make_adder(5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// define a function that accepts a callable | |
function decorate(callable $func) { | |
return "<p>" . $func() . "</p>"; | |
} | |
// execute decorate by passing an anonymous function | |
$result = decorate(function () { | |
return "Hello World!"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// create a lamda function by assigning an anonymous function to a variable | |
$greet = function ($name) { | |
return "Hello {$name}"; | |
}; | |
// it will print Hello World | |
echo $greet("World") . PHP_EOL; |