1. Go to this page and download the library: Download getdkan/mock-chain 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/ */
$organs = (new Options())
->add("heart", Organ::class)
->add("lungs", "yep, the lungs");
$mock = (new Chain($this))
->add(System::class, "getOrgan", $organs)
->add(Organ::class, "getName", "heart")
->getMock();
$this->assertEquals("yep, the lungs",
$mock->getOrgan("lungs"));
$this->assertEquals("heart",
$mock->getOrgan("heart")->getName());
$organs = (new Options())
->add("heart",Organ::class)
->add("lung", "yep, the left lung")
->index(0);
$mock = (new Chain($this))
->add(System::class, "getOrganByNameAndIndex", $organs)
->add(Organ::class, "getName", "heart")
->getMock();
$this->assertEquals("yep, the left lung",
$mock->getOrganByNameAndIndex("lung", 0));
$this->assertEquals("heart",
$mock->getOrganByNameAndIndex("heart", 0)->getName());
$organs = (new Options())
->add(json_encode(["lung", 0]),"yep, the left lung")
->add(json_encode(["lung", 1]), "yep, the right lung");
$mock = (new Chain($this))
->add(System::class, "getOrganByNameAndIndex", $organs)
->add(Organ::class, "getName", "heart")
->getMock();
$this->assertEquals("yep, the left lung",
$mock->getOrganByNameAndIndex("lung", 0));
$this->assertEquals("yep, the right lung",
$mock->getOrganByNameAndIndex("lung", 1));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.