Skip to content

Commit

Permalink
Merge pull request #4 from ptondereau/lumen-support
Browse files Browse the repository at this point in the history
Improve lib
  • Loading branch information
Lisennk authored May 25, 2017
2 parents 7011b35 + 0b6e5f4 commit ded833f
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text=auto

/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/README.md export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
composer.lock
66 changes: 60 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
language: php

sudo: false

matrix:
include:
- php: 5.5.9
env: LARAVEL_VERSION=5.1.*
- php: 5.5.9
env: LARAVEL_VERSION=5.2.*
- php: 5.5
env: LARAVEL_VERSION=5.1.*
- php: 5.5
env: LARAVEL_VERSION=5.2.*
- php: 5.6
env: LARAVEL_VERSION=5.1.*
- php: 5.6
env: LARAVEL_VERSION=5.2.*
- php: 5.6
env: LARAVEL_VERSION=5.3.*
- php: 5.6
env: LARAVEL_VERSION=5.4.*
- php: 7.0
env: LARAVEL_VERSION=5.1.*
- php: 7.0
env: LARAVEL_VERSION=5.2.*
- php: 7.0
env: LARAVEL_VERSION=5.3.*
- php: 7.0
env: LARAVEL_VERSION=5.4.*
- php: 7.1
env: LARAVEL_VERSION=5.1.*
- php: 7.1
env: LARAVEL_VERSION=5.2.*
- php: 7.1
env: LARAVEL_VERSION=5.3.*
- php: 7.1
env: LARAVEL_VERSION=5.4.*
- php: hhvm
env: LARAVEL_VERSION=5.1.*
- php: hhvm
env: LARAVEL_VERSION=5.2.*
- php: hhvm
env: LARAVEL_VERSION=5.3.*
- php: hhvm
env: LARAVEL_VERSION=5.4.*

before_install:
- if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'hhvm.jit = false' >> /etc/hhvm/php.ini ; fi
- composer self-update --stable -n
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update -n

install:
- composer update
php:
- '5.6'
- '7.0'
- hhvm
- nightly
- travis_retry composer install --no-suggest --prefer-dist -n -o

script:
- if [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then vendor/bin/phpunit; fi
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi

after_script:
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
"description": "Slack Events API for Laravel 5",
"keywords": ["slack", "laravel", "api", "slack api", "slack events api", "events", "slack events"],
"require": {
"illuminate/http": "~5.0",
"illuminate/support": "~5.0",
"illuminate/routing": "~5.0"
"illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*",
"illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*"
},
"require-dev": {
"phpunit/phpunit": "5.5.*",
"phpunit/phpunit": "^4.7|^5.0",
"orchestra/testbench": "~3.0"
},
"autoload": {
"psr-4": {
"Lisennk\\LaravelSlackEvents\\": "src/",
"Lisennk\\LaravelSlackEvents\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lisennk\\LaravelSlackEvents\\Tests\\": "tests/"
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/slackEvents.php → config/slackEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| Your validation token from "App Credentials"
|-------------------------------------------------------------
*/
'token' => 'your-validation-token-here',
'token' => env('SLACK_EVENT_TOKEN', 'your-validation-token-here'),

/*
|-------------------------------------------------------------
Expand Down
27 changes: 24 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
<phpunit bootstrap="vendor/autoload.php">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="events">
<directory>tests</directory>
<testsuite name="Laravel Slack-Events Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
3 changes: 2 additions & 1 deletion src/Events/Base/SlackEvent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Lisennk\LaravelSlackEvents\Events\Base;

use Illuminate\Http\Request;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public function setFromRequest(Request $request)
}

/**
* Sets parameters from arrau
* Sets parameters from array
*
* @param array $data
*/
Expand Down
1 change: 0 additions & 1 deletion src/Http/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Event;
use Lisennk\LaravelSlackEvents\EventCreator;
use Lisennk\LaravelSlackEvents\Events\Base\SlackEvent;
use Lisennk\LaravelSlackEvents\Http\EventMiddleware;

/**
* Class EventController
Expand Down
6 changes: 4 additions & 2 deletions src/Http/EventMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class EventMiddleware
*/
public function handle(Request $request, Closure $next)
{
if ($request->input('token') != config('slackEvents.token'))
if ($request->input('token') !== config('slackEvents.token')) {
return response('Wrong token', 200);
if ($request->input('type') == 'url_verification')
}
if ($request->input('type') === 'url_verification') {
return response($request->input('challenge'), 200);
}

return $next($request);
}
Expand Down
22 changes: 12 additions & 10 deletions src/SlackEventsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Lisennk\LaravelSlackEvents;

use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Request;
use Lisennk\LaravelSlackEvents\EventCreator;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\Lumen\Application as LumenApplication;


/**
* Class SlackApiServiceProvider
Expand All @@ -19,15 +18,18 @@ class SlackEventsServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot(Request $request)
public function boot()
{
$this->publishes([
dirname(__FILE__).'/config/slackEvents.php' => config_path('slackEvents.php'),
]);
$source = dirname(__DIR__).'/config/slackEvents.php';

if (!$this->app->routesAreCached()) {
require dirname(__FILE__).'/Http/routes.php';
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([$source => config_path('slackEvents.php')]);
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('slackEvents');
}
$this->mergeConfigFrom($source, 'slackEvents');

require __DIR__.'/Http/routes.php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testFire()

$response = $controller->fire($request, $creator);

$this->assertTrue($response instanceof Response);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(200, $response->status());
}
}
8 changes: 4 additions & 4 deletions tests/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testWrongToken()
$middleware = new EventMiddleware;
$response = $middleware->handle($request, function($response) {});

$this->assertTrue($response instanceof Response);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(200, $response->status());
$this->assertEquals('Wrong token', $response->content());
}
Expand All @@ -45,8 +45,8 @@ public function testMiddlewarePass()
$request->replace($this->eventRequestData);
$middleware = new EventMiddleware;

$response = $middleware->handle($request, function($request) {
$this->assertTrue($request instanceof Request);
$middleware->handle($request, function($request) {
$this->assertInstanceOf(Request::class, $request);
});
}

Expand All @@ -67,7 +67,7 @@ public function testUrlVerification()
$middleware = new EventMiddleware;
$response = $middleware->handle($request, function($response) {});

$this->assertTrue($response instanceof Response);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(200, $response->status());
$this->assertEquals($data['challenge'], $response->content());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CreatorTest.php → tests/SlackEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testShouldCreateReactionAdded()
$events = new EventCreator();

$event = $events->make('reaction_added');
$this->assertTrue($event instanceof ReactionAdded);
$this->assertInstanceOf(ReactionAdded::class, $event);
}

/**
Expand All @@ -35,7 +35,7 @@ public function testShouldCreateChannelCreated()
$events = new EventCreator();

$event = $events->make('channel_created');
$this->assertTrue($event instanceof ChannelCreated);
$this->assertInstanceOf(ChannelCreated::class, $event);
}

/**
Expand Down

0 comments on commit ded833f

Please sign in to comment.