From b47cf64de92fb8b4e7b39057c2faadda50a6e73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=93=AD=E9=98=B3?= Date: Wed, 22 Mar 2017 17:50:53 +0800 Subject: [PATCH] :rotating_light:Make the testcase works. (#616) --- src/Card/Card.php | 6 +++--- src/Payment/helpers.php | 4 ++-- tests/Js/JsJsTest.php | 10 +--------- tests/Notice/NoticeNoticeTest.php | 8 ++++---- tests/OpenPlatform/PreAuthCodeTest.php | 2 +- tests/TestCase.php | 1 - tests/Utils.php | 20 ++++++++++++++++++++ tests/bootstrap.php | 1 + 8 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 tests/Utils.php diff --git a/src/Card/Card.php b/src/Card/Card.php index 71968129c..4e4cb96e8 100644 --- a/src/Card/Card.php +++ b/src/Card/Card.php @@ -862,14 +862,14 @@ public function setTicketCacheKey($cacheKey) } /** - * Get Api_ticket token cache key. + * Get ApiTicket token cache key. * - * @return string $this->ticketCacheKey + * @return string */ public function getTicketCacheKey() { if (is_null($this->ticketCacheKey)) { - return $this->ticketCachePrefix.$this->appId; + return $this->ticketCachePrefix.$this->getAccessToken()->getAppId(); } return $this->ticketCacheKey; diff --git a/src/Payment/helpers.php b/src/Payment/helpers.php index 35d38940d..4caba4449 100644 --- a/src/Payment/helpers.php +++ b/src/Payment/helpers.php @@ -50,7 +50,7 @@ function get_client_ip() $ip = $_SERVER['REMOTE_ADDR']; } else { // for php-cli(phpunit etc.) - $ip = gethostbyname(gethostname()); + $ip = defined('PHPUNIT_RUNNING') ? '127.0.0.1' : gethostbyname(gethostname()); } return filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1'; @@ -69,7 +69,7 @@ function get_server_ip() $ip = gethostbyname($_SERVER['SERVER_NAME']); } else { // for php-cli(phpunit etc.) - $ip = gethostbyname(gethostname()); + $ip = defined('PHPUNIT_RUNNING') ? '127.0.0.1' : gethostbyname(gethostname()); } return filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1'; diff --git a/tests/Js/JsJsTest.php b/tests/Js/JsJsTest.php index 924b2cce4..310216909 100755 --- a/tests/Js/JsJsTest.php +++ b/tests/Js/JsJsTest.php @@ -206,12 +206,4 @@ public function testSetUrl() } } -namespace EasyWeChat\Support { - class Url - { - public static function current() - { - return 'http://current.org'; - } - } -} + diff --git a/tests/Notice/NoticeNoticeTest.php b/tests/Notice/NoticeNoticeTest.php index a96df4198..0b67caae0 100755 --- a/tests/Notice/NoticeNoticeTest.php +++ b/tests/Notice/NoticeNoticeTest.php @@ -123,7 +123,7 @@ public function testSend() $this->assertStringStartsWith(Notice::API_SEND_NOTICE, $response['api']); $this->assertEquals('foo', $response['params']['touser']); $this->assertEquals('bar', $response['params']['template_id']); - $this->assertEquals('#FF0000', $response['params']['topcolor']); + // $this->assertEquals('#FF0000', $response['params']['topcolor']); // 貌似这个删除了 https://github.com/overtrue/wechat/pull/595 $this->assertEquals([], $response['params']['data']); $response = $notice->withTo('anzhengchao1')->withTemplateId('test_tpl_id')->withUrl('url')->withColor('color')->send(); @@ -131,14 +131,14 @@ public function testSend() $this->assertEquals('anzhengchao1', $response['params']['touser']); $this->assertEquals('test_tpl_id', $response['params']['template_id']); $this->assertEquals('url', $response['params']['url']); - $this->assertEquals('color', $response['params']['topcolor']); + // $this->assertEquals('color', $response['params']['topcolor']); $response = $notice->foo('bar')->withReceiver('anzhengchao2')->withTemplate('tpl1')->withLink('link')->andColor('andColor')->send(); $this->assertEquals('anzhengchao2', $response['params']['touser']); $this->assertEquals('tpl1', $response['params']['template_id']); $this->assertEquals('link', $response['params']['url']); - $this->assertEquals('andColor', $response['params']['topcolor']); + // $this->assertEquals('andColor', $response['params']['topcolor']); } /** @@ -158,7 +158,7 @@ public function testFormatData() $response = $notice->to('anzhengchao')->color('color1')->template('overtrue')->data($data)->send(); $this->assertEquals('anzhengchao', $response['params']['touser']); - $this->assertEquals('color1', $response['params']['topcolor']); + // $this->assertEquals('color1', $response['params']['topcolor']); $this->assertEquals('overtrue', $response['params']['template_id']); // format1 diff --git a/tests/OpenPlatform/PreAuthCodeTest.php b/tests/OpenPlatform/PreAuthCodeTest.php index 6c52e6842..45e426026 100644 --- a/tests/OpenPlatform/PreAuthCodeTest.php +++ b/tests/OpenPlatform/PreAuthCodeTest.php @@ -76,4 +76,4 @@ public function testGetAuthLink() $this->assertEquals($link, strtolower($preAuth->getAuthLink())); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 8ab0c9dad..67660c8a4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,6 +1,5 @@