add phpunit
This commit is contained in:
parent
6d182ff061
commit
661bc3168d
@ -24,7 +24,13 @@
|
|||||||
"QL\\":"src"
|
"QL\\":"src"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^3.3"
|
"symfony/var-dumper": "^3.3",
|
||||||
|
"phpunit/phpunit": "^7.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
phpunit.xml
Normal file
19
phpunit.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<phpunit
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="querylist">
|
||||||
|
<directory>./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
</phpunit>
|
48
tests/Feature/InstanceTest.php
Normal file
48
tests/Feature/InstanceTest.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: x
|
||||||
|
* Date: 2018/12/9
|
||||||
|
* Time: 11:10 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
|
||||||
|
use QL\QueryList;
|
||||||
|
use Tests\TestCaseBase;
|
||||||
|
|
||||||
|
class InstanceTest extends TestCaseBase
|
||||||
|
{
|
||||||
|
protected $html;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->html = $this->getSnippet('snippet-1');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function singleton_instance_mode()
|
||||||
|
{
|
||||||
|
$ql = QueryList::getInstance()->html($this->html);
|
||||||
|
$ql2 = QueryList::getInstance();
|
||||||
|
$this->assertEquals($ql->getHtml(),$ql2->getHtml());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function get_new_object()
|
||||||
|
{
|
||||||
|
$ql = (new QueryList())->html($this->html);
|
||||||
|
$ql2 = new QueryList();
|
||||||
|
$this->assertNotEquals($ql->getHtml(),$ql2->getHtml());
|
||||||
|
|
||||||
|
$ql = QueryList::range('')->html($this->html);
|
||||||
|
$ql2 = QueryList::range('');
|
||||||
|
$this->assertNotEquals($ql->getHtml(),$ql2->getHtml());
|
||||||
|
}
|
||||||
|
}
|
20
tests/TestCaseBase.php
Normal file
20
tests/TestCaseBase.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: x
|
||||||
|
* Date: 2018/12/9
|
||||||
|
* Time: 11:43 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class TestCaseBase extends TestCase
|
||||||
|
{
|
||||||
|
public function getSnippet($name)
|
||||||
|
{
|
||||||
|
return file_get_contents(__DIR__.'/assets/'.$name.'.html');
|
||||||
|
}
|
||||||
|
}
|
9
tests/assets/snippet-1.html
Normal file
9
tests/assets/snippet-1.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<div id="one">
|
||||||
|
<div class="two">
|
||||||
|
<a href="http://querylist.cc">QueryList官网</a>
|
||||||
|
<img src="http://querylist.com/1.jpg" alt="这是图片" abc="这是一个自定义属性">
|
||||||
|
<img class="second_pic" src="http://querylist.com/2.jpg" alt="这是图片2">
|
||||||
|
<a href="http://doc.querylist.cc">QueryList文档</a>
|
||||||
|
</div>
|
||||||
|
<span>其它的<b>一些</b>文本</span>
|
||||||
|
</div>
|
5
tests/bootstrap.php
Normal file
5
tests/bootstrap.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
require __DIR__.'/../vendor/autoload.php';
|
Loading…
x
Reference in New Issue
Block a user