PHP code example of yunbuye / thinkphp-facade
1. Go to this page and download the library: Download yunbuye/thinkphp-facade 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/ */
yunbuye / thinkphp-facade example snippets
MyFacade::shouldReceive('get')
->once()
->with('key')
->andReturn('value');
MyFacade::get('key')=='value'//true
use Mockery;
use Mockery\Mock;
//先找到 Cache 对应的绑定实现类 think\Cache ,并对其进行模拟
$mock=Mockery::mock('think\Cache', function ($mock) {
/**
* @var Mock $mock
*/
$return='return';
$key='key';
return $mock->shouldReceive('get')->with($key)->andReturn($return);
});
Container::getInstance()->bindTo('think\Cache',$mock);
//模拟后,即 Cache Facade 也被模拟
Cache::get('key')=='return'//true