Skip to content

Commit

Permalink
phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutianliang committed May 17, 2019
1 parent 8d07e37 commit f150c33
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- '7.1'
- '7.2'

before_script:
Expand Down
10 changes: 10 additions & 0 deletions src/Shrimp/ShrimpWechat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions tests/MaterialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}


Expand Down
3 changes: 2 additions & 1 deletion tests/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 3 additions & 6 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tests/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f150c33

Please sign in to comment.