From 1dc8acd2633e68f6ad9fba8009ae888b25d021f4 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Wed, 7 Feb 2018 21:33:22 +0700 Subject: [PATCH 1/5] Replace cache to Symfony/Cache component. --- .gitignore | 2 + composer.json | 4 + composer.lock | 250 ++++++++++++++++++++++-- runtime/cache/.gitkeep | 0 src/B8Framework/Cache.php | 31 --- src/B8Framework/Cache/ApcCache.php | 149 -------------- src/B8Framework/Cache/RequestCache.php | 90 --------- src/B8Framework/Model.php | 3 +- src/B8Framework/Type/CacheInterface.php | 24 --- src/PHPCensor/Helper/Github.php | 12 +- src/PHPCensor/Model/BuildError.php | 4 +- src/PHPCensor/Model/BuildMeta.php | 4 +- src/PHPCensor/Model/Project.php | 8 +- tests/B8Framework/CacheTest.php | 38 ---- 14 files changed, 257 insertions(+), 362 deletions(-) create mode 100644 runtime/cache/.gitkeep delete mode 100644 src/B8Framework/Cache.php delete mode 100644 src/B8Framework/Cache/ApcCache.php delete mode 100644 src/B8Framework/Cache/RequestCache.php delete mode 100644 src/B8Framework/Type/CacheInterface.php delete mode 100755 tests/B8Framework/CacheTest.php diff --git a/.gitignore b/.gitignore index 57a654d7..4c882368 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ /vendor /composer.phar /runtime + /app/config.yml /public/assets/vendor + /public/artifacts !/public/artifacts/.gitkeep diff --git a/composer.json b/composer.json index 113147cb..71a9790e 100644 --- a/composer.json +++ b/composer.json @@ -56,6 +56,7 @@ "symfony/debug": "~3.4.0", "symfony/dependency-injection": "~3.4.0", "symfony/event-dispatcher": "~3.4.0", + "symfony/cache": "~3.4.0", "psr/log": "~1.0.0", "monolog/monolog": "~1.22.0", "pimple/pimple": "~3.0.0", @@ -94,6 +95,9 @@ "mremi/flowdock": "For FlowdockNotify plugin" }, "extra": { + "platform": { + "php": "5.6.*" + }, "installer-paths": { "public/assets/vendor/sprintf-js": ["npm-asset/sprintf-js"], "public/assets/vendor/codemirror": ["npm-asset/codemirror"], diff --git a/composer.lock b/composer.lock index 1048f470..ac6cba9d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "68c69d9aed8a6c9ef73856c6ddc9ab23", + "content-hash": "acf206f49431b95f0fadc3a765e6930a", "packages": [ { "name": "behat/gherkin", @@ -1602,16 +1602,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.7.26", + "version": "5.7.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd" + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd", - "reference": "7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", "shasum": "" }, "require": { @@ -1635,7 +1635,7 @@ "sebastian/global-state": "^1.1", "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", - "sebastian/version": "~1.0.3|~2.0", + "sebastian/version": "^1.0.6|^2.0.1", "symfony/yaml": "~2.1|~3.0|~4.0" }, "conflict": { @@ -1680,7 +1680,7 @@ "testing", "xunit" ], - "time": "2017-12-17T06:14:38+00:00" + "time": "2018-02-01T05:50:59+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -1787,6 +1787,52 @@ ], "time": "2015-09-11T15:10:35+00:00" }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2016-08-06T20:24:11+00:00" + }, { "name": "psr/container", "version": "1.0.0", @@ -1933,6 +1979,54 @@ ], "time": "2016-10-10T12:19:37+00:00" }, + { + "name": "psr/simple-cache", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-01-02T13:31:39+00:00" + }, { "name": "robmorgan/phinx", "version": "v0.8.1", @@ -2880,6 +2974,76 @@ "homepage": "https://symfony.com", "time": "2018-01-03T07:37:34+00:00" }, + { + "name": "symfony/cache", + "version": "v3.4.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/cache.git", + "reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/cache/zipball/8dee9ec2c9824c3f4039960d679a6689ee1cbdc1", + "reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "psr/cache": "~1.0", + "psr/log": "~1.0", + "psr/simple-cache": "^1.0", + "symfony/polyfill-apcu": "~1.1" + }, + "conflict": { + "symfony/var-dumper": "<3.3" + }, + "provide": { + "psr/cache-implementation": "1.0", + "psr/simple-cache-implementation": "1.0" + }, + "require-dev": { + "cache/integration-tests": "dev-master", + "doctrine/cache": "~1.6", + "doctrine/dbal": "~2.4", + "predis/predis": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Cache\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Cache component with PSR-6, PSR-16, and tags", + "homepage": "https://symfony.com", + "keywords": [ + "caching", + "psr6" + ], + "time": "2018-01-18T22:16:57+00:00" + }, { "name": "symfony/config", "version": "v3.4.4", @@ -3409,17 +3573,73 @@ "time": "2018-01-03T07:37:34+00:00" }, { - "name": "symfony/polyfill-mbstring", - "version": "v1.6.0", + "name": "symfony/polyfill-apcu", + "version": "v1.7.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" + "url": "https://github.com/symfony/polyfill-apcu.git", + "reference": "e8ae2136ddb53dea314df56fcd88e318ab936c00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "url": "https://api.github.com/repos/symfony/polyfill-apcu/zipball/e8ae2136ddb53dea314df56fcd88e318ab936c00", + "reference": "e8ae2136ddb53dea314df56fcd88e318ab936c00", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Apcu\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting apcu_* functions to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "apcu", + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2018-01-30T19:27:44+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", "shasum": "" }, "require": { @@ -3431,7 +3651,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.7-dev" } }, "autoload": { @@ -3465,7 +3685,7 @@ "portable", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-01-30T19:27:44+00:00" }, { "name": "symfony/process", diff --git a/runtime/cache/.gitkeep b/runtime/cache/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/B8Framework/Cache.php b/src/B8Framework/Cache.php deleted file mode 100644 index 0fc477cd..00000000 --- a/src/B8Framework/Cache.php +++ /dev/null @@ -1,31 +0,0 @@ -isEnabled()) { - return $default; - } - - $success = false; - $rtn = apc_fetch($key, $success); - if (!$success) { - $rtn = $default; - } - - return $rtn; - } - - /** - * Add an item to the cache: - * - * @param string $key - * @param mixed $value - * @param integer $ttl - * - * @return array|bool - */ - public function set($key, $value = null, $ttl = 0) - { - if (!$this->isEnabled()) { - return false; - } - - return apc_store($key, $value, $ttl); - } - - /** - * Remove an item from the cache: - * - * @param string $key - * - * @return bool|string[] - */ - public function delete($key) - { - if (!$this->isEnabled()) { - return false; - } - - return apc_delete($key); - } - - /** - * Check if an item is in the cache: - * - * @param string $key - * - * @return bool|string[] - */ - public function contains($key) - { - if (!$this->isEnabled()) { - return false; - } - - return apc_exists($key); - } - - /** - * Short-hand syntax for get() - * - * @see Config::get() - * - * @param string $key - * - * @return mixed - */ - public function __get($key) - { - return $this->get($key, null); - } - - /** - * Short-hand syntax for set() - * - * @see Config::set() - * - * @param string $key - * @param mixed $value - * - * @return array|bool - */ - public function __set($key, $value = null) - { - return $this->set($key, $value); - } - - /** - * Is set - * - * @param string $key - * - * @return bool|string[] - */ - public function __isset($key) - { - return $this->contains($key); - } - - /** - * Unset - * - * @param string $key - */ - public function __unset($key) - { - $this->delete($key); - } -} diff --git a/src/B8Framework/Cache/RequestCache.php b/src/B8Framework/Cache/RequestCache.php deleted file mode 100644 index 97b5a77c..00000000 --- a/src/B8Framework/Cache/RequestCache.php +++ /dev/null @@ -1,90 +0,0 @@ -contains($key) ? $this->data[$key] : $default; - } - - /** - * Add an item to the cache: - */ - public function set($key, $value = null, $ttl = 0) - { - $this->data[$key] = $value; - - return $this; - } - - /** - * Remove an item from the cache: - */ - public function delete($key) - { - if ($this->contains($key)) { - unset($this->data[$key]); - } - - return $this; - } - - /** - * Check if an item is in the cache: - */ - public function contains($key) - { - return array_key_exists($key, $this->data); - } - - /** - * Short-hand syntax for get() - * @see Config::get() - */ - public function __get($key) - { - return $this->get($key, null); - } - - /** - * Short-hand syntax for set() - * @see Config::set() - */ - public function __set($key, $value = null) - { - return $this->set($key, $value); - } - - /** - * Is set - */ - public function __isset($key) - { - return $this->contains($key); - } - - /** - * Unset - */ - public function __unset($key) - { - $this->delete($key); - } -} diff --git a/src/B8Framework/Model.php b/src/B8Framework/Model.php index 6b4c3d3d..a269c346 100644 --- a/src/B8Framework/Model.php +++ b/src/B8Framework/Model.php @@ -3,6 +3,7 @@ namespace b8; use b8\Exception\HttpException; +use Symfony\Component\Cache\Simple\ArrayCache; class Model { @@ -23,7 +24,7 @@ class Model $this->data = array_merge($this->data, $initialData); } - $this->cache = Cache::getCache(Cache::TYPE_REQUEST); + $this->cache = new ArrayCache(); } /** diff --git a/src/B8Framework/Type/CacheInterface.php b/src/B8Framework/Type/CacheInterface.php deleted file mode 100644 index 99097c78..00000000 --- a/src/B8Framework/Type/CacheInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -get(('https://api.github.com' . $url), [ 'query' => $params, ]); - + $body = json_decode($response->getBody(), true); $headers = $response->getHeaders(); - + foreach ($body as $item) { $results[] = $item; } @@ -62,8 +62,8 @@ class Github return []; } - $cache = Cache::getCache(Cache::TYPE_APC); - $rtn = $cache->get('php-censor-github-repos'); + $cache = new FilesystemCache('', 0, RUNTIME_DIR . 'cache'); + $rtn = $cache->get('php-censor.github-repos'); if (!$rtn) { $client = new Client(); @@ -90,7 +90,7 @@ class Github } } - $cache->set('php-censor-github-repos', $rtn); + $cache->set('php-censor.github-repos', $rtn, 3600); } return $rtn; diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index bfb0bc20..5b7bbf1c 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -397,8 +397,8 @@ class BuildError extends Model return null; } - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'php-censor.build-' . $key; + $rtn = $this->cache->get($cacheKey); if (empty($rtn)) { $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 0efa761c..1c2881a2 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -181,8 +181,8 @@ class BuildMeta extends Model return null; } - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'php-censor.build-' . $key; + $rtn = $this->cache->get($cacheKey); if (empty($rtn)) { $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index bf461b7a..c6ad79be 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -453,8 +453,8 @@ class Project extends Model return null; } - $cacheKey = 'Cache.ProjectGroup.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'php-censor.project-group-' . $key; + $rtn = $this->cache->get($cacheKey); if (empty($rtn)) { $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); @@ -741,8 +741,8 @@ class Project extends Model return null; } - $cacheKey = 'Cache.ProjectEnvironments.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'php-censor.project-environments-' . $key; + $rtn = $this->cache->get($cacheKey); if (empty($rtn)) { $store = $this->getEnvironmentStore(); diff --git a/tests/B8Framework/CacheTest.php b/tests/B8Framework/CacheTest.php deleted file mode 100755 index 28fbe2f0..00000000 --- a/tests/B8Framework/CacheTest.php +++ /dev/null @@ -1,38 +0,0 @@ -set('DisableCaching', true); - - $cache = Cache::getCache(Cache::TYPE_APC); - $this->assertFalse($cache->isEnabled()); - $this->assertFalse($cache->set('anything', 10)); - $this->assertTrue(is_null($cache->get('anything'))); - - Config::getInstance()->set('DisableCaching', false); - } - - public function testCaching() - { - $cache = Cache::getCache(Cache::TYPE_APC); - - if ($cache->isEnabled()) { - $this->assertTrue($cache->set('anything', 10)); - $this->assertTrue($cache->get('anything') == 10); - $this->assertTrue(is_null($cache->get('invalid'))); - } - } -} From c05d3d6c90b944d7ef92a2db2e32512b76302d53 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 16 Feb 2018 16:41:56 +0700 Subject: [PATCH 2/5] Fixed PHPUnit assert calls to static. --- tests/B8Framework/DatabaseTest.php | 10 +- tests/B8Framework/FormTest.php | 117 ++++++++++-------- tests/B8Framework/HttpExceptionTest.php | 36 +++--- tests/B8Framework/ViewTest.php | 40 +++--- .../Command/CreateAdminCommandTest.php | 4 +- .../PHPCensor/Command/InstallCommandTest.php | 30 ++--- .../Controller/WebhookControllerTest.php | 10 +- tests/PHPCensor/Helper/AnsiConverterTest.php | 2 +- .../Helper/BuildInterpolatorTest.php | 4 +- .../PHPCensor/Helper/CommandExecutorTest.php | 22 ++-- tests/PHPCensor/Helper/LangTest.php | 6 +- tests/PHPCensor/Helper/MailerFactoryTest.php | 22 ++-- tests/PHPCensor/Model/BuildTest.php | 42 +++---- tests/PHPCensor/Model/ProjectTest.php | 24 ++-- tests/PHPCensor/Plugin/EmailTest.php | 46 +++---- .../Plugin/Option/PhpUnitOptionsTest.php | 14 +-- tests/PHPCensor/Plugin/PharTest.php | 54 ++++---- tests/PHPCensor/Plugin/Util/ExecutorTest.php | 16 +-- tests/PHPCensor/Plugin/Util/FactoryTest.php | 12 +- .../Plugin/Util/PhpUnitResultTest.php | 26 ++-- .../PosixProcessControlTest.php | 2 +- .../ProcessControl/ProcessControlTest.php | 12 +- .../ProcessControl/UnixProcessControlTest.php | 2 +- .../Security/Authentication/ServiceTest.php | 14 +-- .../UserProvider/InternalTest.php | 6 +- tests/PHPCensor/Service/BuildServiceTest.php | 64 +++++----- .../Service/BuiltStatusServiceTest.php | 6 +- .../PHPCensor/Service/ProjectServiceTest.php | 36 +++--- tests/PHPCensor/Service/UserServiceTest.php | 22 ++-- 29 files changed, 355 insertions(+), 346 deletions(-) diff --git a/tests/B8Framework/DatabaseTest.php b/tests/B8Framework/DatabaseTest.php index 0820f275..7a353e8d 100755 --- a/tests/B8Framework/DatabaseTest.php +++ b/tests/B8Framework/DatabaseTest.php @@ -47,7 +47,7 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase $this->checkDatabaseConnection(); $connection = Database::getConnection('write'); - $this->assertInstanceOf('\b8\Database', $connection); + self::assertInstanceOf('\b8\Database', $connection); } public function testGetDetails() @@ -55,10 +55,10 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase $this->checkDatabaseConnection(); $details = Database::getConnection('read')->getDetails(); - $this->assertTrue(is_array($details)); - $this->assertTrue(($details['db'] == DB_NAME)); - $this->assertTrue(($details['user'] == DB_USER)); - $this->assertTrue(($details['pass'] == DB_PASS)); + self::assertTrue(is_array($details)); + self::assertTrue(($details['db'] == DB_NAME)); + self::assertTrue(($details['user'] == DB_USER)); + self::assertTrue(($details['pass'] == DB_PASS)); } /** diff --git a/tests/B8Framework/FormTest.php b/tests/B8Framework/FormTest.php index d8def11f..fbca322b 100755 --- a/tests/B8Framework/FormTest.php +++ b/tests/B8Framework/FormTest.php @@ -2,9 +2,11 @@ namespace Tests\b8; -use b8\Form, b8\Config; +use b8\Form; +use b8\Config; +use PHPUnit\Framework\TestCase; -class FormTest extends \PHPUnit\Framework\TestCase +class FormTest extends TestCase { public function testFormBasics() { @@ -12,8 +14,8 @@ class FormTest extends \PHPUnit\Framework\TestCase $f->setAction('/'); $f->setMethod('POST'); - $this->assertTrue($f->getAction() == '/'); - $this->assertTrue($f->getMethod() == 'POST'); + self::assertTrue($f->getAction() == '/'); + self::assertTrue($f->getMethod() == 'POST'); $config = new Config([ 'b8' => [ @@ -23,10 +25,11 @@ class FormTest extends \PHPUnit\Framework\TestCase ] ]); - $this->assertTrue($f->render('form') == '/POST'); + self::assertTrue($f->render('form') == '/POST'); Config::getInstance()->set('b8.view.path', ''); - $this->assertTrue(strpos((string)$f, 'setClass('element-class'); $f->setContainerClass('container-class'); - $this->assertTrue($f->getName() == 'element-name'); - $this->assertTrue($f->getId() == 'element-id'); - $this->assertTrue($f->getLabel() == 'element-label'); - $this->assertTrue($f->getClass() == 'element-class'); - $this->assertTrue($f->getContainerClass() == 'container-class'); + self::assertTrue($f->getName() == 'element-name'); + self::assertTrue($f->getId() == 'element-id'); + self::assertTrue($f->getLabel() == 'element-label'); + self::assertTrue($f->getClass() == 'element-class'); + self::assertTrue($f->getContainerClass() == 'container-class'); $output = $f->render(); - $this->assertTrue(is_string($output)); - $this->assertTrue(!empty($output)); - $this->assertTrue(strpos($output, 'container-class') !== false); + + self::assertTrue(is_string($output)); + self::assertTrue(!empty($output)); + self::assertTrue(strpos($output, 'container-class') !== false); } public function testInputBasics() { $f = new Form\Element\Text(); + $f->setValue('input-value'); $f->setRequired(true); $f->setValidator(function ($value) { return ($value == 'input-value'); }); - $this->assertTrue($f->getValue() == 'input-value'); - $this->assertTrue($f->getRequired() == true); - $this->assertTrue(is_callable($f->getValidator())); + self::assertTrue($f->getValue() == 'input-value'); + self::assertTrue($f->getRequired() == true); + self::assertTrue(is_callable($f->getValidator())); } public function testInputValidation() { $f = new Form\Element\Text(); $f->setRequired(true); - $this->assertFalse($f->validate()); + + self::assertFalse($f->validate()); $f->setRequired(false); $f->setPattern('input\-value'); - $this->assertFalse($f->validate()); + + self::assertFalse($f->validate()); $f->setValue('input-value'); - $this->assertTrue($f->validate()); + + self::assertTrue($f->validate()); $f->setValidator(function ($item) { if ($item != 'input-value') { @@ -82,11 +90,12 @@ class FormTest extends \PHPUnit\Framework\TestCase } }); - $this->assertTrue($f->validate()); + self::assertTrue($f->validate()); $f->setValue('fail'); $f->setPattern(null); - $this->assertFalse($f->validate()); + + self::assertFalse($f->validate()); } public function testFieldSetBasics() @@ -108,76 +117,76 @@ class FormTest extends \PHPUnit\Framework\TestCase $f->addField($f2); $f->addField($f3); - $this->assertFalse($f->validate()); + self::assertFalse($f->validate()); $f->setValues(['group' => ['one' => 'ONE', 'two' => 'TWO'], 'three' => 'THREE']); $values = $f->getValues(); - $this->assertTrue(is_array($values)); - $this->assertTrue(array_key_exists('group', $values)); - $this->assertTrue(array_key_exists('one', $values['group'])); - $this->assertTrue(array_key_exists('three', $values)); - $this->assertTrue($values['group']['one'] == 'ONE'); - $this->assertTrue($values['group']['two'] == 'TWO'); - $this->assertTrue($values['three'] == 'THREE'); - $this->assertTrue($f->validate()); + self::assertTrue(is_array($values)); + self::assertTrue(array_key_exists('group', $values)); + self::assertTrue(array_key_exists('one', $values['group'])); + self::assertTrue(array_key_exists('three', $values)); + self::assertTrue($values['group']['one'] == 'ONE'); + self::assertTrue($values['group']['two'] == 'TWO'); + self::assertTrue($values['three'] == 'THREE'); + self::assertTrue($f->validate()); $html = $f->render(); - $this->assertTrue(strpos($html, 'one') !== false); - $this->assertTrue(strpos($html, 'two') !== false); + self::assertTrue(strpos($html, 'one') !== false); + self::assertTrue(strpos($html, 'two') !== false); } public function testElements() { $e = new Form\Element\Button(); - $this->assertTrue($e->validate()); - $this->assertTrue(strpos($e->render(), 'button') !== false); + self::assertTrue($e->validate()); + self::assertTrue(strpos($e->render(), 'button') !== false); $e = new Form\Element\Checkbox(); $e->setCheckedValue('ten'); - $this->assertTrue($e->getCheckedValue() == 'ten'); - $this->assertTrue(strpos($e->render(), 'checkbox') !== false); - $this->assertTrue(strpos($e->render(), 'checked') === false); + self::assertTrue($e->getCheckedValue() == 'ten'); + self::assertTrue(strpos($e->render(), 'checkbox') !== false); + self::assertTrue(strpos($e->render(), 'checked') === false); $e->setValue(true); - $this->assertTrue(strpos($e->render(), 'checked') !== false); + self::assertTrue(strpos($e->render(), 'checked') !== false); $e->setValue('ten'); - $this->assertTrue(strpos($e->render(), 'checked') !== false); + self::assertTrue(strpos($e->render(), 'checked') !== false); $e->setValue('fail'); - $this->assertTrue(strpos($e->render(), 'checked') === false); + self::assertTrue(strpos($e->render(), 'checked') === false); $e = new Form\Element\CheckboxGroup(); - $this->assertTrue(strpos($e->render(), 'group') !== false); + self::assertTrue(strpos($e->render(), 'group') !== false); $e = new Form\ControlGroup(); - $this->assertTrue(strpos($e->render(), 'group') !== false); + self::assertTrue(strpos($e->render(), 'group') !== false); $e = new Form\Element\Email(); - $this->assertTrue(strpos($e->render(), 'email') !== false); + self::assertTrue(strpos($e->render(), 'email') !== false); $e = new Form\Element\Select(); $e->setOptions(['key' => 'Val']); $html = $e->render(); - $this->assertTrue(strpos($html, 'select') !== false); - $this->assertTrue(strpos($html, 'option') !== false); - $this->assertTrue(strpos($html, 'key') !== false); - $this->assertTrue(strpos($html, 'Val') !== false); + self::assertTrue(strpos($html, 'select') !== false); + self::assertTrue(strpos($html, 'option') !== false); + self::assertTrue(strpos($html, 'key') !== false); + self::assertTrue(strpos($html, 'Val') !== false); $e = new Form\Element\Submit(); - $this->assertTrue($e->validate()); - $this->assertTrue(strpos($e->render(), 'submit') !== false); + self::assertTrue($e->validate()); + self::assertTrue(strpos($e->render(), 'submit') !== false); $e = new Form\Element\Text(); $e->setValue('test'); - $this->assertTrue(strpos($e->render(), 'test') !== false); + self::assertTrue(strpos($e->render(), 'test') !== false); $e = new Form\Element\TextArea(); $e->setRows(10); - $this->assertTrue(strpos($e->render(), '10') !== false); + self::assertTrue(strpos($e->render(), '10') !== false); $e = new Form\Element\Url(); - $this->assertTrue(strpos($e->render(), 'url') !== false); + self::assertTrue(strpos($e->render(), 'url') !== false); } -} \ No newline at end of file +} diff --git a/tests/B8Framework/HttpExceptionTest.php b/tests/B8Framework/HttpExceptionTest.php index de63ee16..98fd2319 100755 --- a/tests/B8Framework/HttpExceptionTest.php +++ b/tests/B8Framework/HttpExceptionTest.php @@ -9,7 +9,7 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase public function testHttpExceptionIsException() { $ex = new HttpException(); - $this->assertTrue($ex instanceof \Exception); + self::assertTrue($ex instanceof \Exception); } public function testHttpException() @@ -17,10 +17,10 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getMessage() == 'Test'); - $this->assertTrue($ex->getErrorCode() == 500); - $this->assertTrue($ex->getStatusMessage() == 'Internal Server Error'); - $this->assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error'); + self::assertTrue($ex->getMessage() == 'Test'); + self::assertTrue($ex->getErrorCode() == 500); + self::assertTrue($ex->getStatusMessage() == 'Internal Server Error'); + self::assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error'); } } @@ -29,8 +29,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\BadRequestException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 400); - $this->assertTrue($ex->getStatusMessage() == 'Bad Request'); + self::assertTrue($ex->getErrorCode() == 400); + self::assertTrue($ex->getStatusMessage() == 'Bad Request'); } } @@ -39,8 +39,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\ForbiddenException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 403); - $this->assertTrue($ex->getStatusMessage() == 'Forbidden'); + self::assertTrue($ex->getErrorCode() == 403); + self::assertTrue($ex->getStatusMessage() == 'Forbidden'); } } @@ -49,8 +49,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\NotAuthorizedException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 401); - $this->assertTrue($ex->getStatusMessage() == 'Not Authorized'); + self::assertTrue($ex->getErrorCode() == 401); + self::assertTrue($ex->getStatusMessage() == 'Not Authorized'); } } @@ -59,8 +59,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\NotFoundException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 404); - $this->assertTrue($ex->getStatusMessage() == 'Not Found'); + self::assertTrue($ex->getErrorCode() == 404); + self::assertTrue($ex->getStatusMessage() == 'Not Found'); } } @@ -69,8 +69,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\ServerErrorException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 500); - $this->assertTrue($ex->getStatusMessage() == 'Internal Server Error'); + self::assertTrue($ex->getErrorCode() == 500); + self::assertTrue($ex->getStatusMessage() == 'Internal Server Error'); } } @@ -79,8 +79,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase try { throw new HttpException\ValidationException('Test'); } catch (HttpException $ex) { - $this->assertTrue($ex->getErrorCode() == 400); - $this->assertTrue($ex->getStatusMessage() == 'Bad Request'); + self::assertTrue($ex->getErrorCode() == 400); + self::assertTrue($ex->getStatusMessage() == 'Bad Request'); } } -} \ No newline at end of file +} diff --git a/tests/B8Framework/ViewTest.php b/tests/B8Framework/ViewTest.php index 8f35524d..e59acaeb 100755 --- a/tests/B8Framework/ViewTest.php +++ b/tests/B8Framework/ViewTest.php @@ -10,7 +10,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase public function testSimpleView() { $view = new View('simple', __DIR__ . '/data/view/'); - $this->assertTrue($view->render() == 'Hello'); + self::assertTrue($view->render() == 'Hello'); } /** @@ -26,9 +26,9 @@ class ViewTest extends \PHPUnit\Framework\TestCase $view = new View('vars', __DIR__ . '/data/view/'); $view->who = 'World'; - $this->assertTrue(isset($view->who)); - $this->assertFalse(isset($view->what)); - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue(isset($view->who)); + self::assertFalse(isset($view->what)); + self::assertTrue($view->render() == 'Hello World'); } /** @@ -43,78 +43,78 @@ class ViewTest extends \PHPUnit\Framework\TestCase public function testSimpleUserView() { $view = new Template('Hello'); - $this->assertTrue($view->render() == 'Hello'); + self::assertTrue($view->render() == 'Hello'); } public function testUserViewYear() { $view = new Template('{@year}'); - $this->assertTrue($view->render() == date('Y')); + self::assertTrue($view->render() == date('Y')); } public function testUserViewVars() { $view = new Template('Hello {@who}'); $view->who = 'World'; - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue($view->render() == 'Hello World'); $view = new Template('Hello {@who}'); - $this->assertTrue($view->render() == 'Hello '); + self::assertTrue($view->render() == 'Hello '); $view = new Template('Hello {@who.name}'); $view->who = ['name' => 'Dan']; - $this->assertTrue($view->render() == 'Hello Dan'); + self::assertTrue($view->render() == 'Hello Dan'); $tmp = new Template('Hello'); $tmp->who = 'World'; $view = new Template('Hello {@tmp.who}'); $view->tmp = $tmp; - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue($view->render() == 'Hello World'); try { $tmp = new Template('Hello'); $view = new Template('Hello {@tmp.who}'); $view->tmp = $tmp; - $this->assertTrue($view->render() == 'Hello '); + self::assertTrue($view->render() == 'Hello '); } catch (\Exception $e) { self::assertInstanceOf('\PHPUnit_Framework_Error_Notice', $e); } $view = new Template('Hello {@who.toUpperCase}'); $view->who = 'World'; - $this->assertTrue($view->render() == 'Hello WORLD'); + self::assertTrue($view->render() == 'Hello WORLD'); $view = new Template('Hello {@who.toLowerCase}'); $view->who = 'World'; - $this->assertTrue($view->render() == 'Hello world'); + self::assertTrue($view->render() == 'Hello world'); } public function testUserViewIf() { $view = new Template('Hello{if who} World{/if}'); $view->who = true; - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue($view->render() == 'Hello World'); $view = new Template('Hello{if who} World{/if}'); $view->who = false; - $this->assertTrue($view->render() == 'Hello'); + self::assertTrue($view->render() == 'Hello'); $view = new Template('Hello{ifnot who} World{/ifnot}'); $view->who = true; - $this->assertTrue($view->render() == 'Hello'); + self::assertTrue($view->render() == 'Hello'); } public function testUserViewLoop() { $view = new Template('Hello {loop who}{@item}{/loop}'); $view->who = ['W', 'o', 'r', 'l', 'd']; - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue($view->render() == 'Hello World'); $view = new Template('Hello {loop who}{@item}{/loop}'); - $this->assertTrue($view->render() == 'Hello '); + self::assertTrue($view->render() == 'Hello '); $view = new Template('Hello {loop who}{@item}{/loop}'); $view->who = 'World'; - $this->assertTrue($view->render() == 'Hello World'); + self::assertTrue($view->render() == 'Hello World'); } -} \ No newline at end of file +} diff --git a/tests/PHPCensor/Command/CreateAdminCommandTest.php b/tests/PHPCensor/Command/CreateAdminCommandTest.php index 087682be..a4be00ec 100644 --- a/tests/PHPCensor/Command/CreateAdminCommandTest.php +++ b/tests/PHPCensor/Command/CreateAdminCommandTest.php @@ -28,7 +28,7 @@ class CreateAdminCommandTest extends \PHPUnit\Framework\TestCase parent::setUp(); $userStoreMock = $this->getMockBuilder('PHPCensor\\Store\\UserStore')->getMock(); - + $this->command = new CreateAdminCommand($userStoreMock); $this->helper = $this @@ -60,6 +60,6 @@ class CreateAdminCommandTest extends \PHPUnit\Framework\TestCase $commandTester = $this->getCommandTester(); $commandTester->execute([]); - $this->assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay()); + self::assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay()); } } diff --git a/tests/PHPCensor/Command/InstallCommandTest.php b/tests/PHPCensor/Command/InstallCommandTest.php index 2372566b..271703c7 100644 --- a/tests/PHPCensor/Command/InstallCommandTest.php +++ b/tests/PHPCensor/Command/InstallCommandTest.php @@ -140,7 +140,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-type', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->config['b8']['database']['type']); + self::assertEquals('testedvalue', $this->config['b8']['database']['type']); } public function testDatabaseHostConfig() @@ -153,8 +153,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-host', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->config['b8']['database']['servers']['read'][0]['host']); - $this->assertEquals('testedvalue', $this->config['b8']['database']['servers']['write'][0]['host']); + self::assertEquals('testedvalue', $this->config['b8']['database']['servers']['read'][0]['host']); + self::assertEquals('testedvalue', $this->config['b8']['database']['servers']['write'][0]['host']); } public function testDatabaseStringPortConfig() @@ -167,8 +167,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-port', $dialog); // Check that specified arguments are correctly loaded. - $this->assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['read'][0]); - $this->assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['write'][0]); + self::assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['read'][0]); + self::assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['write'][0]); } public function testDatabasePortConfig() @@ -181,8 +181,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-port', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals(333, $this->config['b8']['database']['servers']['read'][0]['port']); - $this->assertEquals(333, $this->config['b8']['database']['servers']['write'][0]['port']); + self::assertEquals(333, $this->config['b8']['database']['servers']['read'][0]['port']); + self::assertEquals(333, $this->config['b8']['database']['servers']['write'][0]['port']); } public function testDatabaseNameConfig() @@ -195,7 +195,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-name', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->config['b8']['database']['name']); + self::assertEquals('testedvalue', $this->config['b8']['database']['name']); } public function testDatabaseUserConfig() @@ -208,19 +208,19 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--db-user', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->config['b8']['database']['username']); + self::assertEquals('testedvalue', $this->config['b8']['database']['username']); } public function testDatabasePasswordConfig() { $dialog = $this->getHelperMock(); - + $dialog->expects($this->once())->method('ask')->willReturn('testedvalue'); $this->executeWithoutParam('--db-password', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->config['b8']['database']['password']); + self::assertEquals('testedvalue', $this->config['b8']['database']['password']); } public function testUrlConfig() @@ -233,7 +233,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--url', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('http://testedvalue.com', $this->config['php-censor']['url']); + self::assertEquals('http://testedvalue.com', $this->config['php-censor']['url']); } public function testAdminEmailConfig() @@ -246,7 +246,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--admin-email', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('admin@php-censor.local', $this->admin['email']); + self::assertEquals('admin@php-censor.local', $this->admin['email']); } public function testAdminNameConfig() @@ -259,7 +259,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--admin-name', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->admin['name']); + self::assertEquals('testedvalue', $this->admin['name']); } public function testAdminPasswordConfig() @@ -272,6 +272,6 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase $this->executeWithoutParam('--admin-password', $dialog); // Check that specified arguments are correctly loaded. - $this->assertEquals('testedvalue', $this->admin['password']); + self::assertEquals('testedvalue', $this->admin['password']); } } diff --git a/tests/PHPCensor/Controller/WebhookControllerTest.php b/tests/PHPCensor/Controller/WebhookControllerTest.php index 0279fa4e..43e81f60 100644 --- a/tests/PHPCensor/Controller/WebhookControllerTest.php +++ b/tests/PHPCensor/Controller/WebhookControllerTest.php @@ -16,17 +16,17 @@ class WebhookControllerTest extends \PHPUnit\Framework\TestCase $error = $webController->handleAction('test', []); - $this->assertInstanceOf('b8\Http\Response\JsonResponse', $error); + self::assertInstanceOf('b8\Http\Response\JsonResponse', $error); $responseData = $error->getData(); - $this->assertEquals(500, $responseData['code']); + self::assertEquals(500, $responseData['code']); - $this->assertEquals('failed', $responseData['body']['status']); + self::assertEquals('failed', $responseData['body']['status']); - $this->assertEquals('application/json', $responseData['headers']['Content-Type']); + self::assertEquals('application/json', $responseData['headers']['Content-Type']); // @todo: we can't text the result is JSON file with - // $this->assertJson((string) $error); + // self::assertJson((string) $error); // since the flush method automatically add the header and break the // testing framework. } diff --git a/tests/PHPCensor/Helper/AnsiConverterTest.php b/tests/PHPCensor/Helper/AnsiConverterTest.php index 2d978fa1..a839f780 100644 --- a/tests/PHPCensor/Helper/AnsiConverterTest.php +++ b/tests/PHPCensor/Helper/AnsiConverterTest.php @@ -13,6 +13,6 @@ class AnsiConverterTest extends TestCase $expectedOutput = 'This is red !'; $actualOutput = AnsiConverter::convert($input); - $this->assertEquals($expectedOutput, $actualOutput); + self::assertEquals($expectedOutput, $actualOutput); } } diff --git a/tests/PHPCensor/Helper/BuildInterpolatorTest.php b/tests/PHPCensor/Helper/BuildInterpolatorTest.php index d55caad2..9f25dba2 100644 --- a/tests/PHPCensor/Helper/BuildInterpolatorTest.php +++ b/tests/PHPCensor/Helper/BuildInterpolatorTest.php @@ -24,7 +24,7 @@ class BuildInterpolatorTest extends \PHPUnit\Framework\TestCase $actualOutput = $this->testedInterpolator->interpolate($string); - $this->assertEquals($expectedOutput, $actualOutput); + self::assertEquals($expectedOutput, $actualOutput); } public function testInterpolate_LeavesStringsUnchangedWhenBuildIsSet() @@ -42,7 +42,7 @@ class BuildInterpolatorTest extends \PHPUnit\Framework\TestCase $actualOutput = $this->testedInterpolator->interpolate($string); - $this->assertEquals($expectedOutput, $actualOutput); + self::assertEquals($expectedOutput, $actualOutput); } } diff --git a/tests/PHPCensor/Helper/CommandExecutorTest.php b/tests/PHPCensor/Helper/CommandExecutorTest.php index e5dea453..3a1a6371 100644 --- a/tests/PHPCensor/Helper/CommandExecutorTest.php +++ b/tests/PHPCensor/Helper/CommandExecutorTest.php @@ -25,7 +25,7 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase { $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); $output = $this->testedExecutor->getLastOutput(); - $this->assertEquals("Hello World", $output); + self::assertEquals("Hello World", $output); } public function testGetLastOutput_ForgetsPreviousCommandOutput() @@ -33,19 +33,19 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); $this->testedExecutor->executeCommand(['echo "%s"', 'Hello Tester']); $output = $this->testedExecutor->getLastOutput(); - $this->assertEquals("Hello Tester", $output); + self::assertEquals("Hello Tester", $output); } public function testExecuteCommand_ReturnsTrueForValidCommands() { $returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']); - $this->assertTrue($returnValue); + self::assertTrue($returnValue); } public function testExecuteCommand_ReturnsFalseForInvalidCommands() { $returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']); - $this->assertFalse($returnValue); + self::assertFalse($returnValue); } /** @@ -62,9 +62,9 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase EOD; $data = str_repeat("-", $length); $returnValue = $this->testedExecutor->executeCommand([$script]); - $this->assertTrue($returnValue); - $this->assertEquals($data, trim($this->testedExecutor->getLastOutput())); - $this->assertEquals($data, trim($this->testedExecutor->getLastError())); + self::assertTrue($returnValue); + self::assertEquals($data, trim($this->testedExecutor->getLastOutput())); + self::assertEquals($data, trim($this->testedExecutor->getLastError())); } /** @@ -80,26 +80,26 @@ EOD; public function testFindBinary_ReturnsNullWihQuietArgument() { $thisFileName = "WorldWidePeace"; - $this->assertFalse($this->testedExecutor->findBinary($thisFileName, true)); + self::assertFalse($this->testedExecutor->findBinary($thisFileName, true)); } public function testReplaceIllegalCharacters() { - $this->assertEquals( + self::assertEquals( "start � end", $this->testedExecutor->replaceIllegalCharacters( "start \xf0\x9c\x83\x96 end" ) ); - $this->assertEquals( + self::assertEquals( "start � end", $this->testedExecutor->replaceIllegalCharacters( "start \xF0\x9C\x83\x96 end" ) ); - $this->assertEquals( + self::assertEquals( "start 123_X08�_X00�_Xa4�_5432 end", $this->testedExecutor->replaceIllegalCharacters( "start 123_X08\x08_X00\x00_Xa4\xa4_5432 end" diff --git a/tests/PHPCensor/Helper/LangTest.php b/tests/PHPCensor/Helper/LangTest.php index 9a1c9ad7..a73687c1 100644 --- a/tests/PHPCensor/Helper/LangTest.php +++ b/tests/PHPCensor/Helper/LangTest.php @@ -8,9 +8,9 @@ class LangTest extends LocalizationTestCase { public function testSuccess() { - $this->assertTrue(true); + self::assertTrue(true); } - + /** * @return array */ @@ -37,7 +37,7 @@ class LangTest extends LocalizationTestCase $en = include($directory . 'lang.en.php'); foreach ($en as $enIndex => $enString) { - $this->assertArrayHasKey($enIndex, $strings); + self::assertArrayHasKey($enIndex, $strings); } }*/ } diff --git a/tests/PHPCensor/Helper/MailerFactoryTest.php b/tests/PHPCensor/Helper/MailerFactoryTest.php index 026fd358..1665d908 100644 --- a/tests/PHPCensor/Helper/MailerFactoryTest.php +++ b/tests/PHPCensor/Helper/MailerFactoryTest.php @@ -27,12 +27,12 @@ class MailerFactoryTest extends \PHPUnit\Framework\TestCase $factory = new MailerFactory(['email_settings' => $config]); - $this->assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address')); - $this->assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port')); - $this->assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption')); - $this->assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username')); - $this->assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password')); - $this->assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address')); + self::assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address')); + self::assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port')); + self::assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption')); + self::assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username')); + self::assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password')); + self::assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address')); } public function testExecute_TestMailer() @@ -49,10 +49,10 @@ class MailerFactoryTest extends \PHPUnit\Framework\TestCase $factory = new MailerFactory(['email_settings' => $config]); $mailer = $factory->getSwiftMailerFromConfig(); - $this->assertEquals($config['smtp_address'], $mailer->getTransport()->getHost()); - $this->assertEquals($config['smtp_port'], $mailer->getTransport()->getPort()); - $this->assertEquals('tls', $mailer->getTransport()->getEncryption()); - $this->assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername()); - $this->assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword()); + self::assertEquals($config['smtp_address'], $mailer->getTransport()->getHost()); + self::assertEquals($config['smtp_port'], $mailer->getTransport()->getPort()); + self::assertEquals('tls', $mailer->getTransport()->getEncryption()); + self::assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername()); + self::assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword()); } } diff --git a/tests/PHPCensor/Model/BuildTest.php b/tests/PHPCensor/Model/BuildTest.php index a9712969..5f486af5 100644 --- a/tests/PHPCensor/Model/BuildTest.php +++ b/tests/PHPCensor/Model/BuildTest.php @@ -7,7 +7,7 @@ use PHPCensor\Model; /** * Unit tests for the Build model class. - * + * * @author Dan Cryer */ class BuildTest extends \PHPUnit\Framework\TestCase @@ -19,32 +19,32 @@ class BuildTest extends \PHPUnit\Framework\TestCase public function testExecute_TestIsAValidModel() { $build = new Build(); - $this->assertTrue($build instanceof \b8\Model); - $this->assertTrue($build instanceof Model); + self::assertTrue($build instanceof \b8\Model); + self::assertTrue($build instanceof Model); } public function testExecute_TestBaseBuildDefaults() { $build = new Build(); - $this->assertEquals('#', $build->getCommitLink()); - $this->assertEquals('#', $build->getBranchLink()); - $this->assertEquals(null, $build->getFileLinkTemplate()); + self::assertEquals('#', $build->getCommitLink()); + self::assertEquals('#', $build->getBranchLink()); + self::assertEquals(null, $build->getFileLinkTemplate()); } public function testExecute_TestIsSuccessful() { $build = new Build(); $build->setStatus(Build::STATUS_PENDING); - $this->assertFalse($build->isSuccessful()); + self::assertFalse($build->isSuccessful()); $build->setStatus(Build::STATUS_RUNNING); - $this->assertFalse($build->isSuccessful()); + self::assertFalse($build->isSuccessful()); $build->setStatus(Build::STATUS_FAILED); - $this->assertFalse($build->isSuccessful()); + self::assertFalse($build->isSuccessful()); $build->setStatus(Build::STATUS_SUCCESS); - $this->assertTrue($build->isSuccessful()); + self::assertTrue($build->isSuccessful()); } public function testExecute_TestBuildExtra() @@ -57,26 +57,26 @@ class BuildTest extends \PHPUnit\Framework\TestCase $build = new Build(); $build->setExtra(json_encode($info)); - $this->assertEquals('Item One', $build->getExtra('item1')); - $this->assertEquals(2, $build->getExtra('item2')); - $this->assertNull($build->getExtra('item3')); - $this->assertEquals($info, $build->getExtra()); - + self::assertEquals('Item One', $build->getExtra('item1')); + self::assertEquals(2, $build->getExtra('item2')); + self::assertNull($build->getExtra('item3')); + self::assertEquals($info, $build->getExtra()); + $build->setExtraValue('item3', 'Item Three'); - $this->assertEquals('Item One', $build->getExtra('item1')); - $this->assertEquals('Item Three', $build->getExtra('item3')); + self::assertEquals('Item One', $build->getExtra('item1')); + self::assertEquals('Item Three', $build->getExtra('item3')); $build->setExtraValues([ 'item3' => 'Item Three New', 'item4' => 4, ]); - $this->assertEquals('Item One', $build->getExtra('item1')); - $this->assertEquals('Item Three New', $build->getExtra('item3')); - $this->assertEquals(4, $build->getExtra('item4')); + self::assertEquals('Item One', $build->getExtra('item1')); + self::assertEquals('Item Three New', $build->getExtra('item3')); + self::assertEquals(4, $build->getExtra('item4')); - $this->assertEquals([ + self::assertEquals([ 'item1' => 'Item One', 'item2' => 2, 'item3' => 'Item Three New', diff --git a/tests/PHPCensor/Model/ProjectTest.php b/tests/PHPCensor/Model/ProjectTest.php index 5f266502..a42ef82f 100644 --- a/tests/PHPCensor/Model/ProjectTest.php +++ b/tests/PHPCensor/Model/ProjectTest.php @@ -7,7 +7,7 @@ use PHPCensor\Model; /** * Unit tests for the Project model class. - * + * * @author Dan Cryer */ class ProjectTest extends \PHPUnit\Framework\TestCase @@ -15,8 +15,8 @@ class ProjectTest extends \PHPUnit\Framework\TestCase public function testExecute_TestIsAValidModel() { $project = new Project(); - $this->assertTrue($project instanceof \b8\Model); - $this->assertTrue($project instanceof Model); + self::assertTrue($project instanceof \b8\Model); + self::assertTrue($project instanceof Model); } public function testExecute_TestGitDefaultBranch() @@ -24,7 +24,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setType('git'); - $this->assertEquals('master', $project->getBranch()); + self::assertEquals('master', $project->getBranch()); } public function testExecute_TestGithubDefaultBranch() @@ -32,7 +32,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setType('github'); - $this->assertEquals('master', $project->getBranch()); + self::assertEquals('master', $project->getBranch()); } public function testExecute_TestGitlabDefaultBranch() @@ -40,7 +40,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setType('gitlab'); - $this->assertEquals('master', $project->getBranch()); + self::assertEquals('master', $project->getBranch()); } public function testExecute_TestBitbucketDefaultBranch() @@ -48,7 +48,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setType('bitbucket'); - $this->assertEquals('master', $project->getBranch()); + self::assertEquals('master', $project->getBranch()); } public function testExecute_TestMercurialDefaultBranch() @@ -56,7 +56,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setType('hg'); - $this->assertEquals('default', $project->getBranch()); + self::assertEquals('default', $project->getBranch()); } public function testExecute_TestProjectAccessInformation() @@ -69,9 +69,9 @@ class ProjectTest extends \PHPUnit\Framework\TestCase $project = new Project(); $project->setAccessInformation($info); - $this->assertEquals('Item One', $project->getAccessInformation('item1')); - $this->assertEquals(2, $project->getAccessInformation('item2')); - $this->assertNull($project->getAccessInformation('item3')); - $this->assertEquals($info, $project->getAccessInformation()); + self::assertEquals('Item One', $project->getAccessInformation('item1')); + self::assertEquals(2, $project->getAccessInformation('item2')); + self::assertNull($project->getAccessInformation('item3')); + self::assertEquals($info, $project->getAccessInformation()); } } diff --git a/tests/PHPCensor/Plugin/EmailTest.php b/tests/PHPCensor/Plugin/EmailTest.php index ef3dfc34..c71cf53d 100644 --- a/tests/PHPCensor/Plugin/EmailTest.php +++ b/tests/PHPCensor/Plugin/EmailTest.php @@ -8,7 +8,7 @@ use PHPCensor\Model\Build; /** * Unit test for the PHPUnit plugin. - * + * * @author meadsteve */ class EmailTest extends \PHPUnit\Framework\TestCase @@ -156,7 +156,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase // As no addresses will have been mailed as non are configured. $expectedReturn = false; - $this->assertEquals($expectedReturn, $returnValue); + self::assertEquals($expectedReturn, $returnValue); } public function testBuildsBasicEmails() @@ -165,7 +165,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('test-receiver@example.com', $this->message['to']); + self::assertContains('test-receiver@example.com', $this->message['to']); } public function testBuildsDefaultEmails() @@ -174,7 +174,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('default-mailto-address@example.com', $this->message['to']); + self::assertContains('default-mailto-address@example.com', $this->message['to']); } public function testExecute_UniqueRecipientsFromWithCommitter() @@ -182,12 +182,12 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com', 'test-receiver2@example.com']]); $returnValue = $this->testedEmailPlugin->execute(); - $this->assertTrue($returnValue); + self::assertTrue($returnValue); - $this->assertCount(2, $this->message['to']); + self::assertCount(2, $this->message['to']); - $this->assertContains('test-receiver@example.com', $this->message['to']); - $this->assertContains('test-receiver2@example.com', $this->message['to']); + self::assertContains('test-receiver@example.com', $this->message['to']); + self::assertContains('test-receiver2@example.com', $this->message['to']); } public function testExecute_UniqueRecipientsWithCommitter() @@ -198,10 +198,10 @@ class EmailTest extends \PHPUnit\Framework\TestCase ]); $returnValue = $this->testedEmailPlugin->execute(); - $this->assertTrue($returnValue); + self::assertTrue($returnValue); - $this->assertContains('test-receiver@example.com', $this->message['to']); - $this->assertContains('committer@test.com', $this->message['to']); + self::assertContains('test-receiver@example.com', $this->message['to']); + self::assertContains('committer@test.com', $this->message['to']); } public function testCcDefaultEmails() @@ -220,7 +220,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertEquals( + self::assertEquals( [ 'cc-email-1@example.com', 'cc-email-2@example.com', @@ -241,7 +241,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('committer-email@example.com', $this->message['to']); + self::assertContains('committer-email@example.com', $this->message['to']); } public function testMailSuccessfulBuildHaveProjectName() @@ -255,8 +255,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('Test-Project', $this->message['subject']); - $this->assertContains('Test-Project', $this->message['body']); + self::assertContains('Test-Project', $this->message['subject']); + self::assertContains('Test-Project', $this->message['body']); } public function testMailFailingBuildHaveProjectName() @@ -270,8 +270,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('Test-Project', $this->message['subject']); - $this->assertContains('Test-Project', $this->message['body']); + self::assertContains('Test-Project', $this->message['subject']); + self::assertContains('Test-Project', $this->message['body']); } public function testMailSuccessfulBuildHaveStatus() @@ -285,8 +285,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('Passing', $this->message['subject']); - $this->assertContains('success', $this->message['body']); + self::assertContains('Passing', $this->message['subject']); + self::assertContains('success', $this->message['body']); } public function testMailFailingBuildHaveStatus() @@ -300,8 +300,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->testedEmailPlugin->execute(); - $this->assertContains('Failing', $this->message['subject']); - $this->assertContains('failed', $this->message['body']); + self::assertContains('Failing', $this->message['subject']); + self::assertContains('failed', $this->message['body']); } public function testMailDeliverySuccess() @@ -316,7 +316,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedEmailPlugin->execute(); - $this->assertEquals(true, $returnValue); + self::assertEquals(true, $returnValue); } public function testMailDeliveryFail() @@ -331,6 +331,6 @@ class EmailTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedEmailPlugin->execute(); - $this->assertEquals(false, $returnValue); + self::assertEquals(false, $returnValue); } } diff --git a/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php b/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php index 378cbee2..490ddc15 100644 --- a/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php +++ b/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php @@ -96,7 +96,7 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase public function testCommandArguments($rawOptions, $parsedArguments) { $options = new PhpUnitOptions($rawOptions, '/location'); - $this->assertSame($parsedArguments, $options->getCommandArguments()); + self::assertSame($parsedArguments, $options->getCommandArguments()); } public function testGetters() @@ -109,14 +109,14 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase '/location' ); - $this->assertEquals('/path/to/run/from', $options->getRunFrom()); - $this->assertEquals('subTest', $options->getTestsPath()); - $this->assertNull($options->getOption('random')); - $this->assertEmpty($options->getDirectories()); - $this->assertEmpty($options->getConfigFiles()); + self::assertEquals('/path/to/run/from', $options->getRunFrom()); + self::assertEquals('subTest', $options->getTestsPath()); + self::assertNull($options->getOption('random')); + self::assertEmpty($options->getDirectories()); + self::assertEmpty($options->getConfigFiles()); $files = $options->getConfigFiles(ROOT_DIR); - $this->assertFileExists(ROOT_DIR . $files[0]); + self::assertFileExists(ROOT_DIR . $files[0]); } } diff --git a/tests/PHPCensor/Plugin/PharTest.php b/tests/PHPCensor/Plugin/PharTest.php index e95848d3..4a711ac4 100644 --- a/tests/PHPCensor/Plugin/PharTest.php +++ b/tests/PHPCensor/Plugin/PharTest.php @@ -85,46 +85,46 @@ class PharTest extends \PHPUnit\Framework\TestCase public function testPlugin() { $plugin = $this->getPlugin(); - $this->assertInstanceOf('PHPCensor\Plugin', $plugin); - $this->assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild()); - $this->assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder()); + self::assertInstanceOf('PHPCensor\Plugin', $plugin); + self::assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild()); + self::assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder()); } public function testDirectory() { $plugin = $this->getPlugin(); $plugin->getBuilder()->buildPath = 'foo'; - $this->assertEquals('foo', $plugin->getDirectory()); + self::assertEquals('foo', $plugin->getDirectory()); $plugin = $this->getPlugin(['directory' => 'dirname']); - $this->assertEquals('dirname', $plugin->getDirectory()); + self::assertEquals('dirname', $plugin->getDirectory()); } public function testFilename() { $plugin = $this->getPlugin(); - $this->assertEquals('build.phar', $plugin->getFilename()); + self::assertEquals('build.phar', $plugin->getFilename()); $plugin = $this->getPlugin(['filename' => 'another.phar']); - $this->assertEquals('another.phar', $plugin->getFilename()); + self::assertEquals('another.phar', $plugin->getFilename()); } public function testRegExp() { $plugin = $this->getPlugin(); - $this->assertEquals('/\.php$/', $plugin->getRegExp()); + self::assertEquals('/\.php$/', $plugin->getRegExp()); $plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']); - $this->assertEquals('/\.(php|phtml)$/', $plugin->getRegExp()); + self::assertEquals('/\.(php|phtml)$/', $plugin->getRegExp()); } public function testStub() { $plugin = $this->getPlugin(); - $this->assertNull($plugin->getStub()); + self::assertNull($plugin->getStub()); $plugin = $this->getPlugin(['stub' => 'stub.php']); - $this->assertEquals('stub.php', $plugin->getStub()); + self::assertEquals('stub.php', $plugin->getStub()); } public function testExecute() @@ -135,14 +135,14 @@ class PharTest extends \PHPUnit\Framework\TestCase $path = $this->buildSource(); $plugin->getBuilder()->buildPath = $path; - $this->assertTrue($plugin->execute()); + self::assertTrue($plugin->execute()); - $this->assertFileExists($path . '/build.phar'); + self::assertFileExists($path . '/build.phar'); PHPPhar::loadPhar($path . '/build.phar'); - $this->assertFileEquals($path . '/one.php', 'phar://build.phar/one.php'); - $this->assertFileEquals($path . '/two.php', 'phar://build.phar/two.php'); - $this->assertFileNotExists('phar://build.phar/config/config.ini'); - $this->assertFileNotExists('phar://build.phar/views/index.phtml'); + self::assertFileEquals($path . '/one.php', 'phar://build.phar/one.php'); + self::assertFileEquals($path . '/two.php', 'phar://build.phar/two.php'); + self::assertFileNotExists('phar://build.phar/config/config.ini'); + self::assertFileNotExists('phar://build.phar/views/index.phtml'); } public function testExecuteRegExp() @@ -153,14 +153,14 @@ class PharTest extends \PHPUnit\Framework\TestCase $path = $this->buildSource(); $plugin->getBuilder()->buildPath = $path; - $this->assertTrue($plugin->execute()); + self::assertTrue($plugin->execute()); - $this->assertFileExists($path . '/build.phar'); + self::assertFileExists($path . '/build.phar'); PHPPhar::loadPhar($path . '/build.phar'); - $this->assertFileEquals($path . '/one.php', 'phar://build.phar/one.php'); - $this->assertFileEquals($path . '/two.php', 'phar://build.phar/two.php'); - $this->assertFileNotExists('phar://build.phar/config/config.ini'); - $this->assertFileEquals($path . '/views/index.phtml', 'phar://build.phar/views/index.phtml'); + self::assertFileEquals($path . '/one.php', 'phar://build.phar/one.php'); + self::assertFileEquals($path . '/two.php', 'phar://build.phar/two.php'); + self::assertFileNotExists('phar://build.phar/config/config.ini'); + self::assertFileEquals($path . '/views/index.phtml', 'phar://build.phar/views/index.phtml'); } public function testExecuteStub() @@ -179,11 +179,11 @@ STUB; $plugin = $this->getPlugin(['stub' => 'stub.php']); $plugin->getBuilder()->buildPath = $path; - $this->assertTrue($plugin->execute()); + self::assertTrue($plugin->execute()); - $this->assertFileExists($path . '/build.phar'); + self::assertFileExists($path . '/build.phar'); $phar = new PHPPhar($path . '/build.phar'); - $this->assertEquals($content, trim($phar->getStub())); // + trim because PHP adds newline char + self::assertEquals($content, trim($phar->getStub())); // + trim because PHP adds newline char } public function testExecuteUnknownDirectory() @@ -195,6 +195,6 @@ STUB; $plugin = $this->getPlugin(['directory' => $directory]); $plugin->getBuilder()->buildPath = $this->buildSource(); - $this->assertFalse($plugin->execute()); + self::assertFalse($plugin->execute()); } } diff --git a/tests/PHPCensor/Plugin/Util/ExecutorTest.php b/tests/PHPCensor/Plugin/Util/ExecutorTest.php index 9f7c6cc2..153daec7 100644 --- a/tests/PHPCensor/Plugin/Util/ExecutorTest.php +++ b/tests/PHPCensor/Plugin/Util/ExecutorTest.php @@ -92,14 +92,14 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedExecutor->executePlugin($pluginName, $options); - $this->assertEquals($expectedReturnValue, $returnValue); + self::assertEquals($expectedReturnValue, $returnValue); } public function testExecutePlugin_LogsFailureForNonExistentClasses() { $options = []; $pluginName = 'DOESNTEXIST'; - + $this->mockBuildLogger->logFailure(sprintf('Plugin does not exist: %s', $pluginName))->shouldBeCalledTimes(1); $this->testedExecutor->executePlugin($pluginName, $options); @@ -162,7 +162,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ] ]; - $this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); $config = [ 'setup' => [ @@ -173,7 +173,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ], ]; - $this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); $config = [ 'setup' => [ @@ -184,7 +184,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ], ]; - $this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); $config = [ 'setup' => [ @@ -197,7 +197,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ], ]; - $this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); $config = [ 'setup' => [ @@ -210,7 +210,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ], ]; - $this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); $config = [ 'setup' => [ @@ -223,7 +223,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase ], ]; - $this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); + self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1')); } } diff --git a/tests/PHPCensor/Plugin/Util/FactoryTest.php b/tests/PHPCensor/Plugin/Util/FactoryTest.php index d284a358..b760b24a 100644 --- a/tests/PHPCensor/Plugin/Util/FactoryTest.php +++ b/tests/PHPCensor/Plugin/Util/FactoryTest.php @@ -48,7 +48,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { { $pluginClass = $this->getFakePluginClassName('ExamplePluginWithSingleOptionalArg'); $plugin = $this->testedFactory->buildPlugin($pluginClass); - $this->assertInstanceOf($pluginClass, $plugin); + self::assertInstanceOf($pluginClass, $plugin); } public function testBuildPluginThrowsExceptionIfMissingResourcesForRequiredArg() @@ -74,7 +74,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { /** @var ExamplePluginWithSingleRequiredArg $plugin */ $plugin = $this->testedFactory->buildPlugin($pluginClass); - $this->assertEquals($this->expectedResource, $plugin->RequiredArgument); + self::assertEquals($this->expectedResource, $plugin->RequiredArgument); } public function testBuildPluginLoadsArgumentsBasedOnType() @@ -90,7 +90,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { /** @var ExamplePluginWithSingleTypedRequiredArg $plugin */ $plugin = $this->testedFactory->buildPlugin($pluginClass); - $this->assertEquals($this->expectedResource, $plugin->RequiredArgument); + self::assertEquals($this->expectedResource, $plugin->RequiredArgument); } public function testBuildPluginLoadsFullExample() @@ -102,7 +102,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { /** @var ExamplePluginFull $plugin */ $plugin = $this->testedFactory->buildPlugin($pluginClass); - $this->assertInstanceOf($pluginClass, $plugin); + self::assertInstanceOf($pluginClass, $plugin); } public function testBuildPluginLoadsFullExampleWithOptions() @@ -121,8 +121,8 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { $expectedArgs ); - $this->assertInternalType('array', $plugin->options); - $this->assertArrayHasKey('thing', $plugin->options); + self::assertInternalType('array', $plugin->options); + self::assertArrayHasKey('thing', $plugin->options); } /** diff --git a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php index f7beba3b..58d119b8 100644 --- a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php +++ b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php @@ -30,31 +30,31 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase $output = $parser->parse()->getResults(); $errors = $parser->getErrors(); - $this->assertEquals(7, $parser->getFailures()); - $this->assertInternalType('array', $output); - $this->assertInternalType('array', $errors); - $this->assertNotEmpty($output); - $this->assertNotEmpty($errors); + self::assertEquals(7, $parser->getFailures()); + self::assertInternalType('array', $output); + self::assertInternalType('array', $errors); + self::assertNotEmpty($output); + self::assertNotEmpty($errors); // The trace elements should not include the build path - $this->assertStringStartsNotWith($buildPath, $output[3]['trace'][0]); - $this->assertStringStartsNotWith($buildPath, $output[3]['trace'][1]); + self::assertStringStartsNotWith($buildPath, $output[3]['trace'][0]); + self::assertStringStartsNotWith($buildPath, $output[3]['trace'][1]); - $this->assertEquals("some output\nfrom f4", $output[7]['output']); - $this->assertEquals("has output\non lines", $output[15]['output']); + self::assertEquals("some output\nfrom f4", $output[7]['output']); + self::assertEquals("has output\non lines", $output[15]['output']); - $this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']); + self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']); try { - $this->assertContains('Incomplete Test:', $output[5]['message']); + self::assertContains('Incomplete Test:', $output[5]['message']); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; } catch (\PHPUnit\Framework\ExpectationFailedException $e) { self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; } - $this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']); + self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']); try { - $this->assertContains('Skipped Test:', $output[11]['message']); + self::assertContains('Skipped Test:', $output[11]['message']); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; } catch (\PHPUnit\Framework\ExpectationFailedException $e) { diff --git a/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php b/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php index ccaf8c8b..2e46e356 100644 --- a/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php +++ b/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php @@ -12,6 +12,6 @@ class PosixProcessControlTest extends UnixProcessControlTest public function testIsAvailable() { - $this->assertEquals(function_exists('posix_kill'), PosixProcessControl::isAvailable()); + self::assertEquals(function_exists('posix_kill'), PosixProcessControl::isAvailable()); } } diff --git a/tests/PHPCensor/ProcessControl/ProcessControlTest.php b/tests/PHPCensor/ProcessControl/ProcessControlTest.php index 45439918..0bd03ef7 100644 --- a/tests/PHPCensor/ProcessControl/ProcessControlTest.php +++ b/tests/PHPCensor/ProcessControl/ProcessControlTest.php @@ -33,8 +33,8 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase $this->process = proc_open($this->getTestCommand(), $desc, $this->pipes); sleep(1); - $this->assertTrue(is_resource($this->process)); - $this->assertTrue($this->isRunning()); + self::assertTrue(is_resource($this->process)); + self::assertTrue($this->isRunning()); $status = proc_get_status($this->process); return (integer)$status['pid']; @@ -51,7 +51,7 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase } array_map('fclose', $this->pipes); $exitCode = proc_close($this->process); - $this->assertFalse($this->isRunning()); + self::assertFalse($this->isRunning()); $this->process = null; return $exitCode; } @@ -76,14 +76,14 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase $pid = $this->startProcess(); - $this->assertTrue($this->object->isRunning($pid)); + self::assertTrue($this->object->isRunning($pid)); fwrite($this->pipes[0], PHP_EOL); $exitCode = $this->endProcess(); - $this->assertEquals(0, $exitCode); - $this->assertFalse($this->object->isRunning($pid)); + self::assertEquals(0, $exitCode); + self::assertFalse($this->object->isRunning($pid)); } public function testSoftKill() diff --git a/tests/PHPCensor/ProcessControl/UnixProcessControlTest.php b/tests/PHPCensor/ProcessControl/UnixProcessControlTest.php index 97864a28..82477937 100644 --- a/tests/PHPCensor/ProcessControl/UnixProcessControlTest.php +++ b/tests/PHPCensor/ProcessControl/UnixProcessControlTest.php @@ -17,6 +17,6 @@ class UnixProcessControlTest extends ProcessControlTest public function testIsAvailable() { - $this->assertEquals(DIRECTORY_SEPARATOR === '/', UnixProcessControl::isAvailable()); + self::assertEquals(DIRECTORY_SEPARATOR === '/', UnixProcessControl::isAvailable()); } } diff --git a/tests/PHPCensor/Security/Authentication/ServiceTest.php b/tests/PHPCensor/Security/Authentication/ServiceTest.php index 35488822..20b4697b 100644 --- a/tests/PHPCensor/Security/Authentication/ServiceTest.php +++ b/tests/PHPCensor/Security/Authentication/ServiceTest.php @@ -8,14 +8,14 @@ class ServiceTest extends \PHPUnit\Framework\TestCase { public function testGetInstance() { - $this->assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance()); + self::assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance()); } public function testBuildBuiltinProvider() { $provider = Service::buildProvider('test', ['type' => 'internal']); - $this->assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider); + self::assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider); } public function testBuildAnyProvider() @@ -23,9 +23,9 @@ class ServiceTest extends \PHPUnit\Framework\TestCase $config = ['type' => '\Tests\PHPCensor\Security\Authentication\DummyProvider']; $provider = Service::buildProvider("test", $config); - $this->assertInstanceOf('\Tests\PHPCensor\Security\Authentication\DummyProvider', $provider); - $this->assertEquals('test', $provider->key); - $this->assertEquals($config, $provider->config); + self::assertInstanceOf('\Tests\PHPCensor\Security\Authentication\DummyProvider', $provider); + self::assertEquals('test', $provider->key); + self::assertEquals($config, $provider->config); } public function testGetProviders() @@ -36,7 +36,7 @@ class ServiceTest extends \PHPUnit\Framework\TestCase $service = new Service($providers); - $this->assertEquals($providers, $service->getProviders()); + self::assertEquals($providers, $service->getProviders()); } public function testGetLoginPasswordProviders() @@ -47,7 +47,7 @@ class ServiceTest extends \PHPUnit\Framework\TestCase $service = new Service($providers); - $this->assertEquals(['b' => $b], $service->getLoginPasswordProviders()); + self::assertEquals(['b' => $b], $service->getLoginPasswordProviders()); } } diff --git a/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php b/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php index f162f393..de896ec7 100644 --- a/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php +++ b/tests/PHPCensor/Security/Authentication/UserProvider/InternalTest.php @@ -25,7 +25,7 @@ class InternalTest extends \PHPUnit\Framework\TestCase $password = 'bla'; $user->setHash(password_hash($password, PASSWORD_DEFAULT)); - $this->assertTrue($this->provider->verifyPassword($user, $password)); + self::assertTrue($this->provider->verifyPassword($user, $password)); } public function testVerifyInvaldPassword() @@ -34,7 +34,7 @@ class InternalTest extends \PHPUnit\Framework\TestCase $password = 'foo'; $user->setHash(password_hash($password, PASSWORD_DEFAULT)); - $this->assertFalse($this->provider->verifyPassword($user, 'bar')); + self::assertFalse($this->provider->verifyPassword($user, 'bar')); } public function testCheckRequirements() @@ -44,6 +44,6 @@ class InternalTest extends \PHPUnit\Framework\TestCase public function testProvisionUser() { - $this->assertNull($this->provider->provisionUser('john@doe.com')); + self::assertNull($this->provider->provisionUser('john@doe.com')); } } diff --git a/tests/PHPCensor/Service/BuildServiceTest.php b/tests/PHPCensor/Service/BuildServiceTest.php index 1020982c..ef158480 100644 --- a/tests/PHPCensor/Service/BuildServiceTest.php +++ b/tests/PHPCensor/Service/BuildServiceTest.php @@ -8,7 +8,7 @@ use PHPCensor\Service\BuildService; /** * Unit tests for the ProjectService class. - * + * * @author Dan Cryer */ class BuildServiceTest extends \PHPUnit\Framework\TestCase @@ -60,18 +60,18 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->createBuild($project, null); - $this->assertEquals(101, $returnValue->getProjectId()); - $this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus()); - $this->assertNull($returnValue->getStartDate()); - $this->assertNull($returnValue->getFinishDate()); - $this->assertNull($returnValue->getLog()); - $this->assertEquals(null, $returnValue->getCommitMessage()); - $this->assertNull($returnValue->getCommitterEmail()); - $this->assertEquals(['branches' => []], $returnValue->getExtra()); - $this->assertEquals('master', $returnValue->getBranch()); - $this->assertInstanceOf('DateTime', $returnValue->getCreateDate()); - $this->assertEquals('', $returnValue->getCommitId()); - $this->assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource()); + self::assertEquals(101, $returnValue->getProjectId()); + self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus()); + self::assertNull($returnValue->getStartDate()); + self::assertNull($returnValue->getFinishDate()); + self::assertNull($returnValue->getLog()); + self::assertEquals(null, $returnValue->getCommitMessage()); + self::assertNull($returnValue->getCommitterEmail()); + self::assertEquals(['branches' => []], $returnValue->getExtra()); + self::assertEquals('master', $returnValue->getBranch()); + self::assertInstanceOf('DateTime', $returnValue->getCreateDate()); + self::assertEquals('', $returnValue->getCommitId()); + self::assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource()); } public function testExecute_CreateBuildWithOptions() @@ -98,10 +98,10 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase 'test' ); - $this->assertEquals('testbranch', $returnValue->getBranch()); - $this->assertEquals('123', $returnValue->getCommitId()); - $this->assertEquals('test', $returnValue->getCommitMessage()); - $this->assertEquals('test@example.com', $returnValue->getCommitterEmail()); + self::assertEquals('testbranch', $returnValue->getBranch()); + self::assertEquals('123', $returnValue->getCommitId()); + self::assertEquals('test', $returnValue->getCommitMessage()); + self::assertEquals('test@example.com', $returnValue->getCommitterEmail()); } public function testExecute_CreateBuildWithExtra() @@ -131,7 +131,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase ['item1' => 1001] ); - $this->assertEquals(1001, $returnValue->getExtra('item1')); + self::assertEquals(1001, $returnValue->getExtra('item1')); } public function testExecute_CreateDuplicateBuild() @@ -151,19 +151,19 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->createDuplicateBuild($build); - $this->assertNotEquals($build->getId(), $returnValue->getId()); - $this->assertEquals($build->getProjectId(), $returnValue->getProjectId()); - $this->assertEquals($build->getCommitId(), $returnValue->getCommitId()); - $this->assertNotEquals($build->getStatus(), $returnValue->getStatus()); - $this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus()); - $this->assertNull($returnValue->getLog()); - $this->assertEquals($build->getBranch(), $returnValue->getBranch()); - $this->assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate()); - $this->assertNull($returnValue->getStartDate()); - $this->assertNull($returnValue->getFinishDate()); - $this->assertEquals('test', $returnValue->getCommitMessage()); - $this->assertEquals('test@example.com', $returnValue->getCommitterEmail()); - $this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1')); + self::assertNotEquals($build->getId(), $returnValue->getId()); + self::assertEquals($build->getProjectId(), $returnValue->getProjectId()); + self::assertEquals($build->getCommitId(), $returnValue->getCommitId()); + self::assertNotEquals($build->getStatus(), $returnValue->getStatus()); + self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus()); + self::assertNull($returnValue->getLog()); + self::assertEquals($build->getBranch(), $returnValue->getBranch()); + self::assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate()); + self::assertNull($returnValue->getStartDate()); + self::assertNull($returnValue->getFinishDate()); + self::assertEquals('test', $returnValue->getCommitMessage()); + self::assertEquals('test@example.com', $returnValue->getCommitterEmail()); + self::assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1')); } public function testExecute_DeleteBuild() @@ -176,6 +176,6 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $service = new BuildService($store); $build = new Build(); - $this->assertEquals(true, $service->deleteBuild($build)); + self::assertEquals(true, $service->deleteBuild($build)); } } diff --git a/tests/PHPCensor/Service/BuiltStatusServiceTest.php b/tests/PHPCensor/Service/BuiltStatusServiceTest.php index 5955163b..12ca714b 100644 --- a/tests/PHPCensor/Service/BuiltStatusServiceTest.php +++ b/tests/PHPCensor/Service/BuiltStatusServiceTest.php @@ -8,7 +8,7 @@ use PHPCensor\Service\BuildStatusService; /** * Unit tests for the ProjectService class. - * + * * @author Dan Cryer */ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase @@ -142,7 +142,7 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase $build = $this->getBuild($buildConfigId); $service = new BuildStatusService(self::BRANCH, $this->project, $build); $service->setUrl('http://php-censor.local/'); - $this->assertEquals($expectedResult, $service->toArray()); + self::assertEquals($expectedResult, $service->toArray()); } public function finishedProvider() @@ -205,4 +205,4 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase ], ]; } -} \ No newline at end of file +} diff --git a/tests/PHPCensor/Service/ProjectServiceTest.php b/tests/PHPCensor/Service/ProjectServiceTest.php index a51644d6..d9cd5862 100644 --- a/tests/PHPCensor/Service/ProjectServiceTest.php +++ b/tests/PHPCensor/Service/ProjectServiceTest.php @@ -7,7 +7,7 @@ use PHPCensor\Service\ProjectService; /** * Unit tests for the ProjectService class. - * + * * @author Dan Cryer */ class ProjectServiceTest extends \PHPUnit\Framework\TestCase @@ -37,10 +37,10 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase { $returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0); - $this->assertEquals('Test Project', $returnValue->getTitle()); - $this->assertEquals('github', $returnValue->getType()); - $this->assertEquals('block8/phpci', $returnValue->getReference()); - $this->assertEquals('master', $returnValue->getBranch()); + self::assertEquals('Test Project', $returnValue->getTitle()); + self::assertEquals('github', $returnValue->getType()); + self::assertEquals('block8/phpci', $returnValue->getReference()); + self::assertEquals('master', $returnValue->getBranch()); } public function testExecute_CreateProjectWithOptions() @@ -55,11 +55,11 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0, $options); - $this->assertEquals('private', $returnValue->getSshPrivateKey()); - $this->assertEquals('public', $returnValue->getSshPublicKey()); - $this->assertEquals('config', $returnValue->getBuildConfig()); - $this->assertEquals('testbranch', $returnValue->getBranch()); - $this->assertEquals(1, $returnValue->getAllowPublicStatus()); + self::assertEquals('private', $returnValue->getSshPrivateKey()); + self::assertEquals('public', $returnValue->getSshPublicKey()); + self::assertEquals('config', $returnValue->getBuildConfig()); + self::assertEquals('testbranch', $returnValue->getBranch()); + self::assertEquals(1, $returnValue->getAllowPublicStatus()); } /** @@ -70,9 +70,9 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $reference = 'git@gitlab.block8.net:block8/phpci.git'; $returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference, 0); - $this->assertEquals('git', $returnValue->getAccessInformation('user')); - $this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain')); - $this->assertEquals('block8/phpci', $returnValue->getReference()); + self::assertEquals('git', $returnValue->getAccessInformation('user')); + self::assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain')); + self::assertEquals('block8/phpci', $returnValue->getReference()); } public function testExecute_UpdateExistingProject() @@ -84,9 +84,9 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->updateProject($project, 'After Title', 'bitbucket', 'After Reference'); - $this->assertEquals('After Title', $returnValue->getTitle()); - $this->assertEquals('After Reference', $returnValue->getReference()); - $this->assertEquals('bitbucket', $returnValue->getType()); + self::assertEquals('After Title', $returnValue->getTitle()); + self::assertEquals('After Reference', $returnValue->getReference()); + self::assertEquals('bitbucket', $returnValue->getType()); } public function testExecute_EmptyPublicStatus() @@ -102,7 +102,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options); - $this->assertEquals(0, $returnValue->getAllowPublicStatus()); + self::assertEquals(0, $returnValue->getAllowPublicStatus()); } public function testExecute_DeleteProject() @@ -115,6 +115,6 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $service = new ProjectService($store); $project = new Project(); - $this->assertEquals(true, $service->deleteProject($project)); + self::assertEquals(true, $service->deleteProject($project)); } } diff --git a/tests/PHPCensor/Service/UserServiceTest.php b/tests/PHPCensor/Service/UserServiceTest.php index 9dad0441..cfe9096d 100644 --- a/tests/PHPCensor/Service/UserServiceTest.php +++ b/tests/PHPCensor/Service/UserServiceTest.php @@ -7,7 +7,7 @@ use PHPCensor\Service\UserService; /** * Unit tests for the ProjectService class. - * + * * @author Dan Cryer */ class UserServiceTest extends \PHPUnit\Framework\TestCase @@ -44,10 +44,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase false ); - $this->assertEquals('Test', $user->getName()); - $this->assertEquals('test@example.com', $user->getEmail()); - $this->assertEquals(0, $user->getIsAdmin()); - $this->assertTrue(password_verify('testing', $user->getHash())); + self::assertEquals('Test', $user->getName()); + self::assertEquals('test@example.com', $user->getEmail()); + self::assertEquals(0, $user->getIsAdmin()); + self::assertTrue(password_verify('testing', $user->getHash())); } public function testExecute_CreateAdminUser() @@ -61,7 +61,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase true ); - $this->assertEquals(1, $user->getIsAdmin()); + self::assertEquals(1, $user->getIsAdmin()); } public function testExecute_RevokeAdminStatus() @@ -72,7 +72,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user->setIsAdmin(1); $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 0); - $this->assertEquals(0, $user->getIsAdmin()); + self::assertEquals(0, $user->getIsAdmin()); } public function testExecute_GrantAdminStatus() @@ -83,7 +83,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user->setIsAdmin(0); $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 1); - $this->assertEquals(1, $user->getIsAdmin()); + self::assertEquals(1, $user->getIsAdmin()); } public function testExecute_ChangesPasswordIfNotEmpty() @@ -92,8 +92,8 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user->setHash(password_hash('testing', PASSWORD_DEFAULT)); $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', 0); - $this->assertFalse(password_verify('testing', $user->getHash())); - $this->assertTrue(password_verify('newpassword', $user->getHash())); + self::assertFalse(password_verify('testing', $user->getHash())); + self::assertTrue(password_verify('newpassword', $user->getHash())); } public function testExecute_DoesNotChangePasswordIfEmpty() @@ -102,6 +102,6 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user->setHash(password_hash('testing', PASSWORD_DEFAULT)); $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', 0); - $this->assertTrue(password_verify('testing', $user->getHash())); + self::assertTrue(password_verify('testing', $user->getHash())); } } From 09cee5a5dfa300397e298e12b0bf88d96b98efb2 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 16 Feb 2018 16:59:36 +0700 Subject: [PATCH 3/5] Added more tests for the forms. --- src/B8Framework/Form/Input.php | 40 +++++++++++++++++----------------- tests/B8Framework/FormTest.php | 26 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/B8Framework/Form/Input.php b/src/B8Framework/Form/Input.php index 90e62645..b3763710 100644 --- a/src/B8Framework/Form/Input.php +++ b/src/B8Framework/Form/Input.php @@ -9,17 +9,17 @@ class Input extends Element /** * @var boolean */ - protected $_required = false; + protected $required = false; /** * @var string */ - protected $_pattern; + protected $pattern; /** * @var callable */ - protected $_validator; + protected $validator; /** * @var mixed @@ -29,12 +29,12 @@ class Input extends Element /** * @var string */ - protected $_error; + protected $error; /** * @var boolean */ - protected $_customError = false; + protected $customError = false; /** * @param string $name @@ -78,7 +78,7 @@ class Input extends Element */ public function getRequired() { - return $this->_required; + return $this->required; } /** @@ -88,7 +88,7 @@ class Input extends Element */ public function setRequired($required) { - $this->_required = (bool)$required; + $this->required = (bool)$required; return $this; } @@ -98,7 +98,7 @@ class Input extends Element */ public function getValidator() { - return $this->_validator; + return $this->validator; } /** @@ -109,7 +109,7 @@ class Input extends Element public function setValidator($validator) { if (is_callable($validator) || $validator instanceof \Closure) { - $this->_validator = $validator; + $this->validator = $validator; } return $this; @@ -120,7 +120,7 @@ class Input extends Element */ public function getPattern() { - return $this->_pattern; + return $this->pattern; } /** @@ -130,7 +130,7 @@ class Input extends Element */ public function setPattern($pattern) { - $this->_pattern = $pattern; + $this->pattern = $pattern; return $this; } @@ -141,12 +141,12 @@ class Input extends Element public function validate() { if ($this->getRequired() && empty($this->value)) { - $this->_error = $this->getLabel() . ' is required.'; + $this->error = $this->getLabel() . ' is required.'; return false; } if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->value)) { - $this->_error = 'Invalid value entered.'; + $this->error = 'Invalid value entered.'; return false; } @@ -157,13 +157,13 @@ class Input extends Element try { call_user_func_array($validator, [$this->value]); } catch (\Exception $ex) { - $this->_error = $ex->getMessage(); + $this->error = $ex->getMessage(); return false; } } - if ($this->_customError) { + if ($this->customError) { return false; } @@ -177,8 +177,8 @@ class Input extends Element */ public function setError($message) { - $this->_customError = true; - $this->_error = $message; + $this->customError = true; + $this->error = $message; return $this; } @@ -189,8 +189,8 @@ class Input extends Element protected function onPreRender(View &$view) { $view->value = $this->getValue(); - $view->error = $this->_error; - $view->pattern = $this->_pattern; - $view->required = $this->_required; + $view->error = $this->error; + $view->pattern = $this->pattern; + $view->required = $this->required; } } diff --git a/tests/B8Framework/FormTest.php b/tests/B8Framework/FormTest.php index fbca322b..dcb58e41 100755 --- a/tests/B8Framework/FormTest.php +++ b/tests/B8Framework/FormTest.php @@ -68,6 +68,19 @@ class FormTest extends TestCase self::assertTrue(is_callable($f->getValidator())); } + public function testInputCreate() + { + $text = Form\Element\Text::create( + 'input-name', + 'input-label', + true + ); + + self::assertEquals('input-name', $text->getName()); + self::assertEquals('input-label', $text->getLabel()); + self::assertTrue($text->getRequired()); + } + public function testInputValidation() { $f = new Form\Element\Text(); @@ -98,6 +111,16 @@ class FormTest extends TestCase self::assertFalse($f->validate()); } + public function testInputValidationWithCustomError() + { + $f = new Form\Element\Text(); + $f->setRequired(true); + $f->setValue('input-value'); + $f->setError('Error!'); + + self::assertFalse($f->validate()); + } + public function testFieldSetBasics() { $f = new Form\FieldSet(); @@ -188,5 +211,8 @@ class FormTest extends TestCase $e = new Form\Element\Url(); self::assertTrue(strpos($e->render(), 'url') !== false); + + $e = new Form\Element\Password(); + self::assertTrue(strpos($e->render(), 'password') !== false); } } From 597a20deea8649315bff1bb7451bd1cdce879761 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 16 Feb 2018 20:18:04 +0700 Subject: [PATCH 4/5] Refactored view/template. --- src/B8Framework/Form.php | 1 + src/B8Framework/Form/Element.php | 2 +- src/B8Framework/Form/Element/Button.php | 2 +- src/B8Framework/Form/Element/Checkbox.php | 2 +- src/B8Framework/Form/Element/Csrf.php | 2 +- src/B8Framework/Form/Element/Email.php | 2 +- src/B8Framework/Form/Element/Password.php | 2 +- src/B8Framework/Form/Element/Select.php | 2 +- src/B8Framework/Form/Element/Submit.php | 2 +- src/B8Framework/Form/Element/Text.php | 2 +- src/B8Framework/Form/Element/TextArea.php | 2 +- src/B8Framework/Form/Element/Url.php | 2 +- src/B8Framework/Form/FieldSet.php | 2 +- src/B8Framework/Form/Input.php | 2 +- src/B8Framework/View.php | 82 --- src/B8Framework/View/Template.php | 548 ------------------ src/PHPCensor/Application.php | 1 - src/PHPCensor/Controller.php | 14 +- src/PHPCensor/Controller/BuildController.php | 7 +- .../Controller/ProjectController.php | 11 +- src/PHPCensor/Controller/UserController.php | 9 +- .../WidgetAllProjectsController.php | 4 +- .../WidgetBuildErrorsController.php | 2 +- .../Controller/WidgetLastBuildsController.php | 2 +- src/PHPCensor/Helper/LoginIsDisabled.php | 31 - src/PHPCensor/Plugin/Email.php | 4 +- src/PHPCensor/View.php | 88 +++ src/PHPCensor/View/Group/index.phtml | 12 +- src/PHPCensor/View/Project/ajax-builds.phtml | 4 +- src/PHPCensor/View/Project/view.phtml | 4 +- src/PHPCensor/View/User/index.phtml | 10 +- src/PHPCensor/View/exception.phtml | 4 +- src/PHPCensor/View/layout.phtml | 24 +- tests/B8Framework/ViewTest.php | 92 +-- 34 files changed, 179 insertions(+), 801 deletions(-) delete mode 100644 src/B8Framework/View.php delete mode 100644 src/B8Framework/View/Template.php delete mode 100644 src/PHPCensor/Helper/LoginIsDisabled.php create mode 100644 src/PHPCensor/View.php diff --git a/src/B8Framework/Form.php b/src/B8Framework/Form.php index 39f59568..31ee1563 100644 --- a/src/B8Framework/Form.php +++ b/src/B8Framework/Form.php @@ -3,6 +3,7 @@ namespace b8; use b8\Form\FieldSet; +use PHPCensor\View; class Form extends FieldSet { diff --git a/src/B8Framework/Form/Element.php b/src/B8Framework/Form/Element.php index e485b9a3..2d89f80d 100644 --- a/src/B8Framework/Form/Element.php +++ b/src/B8Framework/Form/Element.php @@ -2,7 +2,7 @@ namespace b8\Form; -use b8\View; +use PHPCensor\View; use b8\Config; abstract class Element diff --git a/src/B8Framework/Form/Element/Button.php b/src/B8Framework/Form/Element/Button.php index 7f6948a4..b3c7774b 100644 --- a/src/B8Framework/Form/Element/Button.php +++ b/src/B8Framework/Form/Element/Button.php @@ -3,7 +3,7 @@ namespace b8\Form\Element; use b8\Form\Input; -use b8\View; +use PHPCensor\View; class Button extends Input { diff --git a/src/B8Framework/Form/Element/Checkbox.php b/src/B8Framework/Form/Element/Checkbox.php index e69349f7..d2352714 100644 --- a/src/B8Framework/Form/Element/Checkbox.php +++ b/src/B8Framework/Form/Element/Checkbox.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; use b8\Form\Input; class Checkbox extends Input diff --git a/src/B8Framework/Form/Element/Csrf.php b/src/B8Framework/Form/Element/Csrf.php index 89b1e924..ee7fb3f5 100644 --- a/src/B8Framework/Form/Element/Csrf.php +++ b/src/B8Framework/Form/Element/Csrf.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class Csrf extends Hidden { diff --git a/src/B8Framework/Form/Element/Email.php b/src/B8Framework/Form/Element/Email.php index ccf10965..b0990eb8 100644 --- a/src/B8Framework/Form/Element/Email.php +++ b/src/B8Framework/Form/Element/Email.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class Email extends Text { diff --git a/src/B8Framework/Form/Element/Password.php b/src/B8Framework/Form/Element/Password.php index 6701a753..b63d3994 100644 --- a/src/B8Framework/Form/Element/Password.php +++ b/src/B8Framework/Form/Element/Password.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class Password extends Text { diff --git a/src/B8Framework/Form/Element/Select.php b/src/B8Framework/Form/Element/Select.php index 900ed742..d7d91853 100644 --- a/src/B8Framework/Form/Element/Select.php +++ b/src/B8Framework/Form/Element/Select.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; use b8\Form\Input; class Select extends Input diff --git a/src/B8Framework/Form/Element/Submit.php b/src/B8Framework/Form/Element/Submit.php index a95bff0f..14e5ea7a 100644 --- a/src/B8Framework/Form/Element/Submit.php +++ b/src/B8Framework/Form/Element/Submit.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class Submit extends Button { diff --git a/src/B8Framework/Form/Element/Text.php b/src/B8Framework/Form/Element/Text.php index 56c88ca7..59f45ffd 100644 --- a/src/B8Framework/Form/Element/Text.php +++ b/src/B8Framework/Form/Element/Text.php @@ -3,7 +3,7 @@ namespace b8\Form\Element; use b8\Form\Input; -use b8\View; +use PHPCensor\View; class Text extends Input { diff --git a/src/B8Framework/Form/Element/TextArea.php b/src/B8Framework/Form/Element/TextArea.php index 6ec8b85a..b39d6466 100644 --- a/src/B8Framework/Form/Element/TextArea.php +++ b/src/B8Framework/Form/Element/TextArea.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class TextArea extends Text { diff --git a/src/B8Framework/Form/Element/Url.php b/src/B8Framework/Form/Element/Url.php index 4627eb79..e89a4578 100644 --- a/src/B8Framework/Form/Element/Url.php +++ b/src/B8Framework/Form/Element/Url.php @@ -2,7 +2,7 @@ namespace b8\Form\Element; -use b8\View; +use PHPCensor\View; class Url extends Text { diff --git a/src/B8Framework/Form/FieldSet.php b/src/B8Framework/Form/FieldSet.php index 49f485a3..fba88738 100644 --- a/src/B8Framework/Form/FieldSet.php +++ b/src/B8Framework/Form/FieldSet.php @@ -2,7 +2,7 @@ namespace b8\Form; -use b8\View; +use PHPCensor\View; class FieldSet extends Element { diff --git a/src/B8Framework/Form/Input.php b/src/B8Framework/Form/Input.php index b3763710..37813a52 100644 --- a/src/B8Framework/Form/Input.php +++ b/src/B8Framework/Form/Input.php @@ -2,7 +2,7 @@ namespace b8\Form; -use b8\View; +use PHPCensor\View; class Input extends Element { diff --git a/src/B8Framework/View.php b/src/B8Framework/View.php deleted file mode 100644 index 6d976265..00000000 --- a/src/B8Framework/View.php +++ /dev/null @@ -1,82 +0,0 @@ -viewFile = self::getViewFile($file, $path); - } - - protected static function getViewFile($file, $path = null) - { - $viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path; - $fullPath = $viewPath . $file . '.' . static::$extension; - - return $fullPath; - } - - public static function exists($file, $path = null) - { - if (!file_exists(self::getViewFile($file, $path))) { - return false; - } - - return true; - } - - public function __isset($var) - { - return isset($this->vars[$var]); - } - - public function __get($var) - { - return $this->vars[$var]; - } - - public function __set($var, $val) - { - $this->vars[$var] = $val; - } - - public function __call($method, $params = []) - { - if (!isset(self::$helpers[$method])) { - $class = '\\' . Config::getInstance()->get('b8.app.namespace') . '\\Helper\\' . $method; - - if (!class_exists($class)) { - $class = '\\b8\\View\\Helper\\' . $method; - } - - if (!class_exists($class)) { - throw new \Exception('Helper class does not exist: ' . $class); - } - - self::$helpers[$method] = new $class(); - } - - return self::$helpers[$method]; - } - - public function render() - { - extract($this->vars); - - ob_start(); - require($this->viewFile); - $html = ob_get_contents(); - ob_end_clean(); - - return $html; - } -} diff --git a/src/B8Framework/View/Template.php b/src/B8Framework/View/Template.php deleted file mode 100644 index 717d020e..00000000 --- a/src/B8Framework/View/Template.php +++ /dev/null @@ -1,548 +0,0 @@ -viewCode = $viewCode; - - if (!count(self::$templateFunctions)) { - self::$templateFunctions = [ - 'include' => [$this, 'includeTemplate'], - 'call' => [$this, 'callHelperFunction'] - ]; - } - } - - public static function createFromFile($file, $path = null) - { - if (!static::exists($file, $path)) { - throw new \Exception('View file does not exist: ' . $file); - } - - $viewFile = static::getViewFile($file, $path); - return new static(file_get_contents($viewFile)); - } - - public static function createFromString($string) - { - return new static($string); - } - - public function addFunction($name, $handler) - { - self::$templateFunctions[$name] = $handler; - } - - public function removeFunction($name) - { - unset(self::$templateFunctions[$name]); - } - - public function render() - { - return $this->parse($this->viewCode); - } - - protected function parse($string) - { - $keywords = ['ifnot', 'if', 'else', 'for', 'loop', '@', '/ifnot', '/if', '/for', '/loop']; - - foreach (self::$templateFunctions as $function => $handler) { - $keywords[] = $function; - } - - $stack = ['children' => [['type' => 'string', 'body' => '']]]; - $stack['children'][0]['parent'] =& $stack; - $current =& $stack['children'][0]; - - while (!empty($string)) { - $current['body'] .= $this->readUntil('{', $string); - - if (!empty($string)) { - $gotKeyword = false; - - foreach ($keywords as $keyword) { - $kwLen = strlen($keyword) + 1; - - if (substr($string, 0, $kwLen) == '{' . $keyword) { - $gotKeyword = true; - $item = ['type' => $keyword, 'cond' => '', 'children' => '']; - $string = substr($string, $kwLen); - - $cond = trim($this->readUntil('}', $string)); - $item['cond'] = $cond; - $string = substr($string, 1); - - if (array_key_exists($keyword, self::$templateFunctions)) { - $item['function_name'] = $keyword; - $item['type'] = 'function'; - } - - $str = ['type' => 'string', 'body' => '']; - $parent =& $current['parent']; - - if (substr($current['body'], (0 - strlen(PHP_EOL))) === PHP_EOL) { - $current['body'] = substr($current['body'], 0, strlen($current['body']) - strlen(PHP_EOL)); - } - - $item['parent'] =& $parent; - - $parent['children'][] = $item; - - if ($keyword == '@' || $item['type'] == 'function') { - // If we're processing a variable, add a string to the parent and move up to that as current. - $parent['children'][] = $str; - $current =& $parent['children'][count($parent['children']) - 1]; - $current['parent'] =& $parent; - } elseif (substr($keyword, 0, 1) == '/') { - // If we're processing the end of a block (if/loop), add a string to the parent's parent and move up to that. - $parent =& $parent['parent']; - $parent['children'][] = $str; - $current =& $parent['children'][count($parent['children']) - 1]; - $current['parent'] =& $parent; - } else { - if (!is_array($parent['children'][count($parent['children']) - 1]['children'])) { - $parent['children'][count($parent['children']) - 1]['children'] = []; - } - $parent['children'][count($parent['children']) - 1]['children'][] = $str; - $current =& $parent['children'][count($parent['children']) - 1]['children'][0]; - $current['parent'] =& $parent['children'][count($parent['children']) - 1]; - } - - break; - } - } - - if (!$gotKeyword) { - $current['body'] .= substr($string, 0, 1); - $string = substr($string, 1); - } - } - } - - return $this->processStack($stack); - } - - protected function processStack($stack) - { - $res = ''; - - while (count($stack['children'])) { - $current = array_shift($stack['children']); - - switch ($current['type']) { - case 'string': - $res .= $current['body']; - break; - - case '@': - $res .= $this->doParseVar($current['cond']); - break; - - case 'if': - $res .= $this->doParseIf($current['cond'], $current); - break; - - case 'ifnot': - $res .= $this->doParseIfNot($current['cond'], $current); - break; - - case 'loop': - $res .= $this->doParseLoop($current['cond'], $current); - break; - - case 'for': - $res .= $this->doParseFor($current['cond'], $current); - break; - - case 'function': - $res .= $this->doParseFunction($current); - break; - } - } - - return $res; - } - - protected function readUntil($until, &$string) - { - $read = ''; - - while (!empty($string)) { - $char = substr($string, 0, 1); - - if ($char == $until) { - break; - } - - $read .= $char; - $string = substr($string, 1); - } - - return $read; - } - - protected function doParseVar($var) - { - if ($var == 'year') { - return date('Y'); - } - - $val = $this->processVariableName($var); - return $val; - } - - protected function doParseIf($condition, $stack) - { - if ($this->ifConditionIsTrue($condition)) { - return $this->processStack($stack); - } else { - return ''; - } - } - - protected function doParseIfNot($condition, $stack) - { - if (!$this->ifConditionIsTrue($condition)) { - return $this->processStack($stack); - } else { - return ''; - } - } - - protected function ifConditionIsTrue($condition) - { - $matches = []; - - if (preg_match( - '/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/', - $condition, - $matches - )) { - $left = is_numeric($matches[1]) - ? intval($matches[1]) - : $this->processVariableName($matches[1]); - - $right = is_numeric($matches[3]) - ? intval($matches[3]) - : $this->processVariableName($matches[3]); - - $operator = $matches[2]; - - switch ($operator) { - case '==': - case '=': - return ($left == $right); - - case '!=': - return ($left != $right); - - case '>=': - return ($left >= $right); - - case '<=': - return ($left <= $right); - - case '>': - return ($left > $right); - - case '<': - return ($left < $right); - } - } elseif (preg_match('/([a-zA-Z0-9_\-\(\):\s.]+)/', $condition, $matches)) { - return $this->processVariableName($condition) ? true : false; - } - } - - protected function doParseLoop($var, $stack) - { - $working = $this->processVariableName($var); - - if (is_null($working)) { - return ''; - } - - if (!is_array($working)) { - $working = [$working]; - } - - $rtn = ''; - foreach ($working as $key => $val) { - // Make sure we support nesting loops: - $keyWas = isset($this->key) ? $this->key : null; - $valWas = isset($this->value) ? $this->value : null; - $itemWas = isset($this->item) ? $this->item : null; - - // Set up the necessary variables within the stack: - $this->parent = $this; - $this->item = $val; - $this->key = $key; - $this->value = $val; - $rtn .= $this->processStack($stack); - - // Restore state for any parent nested loops: - $this->item = $itemWas; - $this->key = $keyWas; - $this->value = $valWas; - } - - return $rtn; - } - - /** - * Processes loops in templates, of the following styles: - * - * - * {for myarray.items} - * {@item.title} - * {/for} - * - * - * Or: - * - * - * {for 0:pages.count; i++} - * {@i} - * {/for} - * - * - * @param $cond string The condition string for the loop, to be parsed (e.g. "myarray.items" or "0:pages.count; i++") - * @param $stack string The child stack for this loop, to be processed for each item. - * @return string - * @throws \Exception - */ - protected function doParseFor($cond, $stack) - { - // If this is a simple foreach loop, jump over to parse loop: - if (strpos($cond, ';') === false) { - return $this->doParseLoop($cond, $stack); - } - - // Otherwise, process as a for loop: - $parts = explode(';', $cond); - $range = explode(':', trim($parts[0])); - - // Process range: - $rangeLeft = $this->getForRangePart($range[0]); - $rangeRight = $this->getForRangePart($range[1]); - - // Process variable & incrementor / decrementor: - $parts[1] = trim($parts[1]); - - $matches = []; - if (preg_match('/([a-zA-Z0-9_]+)(\+\+|\-\-)/', $parts[1], $matches)) { - $varName = $matches[1]; - $direction = $matches[2] == '++' ? 'increment' : 'decrement'; - } else { - throw new \Exception('Syntax error in for loop: ' . $cond); - } - - $rtn = ''; - - if ($direction == 'increment') { - for ($i = $rangeLeft; $i < $rangeRight; $i++) { - $this->parent = $this; - $this->{$varName} = $i; - $rtn .= $this->processStack($stack); - } - } else { - for ($i = $rangeLeft; $i > $rangeRight; $i--) { - $this->parent = $this; - $this->{$varName} = $i; - $rtn .= $this->processStack($stack); - } - } - - return $rtn; - } - - protected function getForRangePart($part) - { - if (is_numeric($part)) { - return intval($part); - } - - $varPart = $this->processVariableName($part); - - if (is_numeric($varPart)) { - return intval($varPart); - } - - throw new \Exception('Invalid range in for loop: ' . $part); - } - - public function processVariableName($varName) - { - // Case one - Test for function calls: - if (substr($varName, 0, 1) == '(' && substr($varName, -1) == ')') { - $functionCall = substr($varName, 1, -1); - $parts = explode(' ', $functionCall, 2); - $functionName = $parts[0]; - $arguments = isset($parts[1]) ? $parts[1] : null; - - return $this->executeTemplateFunction($functionName, $arguments); - } - - // Case two - Test if it is just a string: - if (substr($varName, 0, 1) == '"' && substr($varName, -1) == '"') { - return substr($varName, 1, -1); - } - - // Case three - Test if it is just a number: - if (is_numeric($varName)) { - return $varName; - } - - // Case four - Test for helper calls: - if (strpos($varName, ':') !== false) { - list($helper, $property) = explode(':', $varName); - - $helper = $this->{$helper}(); - - if (property_exists($helper, $property) || method_exists($helper, '__get')) { - return $helper->{$property}; - } - - return null; - } - - // Case five - Process as a variable: - $varPart = explode('.', $varName); - $thisPart = array_shift($varPart); - - - if (!array_key_exists($thisPart, $this->vars)) { - return null; - } - - $working = $this->{$thisPart}; - - while (count($varPart)) { - $thisPart = array_shift($varPart); - - if (is_object($working)) { - // Check if we're working with an actual property: - if (property_exists($working, $thisPart)) { - $working = $working->{$thisPart}; - continue; - } - - // Check if the object has a magic __get method: - if (method_exists($working, '__get')) { - $working = $working->{$thisPart}; - continue; - } - } - - - if (is_array($working) && array_key_exists($thisPart, $working)) { - $working = $working[$thisPart]; - continue; - } - - if ($thisPart == 'toLowerCase') { - $working = strtolower($working); - continue; - } - - if ($thisPart == 'toUpperCase') { - $working = strtoupper($working); - continue; - } - - if ($thisPart == 'isNumeric') { - return is_numeric($working); - } - - return null; - } - - return $working; - } - - protected function doParseFunction($stack) - { - return $this->executeTemplateFunction($stack['function_name'], $stack['cond']); - } - - protected function executeTemplateFunction($function, $args) - { - if (array_key_exists($function, self::$templateFunctions)) { - $handler = self::$templateFunctions[$function]; - $args = $this->processFunctionArguments($args); - - return $handler($args, $this); - } - - return null; - } - - protected function processFunctionArguments($args) - { - $rtn = []; - $args = explode(';', $args); - - foreach ($args as $arg) { - $arg = explode(':', $arg); - - if (count($arg) == 2) { - $key = trim($arg[0]); - $val = trim($arg[1]); - - if (strpos($val, ',') !== false) { - $val = explode(',', $val); - } - - $rtn[$key] = $val; - } - } - - return $rtn; - } - - public function getVariable($variable) - { - return $this->processVariableName($variable); - } - - protected function includeTemplate($args, $view) - { - $template = static::createFromFile($view->getVariable($args['template'])); - - if (isset($args['variables'])) { - if (!is_array($args['variables'])) { - $args['variables'] = [$args['variables']]; - } - - foreach ($args['variables'] as $variable) { - $variable = explode('=>', $variable); - $variable = array_map('trim', $variable); - - if (count($variable) == 1) { - $template->{$variable[0]} = $view->getVariable($variable[0]); - } else { - $template->{$variable[1]} = $view->getVariable($variable[0]); - } - } - } - - return $template->render(); - } - - protected function callHelperFunction($args) - { - $helper = $args['helper']; - $function = $args['method']; - - return $this->{$helper}()->{$function}(); - } -} diff --git a/src/PHPCensor/Application.php b/src/PHPCensor/Application.php index a4c97605..f60fdbe9 100644 --- a/src/PHPCensor/Application.php +++ b/src/PHPCensor/Application.php @@ -6,7 +6,6 @@ use b8; use b8\Exception\HttpException; use b8\Http\Response; use b8\Http\Response\RedirectResponse; -use b8\View; /** * @author Dan Cryer diff --git a/src/PHPCensor/Controller.php b/src/PHPCensor/Controller.php index e25bd0cf..4ba7ea07 100644 --- a/src/PHPCensor/Controller.php +++ b/src/PHPCensor/Controller.php @@ -6,22 +6,26 @@ use b8\Config; use b8\Exception\HttpException\ForbiddenException; use b8\Http\Request; use b8\Http\Response; -use b8\View; class Controller extends \b8\Controller { /** - * @var \b8\View + * @var View */ protected $controllerView; /** - * @var \b8\View + * @var View */ protected $view; /** - * @var \b8\View + * @var string + */ + protected $className; + + /** + * @var View */ public $layout; @@ -55,7 +59,7 @@ class Controller extends \b8\Controller if (View::exists($this->className)) { $this->controllerView = new View($this->className); } else { - $this->controllerView = new View\Template('{@content}'); + $this->controllerView = new View('{@content}'); } } diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index a3652d3b..c3b25a5e 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -14,6 +14,7 @@ use PHPCensor\Model\Project; use PHPCensor\Model\User; use PHPCensor\Service\BuildService; use PHPCensor\Controller; +use PHPCensor\View; /** * Build Controller - Allows users to run and view builds. @@ -189,7 +190,7 @@ class BuildController extends Controller $errorStore = b8\Store\Factory::getStore('BuildError'); $errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity, $isNew); - $errorView = new b8\View('Build/errors'); + $errorView = new View('Build/errors'); $errorView->build = $build; $errorView->errors = $errors['items']; @@ -213,7 +214,7 @@ class BuildController extends Controller */ protected function getPaginatorHtml($buildId, $plugin, $severity, $isNew, $total, $perPage, $page) { - $view = new b8\View('pagination'); + $view = new View('pagination'); $urlPattern = APP_URL . 'build/view/' . $buildId; $params = []; @@ -306,7 +307,7 @@ class BuildController extends Controller foreach ($builds['items'] as $build) { $item = $build->toArray(1); - $header = new b8\View('Build/header-row'); + $header = new View('Build/header-row'); $header->build = $build; $item['header_row'] = $header->render(); diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index c2b0673d..a4f61d94 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -16,6 +16,7 @@ use PHPCensor\Service\BuildService; use PHPCensor\Service\ProjectService; use PHPCensor\Model\Build; use b8\Http\Response\RedirectResponse; +use PHPCensor\View; /** * Project Controller - Allows users to create, edit and view projects. @@ -141,7 +142,7 @@ class ProjectController extends PHPCensor\Controller */ protected function getPaginatorHtml($projectId, $branch, $environment, $total, $perPage, $page) { - $view = new b8\View('pagination'); + $view = new View('pagination'); $urlPattern = APP_URL . 'project/view/' . $projectId; $params = []; @@ -178,7 +179,7 @@ class ProjectController extends PHPCensor\Controller if (empty($project) || $project->getArchived()) { throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } - + $type = $this->getParam('type', 'branch'); $id = $this->getParam('id'); $debug = (boolean)$this->getParam('debug', false); @@ -273,7 +274,7 @@ class ProjectController extends PHPCensor\Controller $order = ['id' => 'DESC']; $builds = $this->buildStore->getWhere($criteria, $perPage, $start, [], $order); - $view = new b8\View('Project/ajax-builds'); + $view = new View('Project/ajax-builds'); foreach ($builds['items'] as &$build) { $build = BuildFactory::getBuild($build); @@ -312,7 +313,7 @@ class ProjectController extends PHPCensor\Controller $form = $this->projectForm($values); if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { - $view = new b8\View('Project/edit'); + $view = new View('Project/edit'); $view->type = 'add'; $view->project = null; $view->form = $form; @@ -381,7 +382,7 @@ class ProjectController extends PHPCensor\Controller $form = $this->projectForm($values, 'edit/' . $projectId); if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { - $view = new b8\View('Project/edit'); + $view = new View('Project/edit'); $view->type = 'edit'; $view->project = $project; $view->form = $form; diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index 551a65d9..f598d130 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -9,10 +9,11 @@ use PHPCensor\Controller; use PHPCensor\Helper\Lang; use PHPCensor\Model\User; use PHPCensor\Service\UserService; +use PHPCensor\View; /** * User Controller - Allows an administrator to view, add, edit and delete users. - * + * * @author Dan Cryer */ class UserController extends Controller @@ -61,7 +62,7 @@ class UserController extends Controller $name = $this->getParam('name', null); $email = $this->getParam('email', null); $password = $this->getParam('password', null); - + $language = $this->getParam('language', null); if (!$language) { $language = null; @@ -166,7 +167,7 @@ class UserController extends Controller $form = $this->userForm($values); if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { - $view = new b8\View('User/edit'); + $view = new View('User/edit'); $view->type = 'add'; $view->user = null; $view->form = $form; @@ -208,7 +209,7 @@ class UserController extends Controller $form = $this->userForm($values, 'edit/' . $userId); if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { - $view = new b8\View('User/edit'); + $view = new View('User/edit'); $view->type = 'edit'; $view->user = $user; $view->form = $form; diff --git a/src/PHPCensor/Controller/WidgetAllProjectsController.php b/src/PHPCensor/Controller/WidgetAllProjectsController.php index f4013a45..8d45a836 100644 --- a/src/PHPCensor/Controller/WidgetAllProjectsController.php +++ b/src/PHPCensor/Controller/WidgetAllProjectsController.php @@ -5,7 +5,7 @@ namespace PHPCensor\Controller; use PHPCensor\Model\Build; use PHPCensor\Controller; use b8\Store\Factory; -use b8\View; +use PHPCensor\View; use PHPCensor\Model\Project; use b8\Http\Response; use PHPCensor\Store\BuildStore; @@ -101,7 +101,7 @@ class WidgetAllProjectsController extends Controller /** * Get a summary of the project groups we have, and what projects they have in them. - * + * * @return array */ protected function getGroupInfo() diff --git a/src/PHPCensor/Controller/WidgetBuildErrorsController.php b/src/PHPCensor/Controller/WidgetBuildErrorsController.php index 7bde6c44..b0e1e73a 100644 --- a/src/PHPCensor/Controller/WidgetBuildErrorsController.php +++ b/src/PHPCensor/Controller/WidgetBuildErrorsController.php @@ -3,7 +3,7 @@ namespace PHPCensor\Controller; use b8\Store\Factory; -use b8\View; +use PHPCensor\View; use b8\Http\Response; use PHPCensor\Controller; use PHPCensor\Store\BuildStore; diff --git a/src/PHPCensor/Controller/WidgetLastBuildsController.php b/src/PHPCensor/Controller/WidgetLastBuildsController.php index 0e0f2ea0..a613a25f 100644 --- a/src/PHPCensor/Controller/WidgetLastBuildsController.php +++ b/src/PHPCensor/Controller/WidgetLastBuildsController.php @@ -3,7 +3,7 @@ namespace PHPCensor\Controller; use b8\Store\Factory; -use b8\View; +use PHPCensor\View; use b8\Http\Response; use PHPCensor\BuildFactory; use PHPCensor\Controller; diff --git a/src/PHPCensor/Helper/LoginIsDisabled.php b/src/PHPCensor/Helper/LoginIsDisabled.php deleted file mode 100644 index 70ed3486..00000000 --- a/src/PHPCensor/Helper/LoginIsDisabled.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -class LoginIsDisabled -{ - /** - * Checks if - * - * @param $method - * @param array $params - * - * @return mixed|null - */ - public function __call($method, $params = []) - { - unset($method, $params); - - $config = Config::getInstance(); - $disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false); - - return $disableAuth; - } -} diff --git a/src/PHPCensor/Plugin/Email.php b/src/PHPCensor/Plugin/Email.php index c460bb45..c5a9c1b5 100644 --- a/src/PHPCensor/Plugin/Email.php +++ b/src/PHPCensor/Plugin/Email.php @@ -2,14 +2,14 @@ namespace PHPCensor\Plugin; -use b8\View; +use PHPCensor\View; use PHPCensor\Helper\Email as EmailHelper; use Psr\Log\LogLevel; use PHPCensor\Plugin; /** * Email Plugin - Provides simple email capability. - * + * * @author Steve Brazier */ class Email extends Plugin diff --git a/src/PHPCensor/View.php b/src/PHPCensor/View.php new file mode 100644 index 00000000..8a648e42 --- /dev/null +++ b/src/PHPCensor/View.php @@ -0,0 +1,88 @@ +isContent = true; + } else { + if (!self::exists($file, $path)) { + throw new \RuntimeException('View file does not exist: ' . $file); + } + + $this->viewFile = self::getViewFile($file, $path); + } + } + + protected static function getViewFile($file, $path = null) + { + $viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path; + $fullPath = $viewPath . $file . '.' . static::$extension; + + return $fullPath; + } + + public static function exists($file, $path = null) + { + if (!file_exists(self::getViewFile($file, $path))) { + return false; + } + + return true; + } + + public function __isset($var) + { + return isset($this->vars[$var]); + } + + public function __get($var) + { + return $this->vars[$var]; + } + + public function __set($var, $val) + { + $this->vars[$var] = $val; + } + + public function render() + { + if ($this->isContent) { + return $this->vars['content']; + } else { + extract($this->vars); + + ob_start(); + + require($this->viewFile); + + $html = ob_get_contents(); + ob_end_clean(); + + return $html; + } + } + + /** + * @return boolean + */ + protected function LoginIsDisabled() + { + $config = Config::getInstance(); + $disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false); + + return $disableAuth; + } +} diff --git a/src/PHPCensor/View/Group/index.phtml b/src/PHPCensor/View/Group/index.phtml index 7bad7e89..182b4251 100644 --- a/src/PHPCensor/View/Group/index.phtml +++ b/src/PHPCensor/View/Group/index.phtml @@ -1,4 +1,10 @@ - +
@@ -22,7 +28,7 @@
- User()->getIsAdmin() && (!count($group['projects']))): ?> + getIsAdmin() && (!count($group['projects']))): ?> @@ -45,4 +51,4 @@ confirmDelete(e.target.href).onCloseConfirmed = function () {window.location = window.location.href}; }); }); - \ No newline at end of file + diff --git a/src/PHPCensor/View/Project/ajax-builds.phtml b/src/PHPCensor/View/Project/ajax-builds.phtml index a04a9787..7b74a738 100644 --- a/src/PHPCensor/View/Project/ajax-builds.phtml +++ b/src/PHPCensor/View/Project/ajax-builds.phtml @@ -6,6 +6,8 @@ use PHPCensor\Helper\Lang; +$user = $_SESSION['php-censor-user']; + ?> @@ -92,7 +94,7 @@ $branches = $build->getExtra('branches');
- User()->getIsAdmin()): ?> + getIsAdmin()): ?> diff --git a/src/PHPCensor/View/Project/view.phtml b/src/PHPCensor/View/Project/view.phtml index 50ed3dce..52ff981d 100644 --- a/src/PHPCensor/View/Project/view.phtml +++ b/src/PHPCensor/View/Project/view.phtml @@ -6,6 +6,8 @@ use PHPCensor\Helper\Lang; +$user = $_SESSION['php-censor-user']; + ?>