diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..7c95e8a --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +coverage_clover: workbench/code_coverage_report/clover/clover.xml +json_path: workbench/code_coverage_report/clover/coveralls.json \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fcb59e2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root=true + +[*] +charset=utf-8 +end_of_line=lf +indent_style=space +indent_size=4 +insert_final_newline=false +trim_trailing_whitespace=false + +[*.php] +insert_final_newline=true +trim_trailing_whitespace=true \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..473da29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# IDE +/.idea/ + +# Composer +/vendor/ +/composer.lock + +# Workbench +/workbench \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..56aeb16 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: php +matrix: + include: + - php: 5.3 + dist: precise +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - 7.2 +before_script: + - composer install +script: + - vendor/bin/phpunit -v +after_script: + - travis_retry vendor/bin/php-coveralls -v \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f0e3b69 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# KanDisheng DemoPHP + +[![License](https://poser.pugx.org/KanDisheng/DemoPHP/license)](LICENSE) +[![Download](https://poser.pugx.org/KanDisheng/DemoPHP/downloads)](https://packagist.org/packages/KanDisheng/DemoPHP) +[![Stable](https://poser.pugx.org/KanDisheng/DemoPHP/version)](https://packagist.org/packages/KanDisheng/DemoPHP) +[![Unstable](https://poser.pugx.org/KanDisheng/DemoPHP/v/unstable)](https://packagist.org/packages/KanDisheng/DemoPHP) +[![composer.lock Available](https://poser.pugx.org/KanDisheng/DemoPHP/composerlock)](https://packagist.org/packages/KanDisheng/DemoPHP) +[![Build Status](https://travis-ci.org/KanDisheng/DemoPHP.svg?branch=master)](https://travis-ci.org/KanDisheng/DemoPHP) +[![Coverage Status](https://coveralls.io/repos/github/KanDisheng/DemoPHP/badge.svg?branch=master)](https://coveralls.io/github/KanDisheng/DemoPHP?branch=master) + +> KanDisheng DemoPHP + +## Manual + +- [Version 1.0 简体中文](manual/1.0_SimplifiedChinese.md) + +## Contributor + +- [Candison November](http://www.kandisheng.com) - Founder + +## Information + +- [Homepage](http://www.kandisheng.com) +- [GitHub](https://github.com/KanDisheng/DemoPHP) +- [Packagist](https://packagist.org/packages/KanDisheng/DemoPHP) +- [Feedback](https://github.com/KanDisheng/DemoPHP/issues) +- [About KanDisheng](http://www.kandisheng.com) \ No newline at end of file diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..60a6d6f --- /dev/null +++ b/autoload.php @@ -0,0 +1,34 @@ + + */ + +$autoloaDirectory = array( + 'class' => 'KanDisheng\\DemoPHP', + 'interface' => 'KanDisheng\\DemoPHP' +); + +foreach ($autoloaDirectory as $directory => $namespaceRoot) { + $directory = sprintf('%s%s%s', __DIR__, DIRECTORY_SEPARATOR, $directory); + spl_autoload_register(function ($className) use ($directory, $namespaceRoot) { + $directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory); + $directory = rtrim($directory, '/\\'); + $namespaceRoot = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $namespaceRoot); + $namespaceRoot = trim($namespaceRoot, '/\\'); + $className = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $className); + $className = trim($className, '/\\'); + if (substr($className, 0, strlen($namespaceRoot)) == $namespaceRoot) { + $className = substr($className, strlen($namespaceRoot)); + $className = ltrim($className, '/\\'); + } + $extensionList = array('php', 'class.php'); + foreach ($extensionList as $extension) { + $file = $directory . DIRECTORY_SEPARATOR . $className . '.' . $extension; + if (is_file($file) && is_readable($file)) { + require_once($file); + } + } + }); +} diff --git a/class/Demo.php b/class/Demo.php new file mode 100644 index 0000000..8655eb5 --- /dev/null +++ b/class/Demo.php @@ -0,0 +1,32 @@ + + */ + +namespace KanDisheng\DemoPHP; + +/** + * Class Demo + * @package KanDisheng\DemoPHP + */ +class Demo implements DemoInterface +{ + /** + * Demo constructor. + */ + public function __construct() + { + } + + /** + * Demo + * @param string $string + * @return string + */ + public function demo($string = '') + { + return $string; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d42edea --- /dev/null +++ b/composer.json @@ -0,0 +1,71 @@ +{ + "name": "kandisheng/demophp", + "type": "library", + "license": "Apache-2.0", + "homepage": "http://www.kandisheng.com", + "description": "KanDisheng DemoPHP", + "keywords": [ + "KanDisheng", + "DemoPHP", + "PHP" + ], + "support": { + "issues": "https://github.com/KanDisheng/DemoPHP/issues", + "source": "https://github.com/KanDisheng/DemoPHP" + }, + "authors": [ + { + "name": "Candison November", + "role": "Founder", + "email": "kandisheng@163.com", + "homepage": "http://www.kandisheng.com" + } + ], + "autoload": { + "psr-4": { + "KanDisheng\\DemoPHP\\": [ + "interface", + "class" + ] + } + }, + "autoload-dev": { + "psr-4": { + "KanDisheng\\DemoPHP\\Test\\": "test", + "KanDisheng\\DemoPHP\\Script\\": "script" + } + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "*", + "phpmd/phpmd": "*", + "squizlabs/php_codesniffer": "*", + "satooshi/php-coveralls": "*", + "CodeMommy/TaskPHP": "*" + }, + "scripts": { + "environment": [ + "composer -V", + "php -v", + "php -m" + ], + "update-project": [ + "git pull", + "composer self-update", + "composer update" + ], + "test": [ + "composer phpunit", + "composer phpcbf", + "composer phpcs", + "composer phpmd" + ], + "phpmd": "\"vendor/bin/phpmd\" autoload.php,interface,class,script,test,test_case text cleancode,codesize,controversial,design,naming,unusedcode", + "phpcs": "\"vendor/bin/phpcs\" autoload.php interface class script test test_case --standard=PSR2", + "phpcbf": "\"vendor/bin/phpcbf\" autoload.php interface class script test test_case --standard=PSR2", + "phpunit": "KanDisheng\\DemoPHP\\Script\\PHPUnit::start", + "clean": "KanDisheng\\DemoPHP\\Script\\Clean::start" + } +} \ No newline at end of file diff --git a/interface/DemoInterface.php b/interface/DemoInterface.php new file mode 100644 index 0000000..af7ca4b --- /dev/null +++ b/interface/DemoInterface.php @@ -0,0 +1,27 @@ + + */ + +namespace KanDisheng\DemoPHP; + +/** + * Interface DemoInterface + * @package KanDisheng\DemoPHP + */ +interface DemoInterface +{ + /** + * DemoInterface constructor. + */ + public function __construct(); + + /** + * Demo + * @param string $string + * @return string + */ + public function demo($string = ''); +} diff --git a/manual/1.0_SimplifiedChinese.md b/manual/1.0_SimplifiedChinese.md new file mode 100644 index 0000000..3ad1368 --- /dev/null +++ b/manual/1.0_SimplifiedChinese.md @@ -0,0 +1 @@ +# KanDisheng DemoPHP 1.0 开发手册 \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..800d9fa --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + + ./test + ./test_case + + + + + ./interface + ./class + + + + + + + \ No newline at end of file diff --git a/script/Clean.php b/script/Clean.php new file mode 100644 index 0000000..f6bf1a0 --- /dev/null +++ b/script/Clean.php @@ -0,0 +1,42 @@ + + */ + +namespace KanDisheng\DemoPHP\Script; + +use CodeMommy\TaskPHP\Console; +use CodeMommy\TaskPHP\FileSystem; + +/** + * Class Clean + * @package KanDisheng\DemoPHP\Script; + */ +class Clean +{ + /** + * Clean constructor. + */ + public function __construct() + { + } + + /** + * Start + */ + public static function start() + { + PHPUnit::clean(); + $removeList = array( + 'workbench' + ); + $result = FileSystem::remove($removeList); + if ($result) { + Console::printLine('Clean Finished.', 'success'); + } else { + Console::printLine('Clean Error.', 'error'); + } + } +} diff --git a/script/PHPUnit.php b/script/PHPUnit.php new file mode 100644 index 0000000..0ec4e56 --- /dev/null +++ b/script/PHPUnit.php @@ -0,0 +1,99 @@ + + */ + +namespace KanDisheng\DemoPHP\Script; + +use CodeMommy\TaskPHP\Console; +use CodeMommy\TaskPHP\FileSystem; + +/** + * Class PHPUnit + * @package KanDisheng\DemoPHP\Script; + */ +class PHPUnit +{ + const BASE_PATH_NAME = 'KanDisheng'; + + /** + * Base Path + * @var string + */ + private static $basePath = ''; + + /** + * Workbench Path + * @var string + */ + private static $workbenchPath = ''; + + /** + * PHPUnit constructor. + */ + public function __construct() + { + } + + /** + * Get Base Path + * @return string + */ + private static function getBasePath() + { + if (empty(self::$basePath)) { + self::$basePath = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, self::BASE_PATH_NAME); + } + return self::$basePath; + } + + /** + * Get Workbench Path + * @return string + */ + private static function getWorkbenchPath() + { + if (empty(self::$workbenchPath)) { + self::$workbenchPath = sprintf('%s%s%s%s', self::getBasePath(), DIRECTORY_SEPARATOR, time(), rand(100, 999)); + } + return self::$workbenchPath; + } + + /** + * Clean + * @return bool + */ + public static function clean() + { + $removeList = array( + self::getBasePath() + ); + $result = FileSystem::remove($removeList); + if ($result) { + Console::printLine('Clean PHPUnit Report Finished.', 'success'); + return true; + } + Console::printLine('Clean PHPUnit Report Error.', 'error'); + return false; + } + + /** + * Start + */ + public static function start() + { + $coveragePath = sprintf('%s%sCodeCoverageReport', self::getWorkbenchPath(), DIRECTORY_SEPARATOR); + $coveragePathHTML = sprintf('%s%sHTML', $coveragePath, DIRECTORY_SEPARATOR); + $coverageFileHTML = sprintf('%s%sindex.html', $coveragePathHTML, DIRECTORY_SEPARATOR); + $coverageFileClover = sprintf('%s%sClover%sclover.xml', $coveragePath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); + $command = sprintf('"vendor/bin/phpunit" -v --coverage-html="%s" --coverage-clover="%s"', $coveragePathHTML, $coverageFileClover); + system($command); + if (is_file($coverageFileHTML)) { + system(sprintf('start %s', $coverageFileHTML)); + return; + } + Console::printLine('No PHPUnit Report.', 'information'); + } +} diff --git a/test/BaseTest.php b/test/BaseTest.php new file mode 100644 index 0000000..d849aa4 --- /dev/null +++ b/test/BaseTest.php @@ -0,0 +1,59 @@ + + */ + +declare(strict_types=1); + +namespace KanDisheng\DemoPHP\Test; + +use PHPUnit\Framework\TestCase; + +/** + * Class BaseTest + * @package KanDisheng\DemoPHP\Test + */ +class BaseTest extends TestCase +{ + const TEST_CASE_PATH = 'test_case'; + + /** + * Test Case Path + * @var string + */ + private $testCasePath = ''; + + /** + * BaseTest constructor. + */ + public function __construct() + { + parent::__construct(); + $this->testCasePath = sprintf('%s/../%s', __DIR__, self::TEST_CASE_PATH); + } + + /** + * Get Test Case Path + * @param string $path + * @return string + */ + protected function getTestCasePath($path = '') + { + if (empty($path)) { + return $this->testCasePath; + } + $path = trim($path, '/\\'); + $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); + return sprintf('%s%s%s', $this->testCasePath, DIRECTORY_SEPARATOR, $path); + } + + /** + * Test + */ + public function test() + { + $this->assertTrue(true); + } +} diff --git a/test/DemoTest.php b/test/DemoTest.php new file mode 100644 index 0000000..ec3821f --- /dev/null +++ b/test/DemoTest.php @@ -0,0 +1,46 @@ + + */ + +declare(strict_types=1); + +namespace KanDisheng\DemoPHP\Test; + +use KanDisheng\DemoPHP\Demo; + +/** + * Class DemoTest + * @package KanDisheng\DemoPHP\Test + */ +class DemoTest extends BaseTest +{ + /** + * DemoTest constructor. + */ + public function __construct() + { + parent::__construct(); + } + + /** + * Test Construct + */ + public function testConstruct() + { + new Demo(); + $this->assertTrue(true); + } + + /** + * Test Demo + * @return void + */ + public function testDemo() + { + $demo = new Demo(); + $this->assertEquals($demo->demo(1), 1); + } +} diff --git a/test_case/.gitkeep b/test_case/.gitkeep new file mode 100644 index 0000000..e69de29