From ac93f5e377389cbe7ed9305e7c427ded0c63d8b7 Mon Sep 17 00:00:00 2001 From: Chris Tankersley Date: Tue, 28 Apr 2015 01:31:29 -0400 Subject: [PATCH] Added some tests and fixes some PHPCS errors --- .gitattributes | 19 + .gitignore | 3 +- composer.json | 8 +- composer.lock | 1258 ++++++++++++++++- .../Controller/AccountController.php | 122 +- src/Mentoring/Controller/AuthController.php | 128 +- src/Mentoring/Controller/IndexController.php | 26 +- .../AccountServiceProvider.php | 79 +- .../ServiceProvider/AuthServiceProvider.php | 134 +- .../ServiceProvider/IndexServiceProvider.php | 75 +- src/Mentoring/User/User.php | 212 +-- src/Mentoring/User/UserHydrator.php | 140 +- src/Mentoring/User/UserNotFoundException.php | 16 +- src/Mentoring/User/UserService.php | 132 +- tests/Bootstrap.php | 0 tests/MentoringTest/User/UserHydratorTest.php | 132 ++ tests/MentoringTest/User/UserTest.php | 50 + tests/phpunit.xml | 19 + tests/run-full-tests.sh | 5 + 19 files changed, 2020 insertions(+), 538 deletions(-) create mode 100644 .gitattributes create mode 100644 tests/Bootstrap.php create mode 100644 tests/MentoringTest/User/UserHydratorTest.php create mode 100644 tests/MentoringTest/User/UserTest.php create mode 100644 tests/phpunit.xml create mode 100644 tests/run-full-tests.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..24475fb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# Set default behaviour, in case users don't have core.autocrlf set. +* text=auto + +# Declare files that will always have LF line endings on checkout. +* text eol=lf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.PNG binary +*.jpg binary +*.gif binary +*.jar binary +*.pdf binary +*.ppt binary +*.ttf binary +*.bson binary +*.request binary +*.response binary +*.phar binary \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5fea75f..40dd93f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ html/ .idea ._.DS_Store ._Vagrantfile -._puphpet \ No newline at end of file +._puphpet +tests/coverage/ \ No newline at end of file diff --git a/composer.json b/composer.json index e225276..f2c4082 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,13 @@ "symfony/config": "~2.6", "symfony/translation": "~2.6", "symfony/security-csrf": "~2.6", - "symfony/form": "~2.6" + "symfony/form": "~2.6", + "mockery/mockery": "0.9.*" + }, + "require-dev": { + "phpunit/phpunit": "4.6.*", + "squizlabs/php_codesniffer": "~2.3", + "phpmd/phpmd": "~2.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index efc8755..731a844 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6a19af91c4ed4895c5b9932be9856156", + "hash": "9d1fadeafb20b943eed789b3b7350c31", "packages": [ { "name": "doctrine/annotations", @@ -662,6 +662,51 @@ ], "time": "2014-01-28 22:29:15" }, + { + "name": "hamcrest/hamcrest-php", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "ac50c470531243944f977b8de75be0b684a9cb51" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/ac50c470531243944f977b8de75be0b684a9cb51", + "reference": "ac50c470531243944f977b8de75be0b684a9cb51", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "classmap": [ + "hamcrest" + ], + "files": [ + "hamcrest/Hamcrest.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2015-01-20 19:34:09" + }, { "name": "league/oauth2-client", "version": "0.10.1", @@ -723,6 +768,71 @@ ], "time": "2015-04-02 15:09:47" }, + { + "name": "mockery/mockery", + "version": "0.9.4", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~1.1", + "lib-pcre": ">=7.0", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2015-04-02 19:54:00" + }, { "name": "monolog/monolog", "version": "1.13.1", @@ -2248,7 +2358,1151 @@ "time": "2014-12-05 15:19:21" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, + { + "name": "pdepend/pdepend", + "version": "2.0.6", + "source": { + "type": "git", + "url": "https://github.com/pdepend/pdepend.git", + "reference": "a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pdepend/pdepend/zipball/a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4", + "reference": "a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4", + "shasum": "" + }, + "require": { + "symfony/config": ">=2.4", + "symfony/dependency-injection": ">=2.4", + "symfony/filesystem": ">=2.4" + }, + "require-dev": { + "phpunit/phpunit": "4.*@stable", + "squizlabs/php_codesniffer": "@stable" + }, + "bin": [ + "src/bin/pdepend" + ], + "type": "library", + "autoload": { + "psr-0": { + "PDepend\\": "src/main/php/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Official version of pdepend to be handled with Composer", + "time": "2015-03-02 08:06:43" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpmd/phpmd", + "version": "2.2.2", + "source": { + "type": "git", + "url": "https://github.com/phpmd/phpmd.git", + "reference": "7dc4a6b5c07b119ab5da7960b56303fa6855eb84" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpmd/phpmd/zipball/7dc4a6b5c07b119ab5da7960b56303fa6855eb84", + "reference": "7dc4a6b5c07b119ab5da7960b56303fa6855eb84", + "shasum": "" + }, + "require": { + "pdepend/pdepend": "2.0.*", + "php": ">=5.3.0", + "symfony/config": ">=2.4", + "symfony/dependency-injection": ">=2.4", + "symfony/filesystem": ">=2.4" + }, + "require-dev": { + "phpunit/phpunit": "*", + "squizlabs/php_codesniffer": "*" + }, + "bin": [ + "src/bin/phpmd" + ], + "type": "project", + "autoload": { + "psr-0": { + "PHPMD\\": "src/main/php" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Manuel Pichler", + "email": "github@manuel-pichler.de", + "homepage": "https://github.com/manuelpichler", + "role": "Project founder" + }, + { + "name": "Other contributors", + "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", + "role": "Contributors" + } + ], + "description": "PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.", + "homepage": "http://phpmd.org/", + "keywords": [ + "mess detection", + "mess detector", + "pdepend", + "phpmd", + "pmd" + ], + "time": "2015-03-26 07:47:05" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.0.16", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/934fd03eb6840508231a7f73eb8940cf32c3b66c", + "reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-04-11 04:35:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "eab81d02569310739373308137284e0158424330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", + "reference": "eab81d02569310739373308137284e0158424330", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-04-08 04:46:07" + }, + { + "name": "phpunit/phpunit", + "version": "4.6.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "163232991e652e6efed2f8470326fffa61e848e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/163232991e652e6efed2f8470326fffa61e848e2", + "reference": "163232991e652e6efed2f8470326fffa61e848e2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.6.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-04-11 05:23:21" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", + "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-04-02 05:36:41" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "2.3.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "f3100143e94bbeeaa4f1cd7c6389c3733d3d1ce1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/f3100143e94bbeeaa4f1cd7c6389c3733d3d1ce1", + "reference": "f3100143e94bbeeaa4f1cd7c6389c3733d3d1ce1", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2015-04-23 03:40:59" + }, + { + "name": "symfony/dependency-injection", + "version": "v2.6.6", + "target-dir": "Symfony/Component/DependencyInjection", + "source": { + "type": "git", + "url": "https://github.com/symfony/DependencyInjection.git", + "reference": "8e9007012226b4bd41f8afed855c452cf5edc3a6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/8e9007012226b4bd41f8afed855c452cf5edc3a6", + "reference": "8e9007012226b4bd41f8afed855c452cf5edc3a6", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "conflict": { + "symfony/expression-language": "<2.6" + }, + "require-dev": { + "symfony/config": "~2.2", + "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", + "symfony/yaml": "~2.1" + }, + "suggest": { + "symfony/config": "", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\DependencyInjection\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "http://symfony.com", + "time": "2015-03-30 15:54:10" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/src/Mentoring/Controller/AccountController.php b/src/Mentoring/Controller/AccountController.php index f363d4e..3601ccc 100644 --- a/src/Mentoring/Controller/AccountController.php +++ b/src/Mentoring/Controller/AccountController.php @@ -1,61 +1,61 @@ -get('user'); - - $form = $this->createProfileForm($app, $user); - - $form->handleRequest($request); - - if ($form->isValid()) { - $app['user.manager']->saveUser($user); - $app['session']->getFlashBag()->add('success', 'Your profile has been saved.'); - - return $app->redirect($app['url_generator']->generate('account.profile')); - } - - return $app['twig']->render('account/profile.twig', array( - 'profile_form' => $form->createView() - )); - } - - /** - * @param Application $app - * @param User $user - * @param array $options - * @return Form - */ - protected function createProfileForm(Application $app, User $user, array $options = array()) - { - /** @var \Symfony\Component\Form\FormFactory $form_factory */ - $form_factory = $app['form.factory']; - - return $form_factory - ->createBuilder('form', $user, array_merge($options, array( - 'data_class' => 'Mentoring\User\User' - ))) - ->add('name', 'text') - ->add('email', 'email', [ - 'constraints' => [new Email()] - ]) - ->add('isMentor', 'checkbox', [ - 'required' => false, - ]) - ->add('isMentee', 'checkbox', [ - 'required' => false, - ]) - ->add('save', 'submit') - ->getForm(); - } -} \ No newline at end of file +get('user'); + + $form = $this->createProfileForm($app, $user); + + $form->handleRequest($request); + + if ($form->isValid()) { + $app['user.manager']->saveUser($user); + $app['session']->getFlashBag()->add('success', 'Your profile has been saved.'); + + return $app->redirect($app['url_generator']->generate('account.profile')); + } + + return $app['twig']->render('account/profile.twig', array( + 'profile_form' => $form->createView() + )); + } + + /** + * @param Application $app + * @param User $user + * @param array $options + * @return Form + */ + protected function createProfileForm(Application $app, User $user, array $options = array()) + { + /** @var \Symfony\Component\Form\FormFactory $form_factory */ + $form_factory = $app['form.factory']; + + return $form_factory + ->createBuilder('form', $user, array_merge($options, array( + 'data_class' => 'Mentoring\User\User' + ))) + ->add('name', 'text') + ->add('email', 'email', [ + 'constraints' => [new Email()] + ]) + ->add('isMentor', 'checkbox', [ + 'required' => false, + ]) + ->add('isMentee', 'checkbox', [ + 'required' => false, + ]) + ->add('save', 'submit') + ->getForm(); + } +} diff --git a/src/Mentoring/Controller/AuthController.php b/src/Mentoring/Controller/AuthController.php index bf77ce0..9564abe 100644 --- a/src/Mentoring/Controller/AuthController.php +++ b/src/Mentoring/Controller/AuthController.php @@ -1,64 +1,64 @@ -query->get('code'); - - $provider = new Github([ - 'clientId' => $clientID, - 'clientSecret' => $clientSecret, - 'redirectUri' => 'http://mentoring.dev/auth/github', - 'scopes' => ['user', 'read:org', 'user:email'] - ]); - - if(empty($code)) { - $authUrl = $provider->getAuthorizationUrl(); - $app['session']->set('oauth2state', $provider->state); - return $app->redirect($authUrl); - } else { - $token = $provider->getAccessToken('authorization_code', ['code' => $code]); - $userDetails = $provider->getUserDetails($token); - - try { - $user = $app['user.manager']->fetchUserByGithubUid($userDetails->uid); - } catch (UserNotFoundException $exception) { - $email = null; - foreach($provider->getUserEmails($token) as $providerEmail) { - if($providerEmail->primary) { - $email = $providerEmail->email; - break; - } - } - - $user = $app['user.manager']->createUser([ - 'email' => $email, - 'roles' => ['ROLE_USER'], - 'name' => $userDetails->name, - 'githubUid' => $userDetails->uid, - ]); - - $app['user.manager']->saveUser($user); - } - - $app['session']->set('user', $user); - return $app->redirect($app['url_generator']->generate('account.profile')); - } - } - - public function logoutAction(Application $app) - { - $app['session']->clear(); - return $app->redirect($app['url_generator']->generate('index')); - } -} \ No newline at end of file +query->get('code'); + + $provider = new Github([ + 'clientId' => $clientID, + 'clientSecret' => $clientSecret, + 'redirectUri' => 'http://mentoring.dev/auth/github', + 'scopes' => ['user', 'read:org', 'user:email'] + ]); + + if (empty($code)) { + $authUrl = $provider->getAuthorizationUrl(); + $app['session']->set('oauth2state', $provider->state); + return $app->redirect($authUrl); + } else { + $token = $provider->getAccessToken('authorization_code', ['code' => $code]); + $userDetails = $provider->getUserDetails($token); + + try { + $user = $app['user.manager']->fetchUserByGithubUid($userDetails->uid); + } catch (UserNotFoundException $exception) { + $email = null; + foreach ($provider->getUserEmails($token) as $providerEmail) { + if ($providerEmail->primary) { + $email = $providerEmail->email; + break; + } + } + + $user = $app['user.manager']->createUser([ + 'email' => $email, + 'roles' => ['ROLE_USER'], + 'name' => $userDetails->name, + 'githubUid' => $userDetails->uid, + ]); + + $app['user.manager']->saveUser($user); + } + + $app['session']->set('user', $user); + return $app->redirect($app['url_generator']->generate('account.profile')); + } + } + + public function logoutAction(Application $app) + { + $app['session']->clear(); + return $app->redirect($app['url_generator']->generate('index')); + } +} diff --git a/src/Mentoring/Controller/IndexController.php b/src/Mentoring/Controller/IndexController.php index 288d61a..5e5a894 100644 --- a/src/Mentoring/Controller/IndexController.php +++ b/src/Mentoring/Controller/IndexController.php @@ -1,13 +1,13 @@ -render('index/index.twig'); - } -} \ No newline at end of file +render('index/index.twig'); + } +} diff --git a/src/Mentoring/ServiceProvider/AccountServiceProvider.php b/src/Mentoring/ServiceProvider/AccountServiceProvider.php index e30e8c1..9080ccd 100644 --- a/src/Mentoring/ServiceProvider/AccountServiceProvider.php +++ b/src/Mentoring/ServiceProvider/AccountServiceProvider.php @@ -1,40 +1,39 @@ -match('/', 'controller.account:profileAction') - ->method('GET|POST') - ->bind('account.profile') - ->before($app['auth.mustAuthenticate']) - ; - - return $controllers; - } - - public function register(Application $app) - { - $app['controller.account'] = $app->share(function ($app) { - return new AccountController(); - }); - } - - -} \ No newline at end of file +match('/', 'controller.account:profileAction') + ->method('GET|POST') + ->bind('account.profile') + ->before($app['auth.mustAuthenticate']); + + return $controllers; + } + + public function register(Application $app) + { + $app['controller.account'] = $app->share( + function ($app) { + return new AccountController(); + } + ); + } +} diff --git a/src/Mentoring/ServiceProvider/AuthServiceProvider.php b/src/Mentoring/ServiceProvider/AuthServiceProvider.php index b4f294a..e69cb3c 100644 --- a/src/Mentoring/ServiceProvider/AuthServiceProvider.php +++ b/src/Mentoring/ServiceProvider/AuthServiceProvider.php @@ -1,68 +1,66 @@ -get('/github', 'controller.auth:githubAction') - ->bind('auth.github') - ->bind('auth.login') - ; - - $controllers - ->get('/logout', 'controller.auth:logoutAction') - ->bind('auth.logout') - ; - - return $controllers; - } - - public function register(Application $app) - { - $app['user.manager'] = function() use($app) { - return new UserService($app['db'], new UserHydrator()); - }; - - $app['auth.mustAuthenticate'] = function(Application $app) { - return function() use ($app) { - if(!$app['session']->has('user')) { - return $app->redirect($app['url_generator']->generate('auth.login')); - } - }; - }; - - $app['auth.isAdmin'] = function(Application $app) { - return function() use ($app) { - $user = $app['session']->get('user'); - if(!$user || $user->role != 'ROLE_ADMIN') { - $app['session']->getFlashBag()->add('error', 'You do not have privileges for the requested page'); - return $app->redirect($app['url_generator']->generate('index')); - } - }; - }; - - $app['controller.auth'] = $app->share(function($app) { - return new AuthController(); - }); - } - - -} \ No newline at end of file +get('/github', 'controller.auth:githubAction') + ->bind('auth.github') + ->bind('auth.login'); + + $controllers + ->get('/logout', 'controller.auth:logoutAction') + ->bind('auth.logout'); + + return $controllers; + } + + public function register(Application $app) + { + $app['user.manager'] = function () use ($app) { + return new UserService($app['db'], new UserHydrator()); + }; + + $app['auth.mustAuthenticate'] = function (Application $app) { + return function () use ($app) { + if (!$app['session']->has('user')) { + return $app->redirect($app['url_generator']->generate('auth.login')); + } + }; + }; + + $app['auth.isAdmin'] = function (Application $app) { + return function () use ($app) { + $user = $app['session']->get('user'); + if (!$user || $user->role != 'ROLE_ADMIN') { + $app['session']->getFlashBag()->add('error', 'You do not have privileges for the requested page'); + return $app->redirect($app['url_generator']->generate('index')); + } + }; + }; + + $app['controller.auth'] = $app->share( + function ($app) { + return new AuthController(); + } + ); + } +} diff --git a/src/Mentoring/ServiceProvider/IndexServiceProvider.php b/src/Mentoring/ServiceProvider/IndexServiceProvider.php index 9b2b369..e41173d 100644 --- a/src/Mentoring/ServiceProvider/IndexServiceProvider.php +++ b/src/Mentoring/ServiceProvider/IndexServiceProvider.php @@ -1,38 +1,37 @@ -get('/', 'controller.index:indexAction') - ->bind('index') - ; - - return $controllers; - } - - public function register(Application $app) - { - $app['controller.index'] = $app->share(function($app) { - return new IndexController(); - }); - } - - -} \ No newline at end of file +get('/', 'controller.index:indexAction') + ->bind('index'); + + return $controllers; + } + + public function register(Application $app) + { + $app['controller.index'] = $app->share( + function ($app) { + return new IndexController(); + } + ); + } +} diff --git a/src/Mentoring/User/User.php b/src/Mentoring/User/User.php index ca1607d..ca16ead 100644 --- a/src/Mentoring/User/User.php +++ b/src/Mentoring/User/User.php @@ -1,106 +1,106 @@ -email; - } - - public function getGithubUid() - { - return $this->githubUid; - } - - public function getId() - { - return $this->id; - } - - public function getName() - { - return $this->name; - } - - public function getRoles() - { - return $this->roles; - } - - public function getTimeCreated() - { - return $this->timeCreated; - } - - public function isEnabled() - { - return $this->isEnabled; - } - - public function isMentee() - { - return (bool)$this->isMentee; - } - - public function isMentor() - { - return (bool)$this->isMentor; - } - - public function setEmail($email) - { - $this->email = $email; - } - - public function setGithubUid($uid) - { - $this->githubUid = $uid; - } - - public function setId($id) - { - $this->id = $id; - } - - public function setIsEnabled($status) - { - $this->isEnabled = $status; - } - - public function setIsMentee($status) - { - $this->isMentee = $status; - } - - public function setIsMentor($status) - { - $this->isMentor = $status; - } - - public function setName($name) - { - $this->name = $name; - } - - public function setRoles($roles) - { - $this->roles = $roles; - } - - public function setTimeCreated(\DateTime $timeCreated) - { - $this->timeCreated = $timeCreated; - } -} \ No newline at end of file +email; + } + + public function getGithubUid() + { + return $this->githubUid; + } + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function getRoles() + { + return $this->roles; + } + + public function getTimeCreated() + { + return $this->timeCreated; + } + + public function isEnabled() + { + return $this->isEnabled; + } + + public function isMentee() + { + return (bool)$this->isMentee; + } + + public function isMentor() + { + return (bool)$this->isMentor; + } + + public function setEmail($email) + { + $this->email = $email; + } + + public function setGithubUid($uid) + { + $this->githubUid = $uid; + } + + public function setId($id) + { + $this->id = $id; + } + + public function setIsEnabled($status) + { + $this->isEnabled = $status; + } + + public function setIsMentee($status) + { + $this->isMentee = $status; + } + + public function setIsMentor($status) + { + $this->isMentor = $status; + } + + public function setName($name) + { + $this->name = $name; + } + + public function setRoles($roles) + { + $this->roles = $roles; + } + + public function setTimeCreated(\DateTime $timeCreated) + { + $this->timeCreated = $timeCreated; + } +} diff --git a/src/Mentoring/User/UserHydrator.php b/src/Mentoring/User/UserHydrator.php index e4312d9..fadd174 100644 --- a/src/Mentoring/User/UserHydrator.php +++ b/src/Mentoring/User/UserHydrator.php @@ -1,70 +1,70 @@ - $object->getEmail(), - 'id' => $object->getId(), - 'name' => $object->getName(), - 'roles' => $object->getRoles(), - 'timeCreated' => $object->getTimeCreated(), - 'isEnabled' => $object->isEnabled(), - 'githubUid' => $object->getGithubUid(), - 'isMentee' => $object->isMentee(), - 'isMentor' => $object->isMentor(), - ]; - - if($data['timeCreated'] instanceof \DateTime) { - $data['timeCreated'] = $data['timeCreated']->format(\DateTime::ISO8601); - } - - return $data; - } - - /** - * Hydrates a user object with the data - * - * @param array $data - * @param User $object - * - * @return User - */ - public function hydrate(array $data, User $object) - { - $object->setEmail($data['email']); - $object->setName($data['name']); - $object->setIsEnabled($data['isEnabled']); - $object->setGithubUid($data['githubUid']); - $object->setIsMentee($data['isMentee']); - $object->setIsMentor($data['isMentor']); - - if(!$data['timeCreated'] instanceof \DateTime) { - $createdTime = new \DateTime($data['timeCreated']); - $object->setTimeCreated($createdTime); - } else { - $object->setTimeCreated($data['timeCreated']); - } - - if(isset($data['id'])) { - $object->setId($data['id']); - } - - if(is_array($data['roles'])) { - $object->setRoles($data['roles']); - } else { - $object->setRoles(unserialize($data['roles'])); - } - - return $object; - } -} \ No newline at end of file + $object->getEmail(), + 'id' => $object->getId(), + 'name' => $object->getName(), + 'roles' => $object->getRoles(), + 'timeCreated' => $object->getTimeCreated(), + 'isEnabled' => $object->isEnabled(), + 'githubUid' => $object->getGithubUid(), + 'isMentee' => $object->isMentee(), + 'isMentor' => $object->isMentor(), + ]; + + if ($data['timeCreated'] instanceof \DateTime) { + $data['timeCreated'] = $data['timeCreated']->format(\DateTime::ISO8601); + } + + return $data; + } + + /** + * Hydrates a user object with the data + * + * @param array $data + * @param User $object + * + * @return User + */ + public function hydrate(array $data, User $object) + { + $object->setEmail($data['email']); + $object->setName($data['name']); + $object->setIsEnabled($data['isEnabled']); + $object->setGithubUid($data['githubUid']); + $object->setIsMentee($data['isMentee']); + $object->setIsMentor($data['isMentor']); + + if (!$data['timeCreated'] instanceof \DateTime) { + $createdTime = new \DateTime($data['timeCreated']); + $object->setTimeCreated($createdTime); + } else { + $object->setTimeCreated($data['timeCreated']); + } + + if (isset($data['id'])) { + $object->setId($data['id']); + } + + if (is_array($data['roles'])) { + $object->setRoles($data['roles']); + } else { + $object->setRoles(unserialize($data['roles'])); + } + + return $object; + } +} diff --git a/src/Mentoring/User/UserNotFoundException.php b/src/Mentoring/User/UserNotFoundException.php index c33f8a6..eb7d875 100644 --- a/src/Mentoring/User/UserNotFoundException.php +++ b/src/Mentoring/User/UserNotFoundException.php @@ -1,8 +1,8 @@ -dbal = $dbal; - $this->hydrator = $hydrator; - } - - public function saveUser(User $user) - { - $data = $this->hydrator->extract($user); - $data['roles'] = serialize($data['roles']); - - if(empty($data['id'])) { - $this->dbal->insert('users', $data); - $user->setId($this->dbal->lastInsertId()); - } else { - echo 'Update'; - $this->dbal->update('users', $data, ['id' => $data['id']]); - } - - return $user; - } - - public function fetchUserByGithubUid($uid) - { - $user = $this->dbal->fetchAssoc('SELECT * FROM users WHERE githubUid = :githubUid', ['githubUid' => $uid]); - if($user) { - $user = $this->hydrator->hydrate($user, new User()); - return $user; - } - - throw new UserNotFoundException('Could not find user with a UID of ' . $uid); - } - - public function createUser($data) - { - $data['timeCreated'] = new \DateTime(); - $data['isEnabled'] = true; - $data['isMentee'] = false; - $data['isMentor'] = false; - - $user = $this->hydrator->hydrate($data, new User()); - - return $user; - } - - public function deleteUser($user) - { - - } -} \ No newline at end of file +dbal = $dbal; + $this->hydrator = $hydrator; + } + + public function saveUser(User $user) + { + $data = $this->hydrator->extract($user); + $data['roles'] = serialize($data['roles']); + + if (empty($data['id'])) { + $this->dbal->insert('users', $data); + $user->setId($this->dbal->lastInsertId()); + } else { + echo 'Update'; + $this->dbal->update('users', $data, ['id' => $data['id']]); + } + + return $user; + } + + public function fetchUserByGithubUid($uid) + { + $user = $this->dbal->fetchAssoc('SELECT * FROM users WHERE githubUid = :githubUid', ['githubUid' => $uid]); + if ($user) { + $user = $this->hydrator->hydrate($user, new User()); + return $user; + } + + throw new UserNotFoundException('Could not find user with a UID of ' . $uid); + } + + public function createUser($data) + { + $data['timeCreated'] = new \DateTime(); + $data['isEnabled'] = true; + $data['isMentee'] = false; + $data['isMentor'] = false; + + $user = $this->hydrator->hydrate($data, new User()); + + return $user; + } + + public function deleteUser($user) + { + + } +} diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php new file mode 100644 index 0000000..e69de29 diff --git a/tests/MentoringTest/User/UserHydratorTest.php b/tests/MentoringTest/User/UserHydratorTest.php new file mode 100644 index 0000000..44b46d0 --- /dev/null +++ b/tests/MentoringTest/User/UserHydratorTest.php @@ -0,0 +1,132 @@ + 'test@test.com', + 'githubUid' => '1234', + 'id' => 1, + 'name' => 'Mr. McTest', + 'roles' => ['ROLE_USER'], + 'timeCreated' => new \DateTime(), + 'isEnabled' => true, + 'isMentee' => true, + 'isMentor' => false, + ]; + } + + protected function getTestUser() + { + $testData = $this->getTestData(); + + $user = new User(); + $user->setEmail($testData['email']); + $user->setGithubUid($testData['githubUid']); + $user->setId($testData['id']); + $user->setName($testData['name']); + $user->setRoles($testData['roles']); + $user->setTimeCreated($testData['timeCreated']); + $user->setIsEnabled($testData['isEnabled']); + $user->setIsMentee($testData['isMentee']); + $user->setIsMentor($testData['isMentor']); + + return $user; + } + + /** + * Makes sure that hydrator properly hydrates + * + * @author Chris Tankersley + * @since 2015-04-28 + */ + public function testUserIsProperlyHydrated() + { + $testData = $this->getTestData(); + + $user = new User(); + $hydrator = new UserHydrator(); + $user = $hydrator->hydrate($testData, $user); + + $this->assertEquals($testData['email'], $user->getEmail()); + $this->assertEquals($testData['githubUid'], $user->getGithubUid()); + $this->assertEquals($testData['id'], $user->getId()); + $this->assertEquals($testData['name'], $user->getName()); + $this->assertEquals($testData['roles'], $user->getRoles()); + $this->assertEquals($testData['timeCreated'], $user->getTimeCreated()); + $this->assertEquals($testData['isEnabled'], $user->isEnabled()); + $this->assertEquals($testData['isMentee'], $user->isMentee()); + $this->assertEquals($testData['isMentor'], $user->isMentor()); + } + + /** + * Makes sure that we handle string dates properly during hydration + * + * @author Chris Tankersley + * @since 2015-04-28 + */ + public function testTimeCreatedHyrdatesWhenNotDateTime() + { + $testData = $this->getTestData(); + $testData['timeCreated'] = $testData['timeCreated']->format(\DateTime::ISO8601); + + $user = new User(); + $hydrator = new UserHydrator(); + $user = $hydrator->hydrate($testData, $user); + + $this->assertEquals($testData['timeCreated'], $user->getTimeCreated()->format(\DateTime::ISO8601)); + } + + /** + * Makes sure that a serialized array for Roles is properly turned into a real array + * + * @author Chris Tankersley + * @since 2015-04-28 + */ + public function testRolesAreUnserializedIfString() + { + $testData = $this->getTestData(); + $roles = $testData['roles']; + $testData['roles'] = serialize($testData['roles']); + + $user = new User(); + $hydrator = new UserHydrator(); + $user = $hydrator->hydrate($testData, $user); + + $this->assertEquals($roles, $user->getRoles()); + } + + /** + * Makes sure that a user object is properly turned into an array + * + * @author Chris Tankersley + * @since 2015-04-28 + */ + public function testExtractionWorks() + { + $user = $this->getTestUser(); + $hydrator = new UserHydrator(); + $data = $hydrator->extract($user); + + $this->assertEquals($data['email'], $user->getEmail()); + $this->assertEquals($data['githubUid'], $user->getGithubUid()); + $this->assertEquals($data['id'], $user->getId()); + $this->assertEquals($data['name'], $user->getName()); + $this->assertEquals($data['roles'], $user->getRoles()); + $this->assertEquals($data['timeCreated'], $user->getTimeCreated()->format(\DateTime::ISO8601)); + $this->assertEquals($data['isEnabled'], $user->isEnabled()); + $this->assertEquals($data['isMentee'], $user->isMentee()); + $this->assertEquals($data['isMentor'], $user->isMentor()); + } +} \ No newline at end of file diff --git a/tests/MentoringTest/User/UserTest.php b/tests/MentoringTest/User/UserTest.php new file mode 100644 index 0000000..1ad9f6a --- /dev/null +++ b/tests/MentoringTest/User/UserTest.php @@ -0,0 +1,50 @@ + + * @since 2015-04-28 + */ + public function testSettersAndGetters() + { + $testData = [ + 'email' => 'test@test.com', + 'githubUid' => '1234', + 'id' => 1, + 'name' => 'Mr. McTest', + 'roles' => ['ROLE_USER'], + 'timeCreated' => new \DateTime(), + 'enabled' => true, + 'isMentee' => true, + 'isMentor' => false, + ]; + + $user = new User(); + $user->setEmail($testData['email']); + $user->setGithubUid($testData['githubUid']); + $user->setId($testData['id']); + $user->setName($testData['name']); + $user->setRoles($testData['roles']); + $user->setTimeCreated($testData['timeCreated']); + $user->setIsEnabled($testData['enabled']); + $user->setIsMentee($testData['isMentee']); + $user->setIsMentor($testData['isMentor']); + + $this->assertEquals($testData['email'], $user->getEmail()); + $this->assertEquals($testData['githubUid'], $user->getGithubUid()); + $this->assertEquals($testData['id'], $user->getId()); + $this->assertEquals($testData['name'], $user->getName()); + $this->assertEquals($testData['roles'], $user->getRoles()); + $this->assertEquals($testData['timeCreated'], $user->getTimeCreated()); + $this->assertEquals($testData['enabled'], $user->isEnabled()); + $this->assertEquals($testData['isMentee'], $user->isMentee()); + $this->assertEquals($testData['isMentor'], $user->isMentor()); + } +} \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..6b73ace --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,19 @@ + + + + + + + + ./MentoringTest + + + + + ../src + + + + + + diff --git a/tests/run-full-tests.sh b/tests/run-full-tests.sh new file mode 100644 index 0000000..8c8bac7 --- /dev/null +++ b/tests/run-full-tests.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +/var/www/vendor/bin/phpunit --coverage-html=coverage/ +/var/www/vendor/bin/phpcs --standard=PSR2 /var/www/src/ --ignore="*/test/*,autoload_classmap.php,*.js" +# /var/www/vendor/bin/phpmd /var/www/src text phpmd.xml --exclude "*/test/*,*/autoload_classmap.php,*.js"