phpunit test mockup

네.. 목업하는 법, 테스트하는 법 다 까먹었구요..😥 이게 맞는 지 모르겠다.. 틀린게 있다면 누군가 알려준다면 좋겠당..

[1] elasticsearch client의 search method 목업 처리방법

$elasticMock = $this->mock(Client::class);
$elasticMock->shouldReceive('search')
            ->once()
            ->andReturn(json_decode(file_get_contents(__DIR__.'\Mock\product.json'), true));
  • product.json 파일
{
    "took": 3,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful" : 2,
        "skipped" : 0,
        "failed" : 0
    },
    "hits": {
        "total": {
            "value":1,
            "relation":"eq"
        },
        "max_score": null,
        "hits": [{
            "_index" : "product",
            "_type" : "_doc",
            "_id": "testadsfsdfad",
            "_score" : null,
            "_source": {
                "store_id" : "누누",
                "shop_name" : "눈뉴",
                "shop_no" : 1,
                "store_category" : "MALE_BAG"
            }
        }]
    }
}

[2] 커스텀 클래스의 메서드 목업 처리방법

$customMock = $this->mock(CustomClass::class);
$customMock->shouldReceive('getCustomMethod')
            ->once()
            ->andReturn([
                "test1" => '123456',
                "test2" => ["asdfsdf"]
            ]);

좋은 웹페이지 즐겨찾기