From c0dafe067fcd24d5df3d7ad51b02c8c598d4bcf7 Mon Sep 17 00:00:00 2001 From: Jimmy Puckett Date: Sat, 8 Jul 2017 21:49:28 -0400 Subject: [PATCH] Stubbing out the project --- .editorconfig | 16 ++++++ .gitattributes | 10 ++++ .gitignore | 5 ++ .travis.yml | 45 ++++++++++++++++ VERSION | 1 + composer.json | 53 ++++++++++++++++++ gulpfile.js | 25 +++++++++ nitpick.json | 5 ++ phpunit.xml.dist | 58 ++++++++++++++++++++ readme.md | 55 +++++++++++++++++++ src/SsoServiceProvider.php | 33 ++++++++++++ tests/SsoServiceProviderTest.php | 74 +++++++++++++++++++++++++ tests/TestCase.php | 92 ++++++++++++++++++++++++++++++++ 13 files changed, 472 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 VERSION create mode 100644 composer.json create mode 100644 gulpfile.js create mode 100644 nitpick.json create mode 100644 phpunit.xml.dist create mode 100644 readme.md create mode 100644 src/SsoServiceProvider.php create mode 100644 tests/SsoServiceProviderTest.php create mode 100644 tests/TestCase.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1492202 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..42ac8b2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +* text=auto + +/build export-ignore +/tests export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +gulpfile.js +nitpick.json export-ignore +phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6d68db --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor +/node_modules +phpunit.xml +/build +composer.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e3bfd84 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,45 @@ +language: php + +php: + - 5.5.9 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + +env: + global: + - setup=basic + +matrix: + include: + - php: 7.0 + env: setup=lowest + - php: 7.0 + env: setup=stable + - php: 7.1 + env: setup=lowest + - php: 7.1 + env: setup=stable + +sudo: false + +cache: + directories: + - $HOME/.composer/cache + +before_install: + - phpenv config-rm xdebug.ini + - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - travis_retry composer self-update + +install: + - 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 + +before_script: mkdir -p build/logs + +script: vendor/bin/phpunit + +after_script: vendor/bin/coveralls -v -n diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..77d6f4c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.0 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2757d4b --- /dev/null +++ b/composer.json @@ -0,0 +1,53 @@ +{ + "name": "spinen/laravel-discourse-sso", + "description": "Integrate Discourse SSO into Laravel.", + "keywords": [ + "discourse", + "laravel", + "library", + "single sign on", + "spinen", + "sso" + ], + "license": "MIT", + "authors": [ + { + "name": "Jimmy Puckett", + "email": "jimmy.puckett@spinen.com" + } + ], + "require": { + "php": ">=5.5.9", + "cviebrock/discourse-php": "^0.9.3", + "illuminate/support": "~5.1.10|5.2.*|5.3.*|5.4.*" + }, + "require-dev": { + "mockery/mockery": "^0.9.1", + "phpunit/phpunit": "~4.0|~5.0", + "psy/psysh": "^0.5.1", + "satooshi/php-coveralls": "^0.6.1|^1", + "symfony/var-dumper": "~2.7|~3.0" + }, + "autoload": { + "psr-4": { + "Spinen\\Discourse\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Spinen\\Discourse\\": "tests" + } + }, + "extra": { + "laravel": { + "providers": [ + "Spinen\\Discourse\\SsoServiceProvider" + ], + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..1a5893d --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,25 @@ +var gulp = require('gulp'); +var phpunit = require('gulp-phpunit'); +var notify = require('gulp-notify') + +var paths = { + tests: ['tests/**/*Test.php'], +}; + +// Lint the shell code +gulp.task('phpunit', function () { + return gulp.src(paths.tests, {read: false}) + .pipe(phpunit()) + .pipe(notify(function (file) { + // TODO: Give alert of pass/fail + return file.path + })) +}) + +// Rerun the task when a file changes +gulp.task('watch', function() { + gulp.watch(paths.tests, ['phpunit']); +}); + +// The default task (called when you run `gulp` from cli) +gulp.task('default', ['phpunit']); diff --git a/nitpick.json b/nitpick.json new file mode 100644 index 0000000..3881d8d --- /dev/null +++ b/nitpick.json @@ -0,0 +1,5 @@ +{ + "ignore": [ + "tests/*" + ] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a698d71 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,58 @@ + + + + + + + + + ./tests/ + + + + + + + + + + src/ + + + src/config + + + + + + + + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..050c093 --- /dev/null +++ b/readme.md @@ -0,0 +1,55 @@ +# SPINEN's Discourse SSO for Laravel + +[![Latest Stable Version](https://poser.pugx.org/spinen/laravel-discourse-sso/v/stable)](https://packagist.org/packages/spinen/laravel-discourse-sso) +[![Total Downloads](https://poser.pugx.org/spinen/laravel-discourse-sso/downloads)](https://packagist.org/packages/spinen/laravel-discourse-sso) +[![Latest Unstable Version](https://poser.pugx.org/spinen/laravel-discourse-sso/v/unstable)](https://packagist.org/packages/spinen/laravel-discourse-sso) +[![Dependency Status](https://www.versioneye.com/php/spinen:laravel-discourse-sso/0.1.1/badge.svg)](https://www.versioneye.com/php/spinen:laravel-discourse-sso/0.1.1) +[![License](https://poser.pugx.org/spinen/laravel-discourse-sso/license)](https://packagist.org/packages/spinen/laravel-discourse-sso) + +[Discourse](https://www.discourse.org) is a great online forum software that supports Single Sign On ([SSO](https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045)). There is a great PHP library that handles all of the heavy lifting to make the SSO work called [cviebrock/discourse-php](https://github.com/cviebrock/discourse-php), which this package uses. This package is loosely based on the work done by [jaewun/discourse-sso-laravel](https://github.com/jaewun/discourse-sso-laravel). + +## Build Status + +| Branch | Status | Coverage | Code Quality | +| ------ | :----: | :------: | :----------: | +| Develop | [![Build Status](https://travis-ci.org/spinen/laravel-discourse-sso.svg?branch=develop)](https://travis-ci.org/spinen/laravel-discourse-sso) | [![Coverage Status](https://coveralls.io/repos/spinen/laravel-discourse-sso/badge.svg?branch=develop&service=github)](https://coveralls.io/github/spinen/laravel-discourse-sso?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=develop) | +| Master | [![Build Status](https://travis-ci.org/spinen/laravel-discourse-sso.svg?branch=master)](https://travis-ci.org/spinen/laravel-discourse-sso) | [![Coverage Status](https://coveralls.io/repos/spinen/laravel-discourse-sso/badge.svg?branch=master&service=github)](https://coveralls.io/github/spinen/laravel-discourse-sso?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=master) | + +## Prerequisite + +As side from Laravel >= 5.1, there is 1 package that is required. + +* ["cviebrock/discourse-php": "^0.9.3",](https://github.com/briannesbitt/Carbon) + +## Install + +Install Discourse SSO for Laravel: + +```bash + $ composer require spinen/laravel-discourse-sso +``` + +### For >= Laravel 5.5, you are done with the Install + +The package uses the auto registration feature + +### For < Laravel 5.5, you have to register the Service Provider + +Add the Service Provider to `config/app.php`: + +```php + 'providers' => [ + // ... + Spinen\Discourse\SsoServiceProvider::class, + ]; +``` + +## Configuration + +All of the configuration values are stored in under a `discourse` key in `config/services.php`. Here is the array to add... + +TODO: Put all of the config stuff here + +## Using the package + +TODO: Fill this in diff --git a/src/SsoServiceProvider.php b/src/SsoServiceProvider.php new file mode 100644 index 0000000..bad76d1 --- /dev/null +++ b/src/SsoServiceProvider.php @@ -0,0 +1,33 @@ +setUpMocks(); + + $this->service_provider = new SsoServiceProvider($this->application_mock); + } + + private function setUpMocks() + { + $this->events_mock = Mockery::mock(Events::class); + $this->events_mock->shouldReceive('listen') + ->withAnyArgs() + ->andReturnNull(); + + $this->application_mock = Mockery::mock(Application::class); + $this->application_mock->shouldReceive('offsetGet') + ->zeroOrMoreTimes() + ->with('events') + ->andReturn($this->events_mock); + + $this->purge_command_mock = Mockery::mock(PurgeCommand::class); + } + + /** + * @test + * @group unit + */ + public function it_can_be_constructed() + { + $this->assertInstanceOf(SsoServiceProvider::class, $this->service_provider); + } + + /** + * @test + * @group unit + */ + public function it_boots_the_service() + { + $this->assertNull($this->service_provider->boot()); + // NOTE: It would be nice to verify that the config got set. + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..227e520 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,92 @@ + $val) { + $mock->shouldReceive('offsetGet') + ->with($key) + ->andReturn($val); + + $mock->shouldReceive('offsetExists') + ->with($key) + ->andReturn(true); + } + + $mock->shouldReceive('offsetExists') + ->andReturn(false); + } + + if ($mock instanceof Iterator) { + $counter = 0; + + $mock->shouldReceive('rewind') + ->andReturnUsing(function () use (& $counter) { + $counter = 0; + }); + + $vals = array_values($items); + $keys = array_values(array_keys($items)); + + $mock->shouldReceive('valid') + ->andReturnUsing(function () use (& $counter, $vals) { + return isset($vals[$counter]); + }); + + $mock->shouldReceive('current') + ->andReturnUsing(function () use (& $counter, $vals) { + return $vals[$counter]; + }); + + $mock->shouldReceive('key') + ->andReturnUsing(function () use (& $counter, $keys) { + return $keys[$counter]; + }); + + $mock->shouldReceive('next') + ->andReturnUsing(function () use (& $counter) { + ++ $counter; + }); + } + + if ($mock instanceof Countable) { + $mock->shouldReceive('count') + ->andReturn(count($items)); + } + } +}