Skip to content

Commit

Permalink
修复:测试失败时日志文件未删除 (overtrue#318)
Browse files Browse the repository at this point in the history
* Add @after annotation to unlink log file after tests

* Add Mockery global helpers back
  • Loading branch information
zingimmick authored Nov 19, 2021
1 parent 94de413 commit a76bd3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/Gateways/ErrorlogGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@

class ErrorlogGatewayTest extends TestCase
{
protected $logFile = 'easy-sms-error-log-mock-file.log';

/**
* @after
*/
public function removeLogFile()
{
unlink($this->logFile);
}

public function testSend()
{
$logFile = 'easy-sms-error-log-mock-file.log';
$gateway = new ErrorlogGateway([
'file' => $logFile,
'file' => $this->logFile,
]);

$message = new Message([
Expand All @@ -33,13 +42,12 @@ public function testSend()

$gateway->send(new PhoneNumber(new PhoneNumber(18188888888)), $message, new Config());

$this->assertTrue(file_exists($logFile));
$this->assertFalse(
$this->assertTrue(file_exists($this->logFile));
$this->assertNotFalse(
strpos(
'to: 18188888888 | message: "This is a test message." | template: "" | data: {"foo":"bar"}',
file_get_contents($logFile)
file_get_contents($this->logFile),
'to: 18188888888 | message: "This is a test message." | template: "" | data: {"foo":"bar"}'
)
);
unlink($logFile);
}
}
17 changes: 17 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@

namespace Overtrue\EasySms\Tests;

use Mockery;

class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @before
*/
public function registerMockery()
{
Mockery::globalHelpers();
}

/**
* @after
*/
public function closeMockery()
{
Mockery::close();
}
}

0 comments on commit a76bd3e

Please sign in to comment.