From 661bc3168df207e820b3fac06a7aad98d79745ff Mon Sep 17 00:00:00 2001 From: Jaeger Date: Mon, 10 Dec 2018 00:13:16 +0800 Subject: [PATCH] add phpunit --- composer.json | 8 +++++- phpunit.xml | 19 ++++++++++++++ tests/Feature/InstanceTest.php | 48 ++++++++++++++++++++++++++++++++++ tests/TestCaseBase.php | 20 ++++++++++++++ tests/assets/snippet-1.html | 9 +++++++ tests/bootstrap.php | 5 ++++ 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml create mode 100644 tests/Feature/InstanceTest.php create mode 100644 tests/TestCaseBase.php create mode 100644 tests/assets/snippet-1.html create mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index c14f601..d5e2232 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,13 @@ "QL\\":"src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "require-dev": { - "symfony/var-dumper": "^3.3" + "symfony/var-dumper": "^3.3", + "phpunit/phpunit": "^7.5" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ba72a84 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + ./tests + + + + + + src + + + + \ No newline at end of file diff --git a/tests/Feature/InstanceTest.php b/tests/Feature/InstanceTest.php new file mode 100644 index 0000000..58c268d --- /dev/null +++ b/tests/Feature/InstanceTest.php @@ -0,0 +1,48 @@ +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()); + } +} \ No newline at end of file diff --git a/tests/TestCaseBase.php b/tests/TestCaseBase.php new file mode 100644 index 0000000..c88d73e --- /dev/null +++ b/tests/TestCaseBase.php @@ -0,0 +1,20 @@ + +
+ QueryList官网 + 这是图片 + 这是图片2 + QueryList文档 +
+ 其它的一些文本 + \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..eace7af --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,5 @@ +