From 2e0c0ef66ffedac0c4965fcc810f10c49fb26180 Mon Sep 17 00:00:00 2001 From: anolilab Date: Fri, 24 Jul 2015 16:37:30 +0200 Subject: [PATCH 1/2] start --- .coveralls.yml | 1 + .editorconfig | 15 +++ .gitattributes | 10 ++ .gitignore | 4 + .php_cs | 27 ++++ .php_cs.cache | 1 + .scrutinizer.yml | 167 ++++++++++++++++++++++++ .travis.yml | 55 ++++++++ CHANGELOG.md | 20 +++ CONTRIBUTING.md | 33 +++++ LICENSE | 2 +- README.md | 58 +++++++- composer.json | 52 ++++++++ phpunit.xml.dist | 35 +++++ src/Gwa/Contracts/WPBridgeInterface.php | 7 + src/Gwa/MockWPBridge.php | 105 +++++++++++++++ src/Gwa/Traits/WpBridgeTrait.php | 41 ++++++ src/Gwa/WPBridge.php | 40 ++++++ 18 files changed, 671 insertions(+), 2 deletions(-) create mode 100644 .coveralls.yml create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .php_cs create mode 100644 .php_cs.cache create mode 100644 .scrutinizer.yml create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/Gwa/Contracts/WPBridgeInterface.php create mode 100644 src/Gwa/MockWPBridge.php create mode 100644 src/Gwa/Traits/WpBridgeTrait.php create mode 100644 src/Gwa/WPBridge.php diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..7712ce0 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +src_dir: src \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9d49909 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b263871 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/.scrutinizer.yml export-ignore +/tests export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f02a2f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +composer.lock +docs +vendor diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..a70436d --- /dev/null +++ b/.php_cs @@ -0,0 +1,27 @@ +files() + ->in(__DIR__) + ->exclude('build') + ->exclude('vendor') + ->notName('*.phar') + ->notName('CONTRIBUTING') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return Symfony\CS\Config\Config::create() + // use default PSR-2_LEVEL: + ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) + ->fixers( + [ + 'header_comment', + 'phpdoc_order', + 'ordered_use', + 'short_array_syntax', + 'strict', + 'strict_param', + ] + ) + ->finder($finder) + ->setUsingCache(true); diff --git a/.php_cs.cache b/.php_cs.cache new file mode 100644 index 0000000..a334164 --- /dev/null +++ b/.php_cs.cache @@ -0,0 +1 @@ +a:3:{s:7:"version";s:53:"1.9.1:v1.9.1#f2c2c5527113f346d77eb790e62395fe8de58c4f";s:6:"fixers";a:26:{i:0;s:6:"braces";i:1;s:6:"elseif";i:2;s:8:"encoding";i:3;s:10:"eof_ending";i:4;s:19:"function_call_space";i:5;s:20:"function_declaration";i:6;s:14:"header_comment";i:7;s:11:"indentation";i:8;s:20:"line_after_namespace";i:9;s:8:"linefeed";i:10;s:19:"lowercase_constants";i:11;s:18:"lowercase_keywords";i:12;s:21:"method_argument_space";i:13;s:12:"multiple_use";i:14;s:11:"ordered_use";i:15;s:11:"parenthesis";i:16;s:15:"php_closing_tag";i:17;s:12:"phpdoc_order";i:18;s:4:"psr0";i:19;s:18:"short_array_syntax";i:20;s:9:"short_tag";i:21;s:25:"single_line_after_imports";i:22;s:6:"strict";i:23;s:12:"strict_param";i:24;s:15:"trailing_spaces";i:25;s:10:"visibility";}s:6:"hashes";a:3:{s:24:"src\Gwa\MockWPBridge.php";i:-314380194;s:20:"src\Gwa\WPBridge.php";i:-1930432888;s:29:"src\Gwa\WPBridgeInterface.php";i:1234789943;}} \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..74a55c5 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,167 @@ +filter: + paths: ['src/*'] + excluded_paths: [tests/*, vendor/*] + +checks: + php: + code_rating: true + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: false + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + no_unnecessary_function_call_in_for_loop: true + avoid_unnecessary_concatenation: true + duplication: true + prefer_sapi_constant: true + variable_existence: true + useless_calls: true + use_statement_alias_conflict: true + unused_variables: true + unused_properties: true + unused_parameters: true + unused_methods: true + unreachable_code: true + sql_injection_vulnerabilities: true + security_vulnerabilities: true + precedence_mistakes: true + precedence_in_conditions: true + parameter_non_unique: true + no_property_on_interface: true + no_non_implemented_abstract_methods: true + deprecated_code_usage: true + closure_use_not_conflicting: true + closure_use_modifiable: true + avoid_useless_overridden_methods: true + avoid_conflicting_incrementers: true + assignment_of_null_return: true + verify_access_scope_valid: true + too_many_arguments: true + symfony_request_injection: true + parameter_doc_comments: true + argument_type_checks: true + avoid_corrupting_byteorder_marks: true + avoid_entity_manager_injection: true + catch_class_exists: true + encourage_shallow_comparison: false + foreach_traversable: true + foreach_usable_as_reference: true + instanceof_class_exists: true + method_calls_on_non_object: true + missing_arguments: true + no_duplicate_arguments: false + require_php_tag_first: true + return_doc_comments: true + verify_property_names: true + verify_argument_usable_as_reference: true + use_self_instead_of_fqcn: true + uppercase_constants: true + simplify_boolean_return: true + properties_in_camelcaps: true + prefer_while_loop_over_for_loop: true + phpunit_assertions: true + parameters_in_camelcaps: true + param_doc_comment_if_not_inferrable: true + optional_parameters_at_the_end: true + no_short_variable_names: + minimum: '3' + no_short_method_names: + minimum: '' + no_goto: true + newline_at_end_of_file: true + more_specific_types_in_doc_comments: true + line_length: + max_length: '160' + function_in_camel_caps: true + fix_line_ending: true + encourage_single_quotes: true + encourage_postdec_operator: true + classes_in_camel_caps: true + avoid_unnecessary_concatenation: true + avoid_todo_comments: true + avoid_multiple_statements_on_same_line: true + avoid_fixme_comments: true + +build: + environment: + php: '5.4.0' + dependencies: + override: + - 'composer install' + +tools: + external_code_coverage: + timeout: 600 + runs: 3 + php_changetracking: true + + php_code_sniffer: + config: + standard: PSR-2 + + php_cs_fixer: + enabled: true + extensions: + - php + command: php-cs-fixer + config: + level: all + filter: + excluded_paths: + - 'bin/*' + - 'vendor/*' + - 'tests/*' + + php_loc: + enabled: true + extensions: + - php + command: phploc + filter: + excluded_paths: + - bin + - vendor + - tests/* + + php_mess_detector: + enabled: true + extensions: + - php + command: phpmd + filter: + excluded_paths: + - 'bin/*' + - 'vendor/*' + - 'tests/*' + php_cpd: + enabled: false + + php_analyzer: + enabled: true + extensions: + - php + filter: + excluded_paths: + - 'bin/*' + - 'vendor/*' + - 'tests/*' + + php_pdepend: + enabled: true + suffixes: + - php + command: pdepend + excluded_dirs: + - bin + - vendor + - tests/* + + sensiolabs_security_checker: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..da2365d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,55 @@ +language: php + +php: + - 5.5.9 + - 5.5 + - 5.6 + - 7.0 + - hhvm + - nightly + - hhvm-nightly + +env: + global: + - setup=basic + +matrix: + include: + - php: 5.5.9 + env: setup=lowest + - php: 5.5.9 + env: setup=stable + allow_failures: + - env: setup=lowest + - env: setup=stable + - php: 7.0 + - php: nightly + - php: hhvm + - php: hhvm-nightly + fast_finish: true + +sudo: false + +cache: + directories: + - $HOME/.composer/cache + +before_install: + - if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then git fetch origin "refs/pull/$TRAVIS_PULL_REQUEST/head"; else git fetch origin "$TRAVIS_BRANCH"; fi; + - if [[ "$TRAVIS_COMMIT" != `git rev-parse FETCH_HEAD` ]]; then echo "Pull request or branch commit hash has changed, aborting."; exit 1; fi; + - composer self-update + - travis_retry composer self-update + - travis_retry composer install --prefer-source --no-interaction + - OCULAR_ENV='5.4' + +install: + - curl http://get.sensiolabs.org/security-checker.phar -o security-checker.phar + - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-source; fi + - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi + - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi + + +script: + - php -n security-checker.phar security:check --format=simple + - vendor/bin/phpunit --verbose --coverage-text --coverage-clover=build/logs/coverage.clover + - if [ $(phpenv version-name) = $OCULAR_ENV ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover build/logs/coverage.clover; fi diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b9cd259 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All Notable changes to `MockeryWPBridge` will be documented in this file + +## NEXT - YYYY-MM-DD + +### Added +- Nothing + +### Deprecated +- Nothing + +### Fixed +- Nothing + +### Removed +- Nothing + +### Security +- Nothing diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..35c0539 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +We accept contributions via Pull Requests on [Github](https://github.com/gwa/MockeryWPBridge). + + +## Pull Requests + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-cs`` and fix it with ``$ composer fix-cs``. + + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **Create feature branches** - Don't ask us to pull from your master branch. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + + +## Running Tests + +``` bash +$ phpunit +``` + + +**Happy coding**! diff --git a/LICENSE b/LICENSE index c9597d3..1815c87 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Great White Ark +Copyright (c) 2015 MockeryWPBridge Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6f36e5f..97e3e29 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ # MockeryWPBridge -MockeryWPBridge is a simple bridge to mock all wordpress function. + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/gwa/MockeryWPBridge.svg?style=flat-square)](https://packagist.org/packages/gwa/MockeryWPBridge) +[![Total Downloads](https://img.shields.io/packagist/dt/gwa/MockeryWPBridge.svg?style=flat-square)](https://packagist.org/packages/gwa/MockeryWPBridge) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) + +## Master + +[![Build Status](https://img.shields.io/travis/gwa/MockeryWPBridge/master.svg?style=flat-square)](https://travis-ci.org/gwa/MockeryWPBridge) +[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/gwa/MockeryWPBridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/gwa/MockeryWPBridge/code-structure) +[![Quality Score](https://img.shields.io/scrutinizer/g/gwa/MockeryWPBridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/gwa/MockeryWPBridge) + +## Develop + +[![Build Status](https://img.shields.io/travis/gwa/MockeryWPBridge/master.svg?style=flat-square)](https://travis-ci.org/gwa/MockeryWPBridge) +[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/gwa/MockeryWPBridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/gwa/MockeryWPBridge/code-structure) +[![Quality Score](https://img.shields.io/scrutinizer/g/gwa/MockeryWPBridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/gwa/MockeryWPBridge) + +## Install + +Via Composer + +``` bash +$ composer require gwa/MockeryWPBridge +``` + +## Usage + +``` php +echo "test"; +``` + +## Change log + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security + +If you discover any security related issues, please email :author_email instead of using the issue tracker. + +## Credits + +- [Great White Ark](https://github.com/gwa) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f3ee40b --- /dev/null +++ b/composer.json @@ -0,0 +1,52 @@ +{ + "name" : "gwa/MockeryWPBridge", + "type" : "library", + "description": "MockeryWPBridge is a simple bridge to mock all wordpress function.", + "keywords" : [ + ":keywords" + ], + "license" : "MIT", + "homepage" : "https://github.com/gwa/MockeryWPBridge", + "support" : { + "issues" : "https://github.com/gwa/MockeryWPBridge/issues", + "source" : "https://github.com/gwa/MockeryWPBridge" + }, + "authors" : [ + { + "name" : "Great White Ark", + "homepage": "http://www.greatwhiteark.com", + "role" : "Developer" + } + ], + "require": { + "php" : ">=5.4.0" + }, + "require-dev": { + "fabpot/php-cs-fixer" : "~1.9", + "mockery/mockery" : "~0.9.4", + "phpunit/phpunit" : "~4.6.4", + "scrutinizer/ocular" : "~1.1" + }, + "autoload": { + "psr-4": { + "Gwa\\Wordpress\\MockeryWPBridge\\" : "src/Gwa/" + } + }, + "autoload-dev": { + "psr-4": { + "Gwa\\Wordpress\\MockeryWPBridge\\Tests\\" : "tests/" + } + }, + "extra": { + "branch-alias": { + "dev-master" : "1.0.0-dev" + } + }, + "scripts": { + "test" : "phpunit", + "check-cs" : "php-cs-fixer.phar fix -v --dry-run", + "fix-cs" : "php-cs-fixer.phar fix" + }, + "minimum-stability" : "dev", + "prefer-stable" : true +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a9ce56b --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,35 @@ + + + + + ./tests + + + + + ./src + + + + + + + + + + + + + diff --git a/src/Gwa/Contracts/WPBridgeInterface.php b/src/Gwa/Contracts/WPBridgeInterface.php new file mode 100644 index 0000000..72d65c0 --- /dev/null +++ b/src/Gwa/Contracts/WPBridgeInterface.php @@ -0,0 +1,7 @@ +shortcodes[$tag] = $func; + } + + /** + * Check if shortcode exist. + * + * @param string $tag + * + * @return boolean + */ + public function hasShortcode($tag) + { + return isset($this->shortcodes[$tag]); + } + + /** + * Get a shortcode callback. + * + * @param string $tag + * + * @return mixed + */ + public function getShortcodeCallback($tag) + { + return isset($this->shortcodes[$tag]) ? $this->shortcodes[$tag] : null; + } + + /** + * Combines shortcode attributes with known attributes and fills in defaults when needed. + * + * @param array $pairs + * @param array $atts + * @param string|null $shortcode + * + * @return array + */ + public function shortcodeAtts($pairs, $atts, $shortcode = null) + { + return array_merge($pairs, $atts); + } + + /* -------- */ + + /** + * Wordpress mock on __() func. + * + * @param string $text + * @param string $domain + * + * @return string + */ + public function __($text, $domain) + { + return $text; + } + + /* -------- */ + + public function __call($function, $args) + { + return call_user_func_array([$this->mock, $function], $args); + } + + public function mock() + { + if (!isset($this->mock)) { + $this->mock = Mockery::mock('WPBridge'); + } + + return $this->mock; + } +} diff --git a/src/Gwa/Traits/WpBridgeTrait.php b/src/Gwa/Traits/WpBridgeTrait.php new file mode 100644 index 0000000..3aae1bd --- /dev/null +++ b/src/Gwa/Traits/WpBridgeTrait.php @@ -0,0 +1,41 @@ +wpbridge = $wpbridge; + + return $this; + } + + /** + * Get MockeryWPBridge. + * + * @return WPBridge + */ + public function getWPBridge() + { + return $this->wpbridge; + } +} diff --git a/src/Gwa/WPBridge.php b/src/Gwa/WPBridge.php new file mode 100644 index 0000000..ca2e633 --- /dev/null +++ b/src/Gwa/WPBridge.php @@ -0,0 +1,40 @@ +wpGetAttachmentImageSrc(...); + */ +class WPBridge implements WPBridgeInterface +{ + /** + * Magic call on all camel wordpress functions. + * + * @param string $function + * + * @return array + */ + public function __call($function, $args) + { + return call_user_func_array($this->camelToUnderscore($function), $args); + } + + /** + * Rename camelcase to underscore. + * + * @param string $string + * + * @return string + */ + public function camelToUnderscore($string) + { + return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $string)); + } +} From cc8b1534f7ae92719327449c926e73819bc2a6b5 Mon Sep 17 00:00:00 2001 From: anolilab Date: Fri, 24 Jul 2015 16:41:37 +0200 Subject: [PATCH 2/2] rename class, added email --- README.md | 4 ++-- src/Gwa/{MockWPBridge.php => MockeryWPBridge.php} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Gwa/{MockWPBridge.php => MockeryWPBridge.php} (97%) diff --git a/README.md b/README.md index 97e3e29..96bdda8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ $ composer require gwa/MockeryWPBridge ## Usage ``` php -echo "test"; +TODO ``` ## Change log @@ -46,7 +46,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Security -If you discover any security related issues, please email :author_email instead of using the issue tracker. +If you discover any security related issues, please email groves@greatwhiteark.com instead of using the issue tracker. ## Credits diff --git a/src/Gwa/MockWPBridge.php b/src/Gwa/MockeryWPBridge.php similarity index 97% rename from src/Gwa/MockWPBridge.php rename to src/Gwa/MockeryWPBridge.php index 9934df5..c8c375d 100644 --- a/src/Gwa/MockWPBridge.php +++ b/src/Gwa/MockeryWPBridge.php @@ -4,7 +4,7 @@ use Gwa\Wordpress\MockeryWPBridge\Contracts\WPBridgeInterface; use Mockery; -class MockWPBridge implements WPBridgeInterface +class MockeryWPBridge implements WPBridgeInterface { /** * Mockery instance.