PHP code example of holistic-agency / frozen

1. Go to this page and download the library: Download holistic-agency/frozen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

holistic-agency / frozen example snippets


// src/MyClass.php
use HolisticAgency\Decouple\ClockInterface;
use Psr\Clock\ClockInterface;

class MyClass
{
    public function myMethod(ClockInterface $clock)
    {
        // some code ...

        $now = $clock->now()->format('Y-m-d H:i:s T');

        // some code ...
    }
}

// src/Elsewhere.php
use HolisticAgency\Decouple\Clock;

$myClass = new Myclass();
$myClass->myMethod(new Clock());

// tests/MyClassTest.php
use HolisticAgency\Decouple\Frozen\Clock;

class MyClassTest
{
    public function testMyMethod()
    {
        // Given
        $myTestClass = new MyClass();
        $frozen = new Clock(new DateTimeImmutable('2022-02-05 16:32:29 CET'));

        // When
        $actual = $myTestClass->myMethod($frozen);

        // Then
        // assert what you need
        // knowing $now is equal to '2022-02-05 16:32:29 CET'
        // inside myMethod()
    }
}

$generator = new MersenneTwister();
$unknon = $generator->draw(); // an integer between 0 and PHP_INT_MAX nerator->draw() ; // an integer between 1 and 6 = $guesser->draw(); // 10
$cheater = $guesser->draw(); // 17
$cheater = $guesser->draw(); //  1
$cheater = $guesser->draw(); // 10

// src/MyNetwork.php
use HolisticAgency\Decouple\NetworkInterface;

class MyNetwork
{
    public checkIfRemoteIsAvailable(NetworkInterface $network, string $remote): bool
    {
        return $network->resolve($remote) != '';
    }
}

// tests/MyNetworkTest.php
use HolisticAgency\Decouple\Frozen\Network as FrozenNetwork;

class MyNetworkTest
{
    public function testCheckIfRemoteIsAvailable()
    {
        // Given
        $myTestClass = new MyNetwork();
        $frozen = new FrozenNetwork(
            'production.local',
            '192.168.1.10',
            'app.my.org',
            ['proxy.inside.local' => '10.10.0.10'],
        );

        // When
        $actual1 = $myTestClass->checkIfRemoteIsAvailable($frozen, 'api.outside.net');
        $actual2 = $myTestClass->checkIfRemoteIsAvailable($frozen, 'proxy.inside.local');

        // Then
        // $actual1 is false
        // $actual2 is tue
    }
}