summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-07-07 15:37:56 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-17 12:34:56 +0200
commita0c6f2e5e071a287717e58f32c5b3cf6e219f321 (patch)
tree231363a90e1c8296e8a06a0346078adc3c5e8454 /tests
parentbba87a2a3b46d20a552efa4a1d00d3253aedf27b (diff)
downloadnextcloud-server-a0c6f2e5e071a287717e58f32c5b3cf6e219f321.tar.gz
nextcloud-server-a0c6f2e5e071a287717e58f32c5b3cf6e219f321.zip
Use the decorator pattern
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/app/codechecker/codecheckertest.php16
-rw-r--r--tests/lib/app/codechecker/deprecationchecktest.php (renamed from tests/lib/app/codechecker/deprecationlisttest.php)24
-rw-r--r--tests/lib/app/codechecker/mock/testlist.php15
-rw-r--r--tests/lib/app/codechecker/nodevisitortest.php10
-rw-r--r--tests/lib/app/codechecker/strongcomparisonchecktest.php70
5 files changed, 110 insertions, 25 deletions
diff --git a/tests/lib/app/codechecker/codecheckertest.php b/tests/lib/app/codechecker/codecheckertest.php
index 93bf0b32c58..cdbb7c17da5 100644
--- a/tests/lib/app/codechecker/codecheckertest.php
+++ b/tests/lib/app/codechecker/codecheckertest.php
@@ -8,7 +8,9 @@
namespace Test\App\CodeChecker;
-use OC;
+use OC\App\CodeChecker\CodeChecker;
+use OC\App\CodeChecker\EmptyCheck;
+use OC\App\CodeChecker\PrivateCheck;
use Test\TestCase;
class CodeCheckerTest extends TestCase {
@@ -20,10 +22,10 @@ class CodeCheckerTest extends TestCase {
* @param string $fileToVerify
*/
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
- $checker = new OC\App\CodeChecker\CodeChecker(
- new OC\App\CodeChecker\PrivateList()
+ $checker = new CodeChecker(
+ new PrivateCheck(new EmptyCheck())
);
- $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
$this->assertEquals(1, count($errors));
$this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
@@ -46,10 +48,10 @@ class CodeCheckerTest extends TestCase {
* @param string $fileToVerify
*/
public function testPassValidUsage($fileToVerify) {
- $checker = new OC\App\CodeChecker\CodeChecker(
- new OC\App\CodeChecker\PrivateList()
+ $checker = new CodeChecker(
+ new PrivateCheck(new EmptyCheck())
);
- $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
$this->assertEquals(0, count($errors));
}
diff --git a/tests/lib/app/codechecker/deprecationlisttest.php b/tests/lib/app/codechecker/deprecationchecktest.php
index 2293d31a1f6..2cf64a9d186 100644
--- a/tests/lib/app/codechecker/deprecationlisttest.php
+++ b/tests/lib/app/codechecker/deprecationchecktest.php
@@ -6,12 +6,14 @@
* See the COPYING-README file.
*/
-namespace Test\App;
+namespace Test\App\CodeChecker;
-use OC;
+use OC\App\CodeChecker\CodeChecker;
+use OC\App\CodeChecker\DeprecationCheck;
+use OC\App\CodeChecker\EmptyCheck;
use Test\TestCase;
-class DeprecationListTest extends TestCase {
+class DeprecationCheckTest extends TestCase {
/**
* @dataProvider providesFilesToCheck
@@ -20,10 +22,10 @@ class DeprecationListTest extends TestCase {
* @param string $fileToVerify
*/
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
- $checker = new OC\App\CodeChecker\CodeChecker(
- new OC\App\CodeChecker\DeprecationList()
+ $checker = new CodeChecker(
+ new DeprecationCheck(new EmptyCheck())
);
- $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
$this->assertEquals(1, count($errors));
$this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
@@ -32,8 +34,6 @@ class DeprecationListTest extends TestCase {
public function providesFilesToCheck() {
return [
- ['==', 1005, 'test-equal.php'],
- ['!=', 1005, 'test-not-equal.php'],
['OCP\AppFramework\IApi', 1006, 'test-deprecated-use.php'],
['OCP\AppFramework\IApi', 1006, 'test-deprecated-use-alias.php'],
['AppFramework\IApi', 1001, 'test-deprecated-use-sub.php'],
@@ -46,16 +46,18 @@ class DeprecationListTest extends TestCase {
* @param string $fileToVerify
*/
public function testPassValidUsage($fileToVerify) {
- $checker = new OC\App\CodeChecker\CodeChecker(
- new OC\App\CodeChecker\DeprecationList()
+ $checker = new CodeChecker(
+ new DeprecationCheck(new EmptyCheck())
);
- $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
$this->assertEquals(0, count($errors));
}
public function validFilesData() {
return [
+ ['test-equal.php'],
+ ['test-not-equal.php'],
['test-extends.php'],
['test-implements.php'],
['test-static-call.php'],
diff --git a/tests/lib/app/codechecker/mock/testlist.php b/tests/lib/app/codechecker/mock/testlist.php
index c4985e8e625..5f5a9fcc38e 100644
--- a/tests/lib/app/codechecker/mock/testlist.php
+++ b/tests/lib/app/codechecker/mock/testlist.php
@@ -21,15 +21,24 @@
namespace Test\App\CodeChecker\Mock;
-use OC\App\CodeChecker\ICheckList;
+use OC\App\CodeChecker\ICheck;
-class TestList implements ICheckList {
+class TestList implements ICheck {
+ /** @var ICheck */
+ protected $check;
+
+ /**
+ * @param ICheck $check
+ */
+ public function __construct(ICheck $check) {
+ $this->check = $check;
+ }
/**
* @return string
*/
public function getDescription() {
- return 'deprecated';
+ return 'testing';
}
/**
diff --git a/tests/lib/app/codechecker/nodevisitortest.php b/tests/lib/app/codechecker/nodevisitortest.php
index 1207ca6a043..0b5aea28324 100644
--- a/tests/lib/app/codechecker/nodevisitortest.php
+++ b/tests/lib/app/codechecker/nodevisitortest.php
@@ -8,7 +8,9 @@
namespace Test\AppCodeChecker;
-use OC;
+use OC\App\CodeChecker\CodeChecker;
+use OC\App\CodeChecker\EmptyCheck;
+use Test\App\CodeChecker\Mock\TestList;
use Test\TestCase;
class NodeVisitorTest extends TestCase {
@@ -56,10 +58,10 @@ class NodeVisitorTest extends TestCase {
* @param string $fileToVerify
*/
public function testMethodsToCheck($expectedErrors, $fileToVerify) {
- $checker = new OC\App\CodeChecker\CodeChecker(
- new \Test\App\CodeChecker\Mock\TestList()
+ $checker = new CodeChecker(
+ new TestList(new EmptyCheck())
);
- $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
$this->assertCount(sizeof($expectedErrors), $errors);
diff --git a/tests/lib/app/codechecker/strongcomparisonchecktest.php b/tests/lib/app/codechecker/strongcomparisonchecktest.php
new file mode 100644
index 00000000000..c73eae286ab
--- /dev/null
+++ b/tests/lib/app/codechecker/strongcomparisonchecktest.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\App\CodeChecker;
+
+use OC\App\CodeChecker\CodeChecker;
+use OC\App\CodeChecker\EmptyCheck;
+use OC\App\CodeChecker\StrongComparisonCheck;
+use Test\TestCase;
+
+class StrongComparisonCheckTest extends TestCase {
+
+ /**
+ * @dataProvider providesFilesToCheck
+ * @param string $expectedErrorToken
+ * @param int $expectedErrorCode
+ * @param string $fileToVerify
+ */
+ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
+ $checker = new CodeChecker(
+ new StrongComparisonCheck(new EmptyCheck())
+ );
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+
+ $this->assertEquals(1, count($errors));
+ $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
+ $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']);
+ }
+
+ public function providesFilesToCheck() {
+ return [
+ ['==', 1005, 'test-equal.php'],
+ ['!=', 1005, 'test-not-equal.php'],
+ ];
+ }
+
+ /**
+ * @dataProvider validFilesData
+ * @param string $fileToVerify
+ */
+ public function testPassValidUsage($fileToVerify) {
+ $checker = new CodeChecker(
+ new StrongComparisonCheck(new EmptyCheck())
+ );
+ $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
+
+ $this->assertEquals(0, count($errors));
+ }
+
+ public function validFilesData() {
+ return [
+ ['test-deprecated-use.php'],
+ ['test-deprecated-use-alias.php'],
+ ['test-deprecated-use-sub.php'],
+ ['test-deprecated-use-sub-alias.php'],
+ ['test-extends.php'],
+ ['test-implements.php'],
+ ['test-static-call.php'],
+ ['test-const.php'],
+ ['test-new.php'],
+ ['test-use.php'],
+ ['test-identical-operator.php'],
+ ];
+ }
+}