Skip to content

Commit

Permalink
feat:添加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
ricoa committed Apr 25, 2017
1 parent 030cd85 commit f0bbbce
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ use Ricoa\CopyWritingCorrect\CopyWritingCorrectService;

$service=new CopyWritingCorrectService();

$service->addCorrectors([new ExampleCorrector()]);//注入纠正器
$service->resetCorrectors([new ExampleCorrector()]);//重置纠正器,也即废弃默认的纠正器
$service->addCorrectors([ExampleCorrector::class]);//注入纠正器
$service->resetCorrectors([ExampleCorrector::class]);//重置纠正器,也即废弃默认的纠正器

$text=$service->correct('在LeanCloud上,数据存储是围绕AVObject进行的。');

Expand Down
50 changes: 50 additions & 0 deletions tests/unit/CorrectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
use Ricoa\CopyWritingCorrect\CopyWritingCorrectService;

/**
* 纠正器注入、重置功能
* Class CorrectorTest
*/
class CorrectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
}

protected function tearDown()
{
}

// tests
public function testMe()
{

$service=new CopyWritingCorrectService();

$correctors=[new class extends \Ricoa\CopyWritingCorrect\Correctors\Corrector{
protected static $corrector=null;
/**
* @param string $text
*
* @return mixed
*/
public function handle($text)
{
return $text;
}
}];
$service->addCorrectors($correctors);//注入纠正器

$this->assertEquals(
'使用 GitHub 登录',
$service->correct('使用github登录')
);

$service->resetCorrectors($correctors);//重置纠正器,也即废弃默认的纠正器

$this->assertEquals(
'使用github登录',
$service->correct('使用github登录')
);
}
}

0 comments on commit f0bbbce

Please sign in to comment.