1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the dingtalk. |
4
|
|
|
* User: Ilham Tahir <[email protected]> |
5
|
|
|
* This source file is subject to the MIT license that is bundled |
6
|
|
|
* with this source code in the file LICENSE. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aplisin\DingTalk\Tests; |
10
|
|
|
|
11
|
|
|
use Aplisin\DingTalk\Kernel\ServiceContainer; |
12
|
|
|
use Aplisin\DingTalk\Kernel\AccessToken; |
13
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
14
|
|
|
|
15
|
|
|
abstract class BaseCase extends BaseTestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param $name |
20
|
|
|
* @param array $methods |
21
|
|
|
* @param ServiceContainer|null $app |
22
|
|
|
* @return \Mockery\Mock |
23
|
|
|
*/ |
24
|
|
|
public function mockApiClient($name, $methods = [], ServiceContainer $app = null) |
25
|
|
|
{ |
26
|
|
|
$methods = implode(',', array_merge([ |
27
|
|
|
'httpGet', 'httpPost', 'httpPostJson', 'httpUpload', |
28
|
|
|
'request', 'requestRaw', 'registerMiddlewares', |
29
|
|
|
], (array) $methods)); |
30
|
|
|
|
31
|
|
|
$client = \Mockery::mock( |
32
|
|
|
$name."[{$methods}]", |
33
|
|
|
[$app ?? \Mockery::mock(ServiceContainer::class), |
34
|
|
|
\Mockery::mock(AccessToken::class), ] |
35
|
|
|
)->shouldAllowMockingProtectedMethods(); |
36
|
|
|
$client->allows()->registerHttpMiddlewares()->andReturnNull(); |
37
|
|
|
|
38
|
|
|
return $client; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function tearDown() |
42
|
|
|
{ |
43
|
|
|
parent::tearDown(); |
44
|
|
|
if ($container = \Mockery::getContainer()) { |
45
|
|
|
$this->addToAssertionCount($container->Mockery_getExpectationCount()); |
46
|
|
|
} |
47
|
|
|
\Mockery::close(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|