新增phpunit
This commit is contained in:
@@ -32,7 +32,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^4.2",
|
"symfony/var-dumper": "^4.2",
|
||||||
"topthink/think-trace":"^1.0"
|
"topthink/think-trace":"^1.0",
|
||||||
|
"phpunit/phpunit": "^8.5"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -43,6 +44,11 @@
|
|||||||
"": "extend/"
|
"": "extend/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"catchAdmin\\tests\\": "tests"
|
||||||
|
}
|
||||||
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"preferred-install": "dist"
|
"preferred-install": "dist"
|
||||||
},
|
},
|
||||||
|
1728
composer.lock
generated
1728
composer.lock
generated
File diff suppressed because it is too large
Load Diff
31
phpunit.xml
Normal file
31
phpunit.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Feature">
|
||||||
|
<directory suffix="Test.php">./tests/feature</directory>
|
||||||
|
</testsuite>
|
||||||
|
|
||||||
|
<testsuite name="Unit">
|
||||||
|
<directory suffix="Test.php">./tests/unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">./app</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
<php>
|
||||||
|
<env name="APP_ENV" value="testing"/>
|
||||||
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
|
<env name="QUEUE_DRIVER" value="sync"/>
|
||||||
|
</php>
|
||||||
|
</phpunit>
|
49
tests/unit/TrieTest.php
Normal file
49
tests/unit/TrieTest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
namespace catchAdmin\tests\unit;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use catcher\library\Trie;
|
||||||
|
|
||||||
|
class TrieTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function getTries()
|
||||||
|
{
|
||||||
|
$words = [
|
||||||
|
'你大爷', '尼玛', 'SB'
|
||||||
|
];
|
||||||
|
|
||||||
|
$trie = new Trie();
|
||||||
|
|
||||||
|
foreach ($words as $word) {
|
||||||
|
$trie->add($word);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $trie->getTries();
|
||||||
|
}
|
||||||
|
public function testData()
|
||||||
|
{
|
||||||
|
$this->assertEquals([
|
||||||
|
'你' => ['大' => ['爷' => ['end' => true]]],
|
||||||
|
'尼' => ['玛' => ['end' => true]],
|
||||||
|
'S' => ['B' => ['end' => true]],
|
||||||
|
], $this->getTries());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReplace()
|
||||||
|
{
|
||||||
|
$string = '你大爷的真尼玛SB';
|
||||||
|
|
||||||
|
$this->assertEquals('***的真****',(new Trie())->replace($this->getTries(), $string));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasSensitiveWord()
|
||||||
|
{
|
||||||
|
$string = '你大爷的真尼玛SB';
|
||||||
|
|
||||||
|
$res = (new Trie())->getSensitiveWords($this->getTries(), $string, false);
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertEquals('你大爷', $res);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user