diff --git a/.travis.yml b/.travis.yml index 0ceeacd..833dc58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - '7.1' - '7.2' before_script: diff --git a/src/Shrimp/ShrimpWechat.php b/src/Shrimp/ShrimpWechat.php index af557d2..b1a8be3 100644 --- a/src/Shrimp/ShrimpWechat.php +++ b/src/Shrimp/ShrimpWechat.php @@ -105,6 +105,16 @@ public function __construct($appId, $secret, $bindAccessTokenCallable = true, $c self::$dispatcher = new EventDispatcher(); } + /** + * 获取事件调度器 + * + * @return EventDispatcher|null + */ + public function getDispatcher(): ?EventDispatcher + { + return self::$dispatcher; + } + /** * @param string $accessToken * @param int $expire diff --git a/tests/MaterialTest.php b/tests/MaterialTest.php index 871f5ba..fb8ddc7 100644 --- a/tests/MaterialTest.php +++ b/tests/MaterialTest.php @@ -32,16 +32,15 @@ public function __construct($name = null, array $data = [], $dataName = '') /** * 测试上传图片 + * * @throws Exception + * @expectedException Exception */ public function testUploadFile() { - try { - $file = new MediaFile(dirname(__DIR__) . '/example.png'); - $result = $this->sdk->material->uploadMaterialImage($file); - $this->assertCount(1, $result); - } catch (\Exception $e) { - } + $file = new MediaFile(dirname(__DIR__) . '/example.png'); + $result = $this->sdk->material->uploadMaterialImage($file); + self::assertCount(1, $result); } /** @@ -50,14 +49,12 @@ public function testUploadFile() * @param array $content * @param MediaFile $file * @throws Exception + * @expectedException Exception */ public function testCreatePictureContent(array $content, MediaFile $file) { - try { - $result = $this->sdk->material->createPictureContent($content, $file); - $this->assertArrayHasKey('media_id', $result); - } catch (Exception $e) { - } + $result = $this->sdk->material->createPictureContent($content, $file); + self::assertArrayHasKey('media_id', $result); } diff --git a/tests/MenuTest.php b/tests/MenuTest.php index 3b6beb2..b56069f 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -30,10 +30,11 @@ public function __construct($name = null, array $data = [], $dataName = '') /** * @throws Exception + * @expectedException Exception */ public function testMenuQuery() { $menu = $this->sdk->menu->menuQuery(); - $this->assertArrayHasKey('menu', $menu); + self::assertArrayHasKey('menu', $menu); } } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 46b9a09..4cde462 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -35,15 +35,12 @@ public function __construct($name = null, array $data = [], $dataName = '') * * @param $mediaId * @throws Exception + * @expectedException Exception */ public function testMassForTag($mediaId) { - try { - $result = $this->sdk->message->massForTag($mediaId, Message::TYPE_NEWS); - $this->assertArrayHasKey('msg_id', $result); - } catch (Exception $e) { - $this->assertContains("no permission for this msgtype hint", $e->getMessage()); - } + $result = $this->sdk->message->massForTag($mediaId, Message::TYPE_NEWS); + self::assertArrayHasKey('msg_id', $result); } /** diff --git a/tests/UserTest.php b/tests/UserTest.php index bed0a8b..d4ba5ed 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -30,23 +30,25 @@ public function __construct($name = null, array $data = [], $dataName = '') /** * @throws Exception + * @expectedException Exception */ public function testCreateLabel() { $name = "Test" . range('a', 'z')[mt_rand(0, 25)] . mt_rand(1, 100); $label = $this->sdk->user->createLabel($name); - $this->assertArrayHasKey('tag', $label); + self::assertArrayHasKey('tag', $label); $name = "Update" . range('a', 'z')[mt_rand(0, 25)] . mt_rand(1, 100); - $this->assertArrayHasKey('errcode', $this->sdk->user->updateLabel($label['tag']['id'], $name)); + self::assertArrayHasKey('errcode', $this->sdk->user->updateLabel($label['tag']['id'], $name)); } /** * @throws Exception + * @expectedException Exception */ public function testGetLabel() { $tags = $this->sdk->user->getLabel(); - $this->assertArrayHasKey('tags', $tags); + self::assertArrayHasKey('tags', $tags); } }