diff --git a/.arclint b/.arclint --- a/.arclint +++ b/.arclint @@ -28,8 +28,12 @@ "phpcs": { "type": "phpcs", "bin": "vendor/bin/phpcs", - "phpcs.standard": "PSR1", - "include": "(^app/.*\\.php$)" + "phpcs.standard": "phpcs.xml", + "include": [ + "(app/.*\\.php$)", + "(config/.*\\.php$)", + "(tests/.*\\.php$)" + ] }, "spelling": { "type": "spelling" diff --git a/app/Analyzers/BasePayloadAnalyzer.php b/app/Analyzers/BasePayloadAnalyzer.php --- a/app/Analyzers/BasePayloadAnalyzer.php +++ b/app/Analyzers/BasePayloadAnalyzer.php @@ -2,10 +2,9 @@ namespace Nasqueron\Notifications\Analyzers; -use Config; -use Storage; - use BadMethodCallException; +use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Storage; abstract class BasePayloadAnalyzer { @@ -36,7 +35,7 @@ /** * The configuration for the payload analyzer - * @var PayloadAnalyzerConfiguration; + * @var PayloadAnalyzerConfiguration */ protected $configuration; @@ -80,7 +79,7 @@ $filename = $dir . '/' . $this->project . '.json'; - if (!Storage::has($filename)) { + if (!Storage::exists($filename)) { return $dir . '/' . static::CONFIG_DEFAULT_FILE; } diff --git a/app/Analyzers/DockerHub/BuildFailureEvent.php b/app/Analyzers/DockerHub/BuildFailureEvent.php --- a/app/Analyzers/DockerHub/BuildFailureEvent.php +++ b/app/Analyzers/DockerHub/BuildFailureEvent.php @@ -2,7 +2,7 @@ namespace Nasqueron\Notifications\Analyzers\DockerHub; -use Mailgun; +use Nasqueron\Notifications\Facades\Mailgun; class BuildFailureEvent extends BaseEvent { diff --git a/app/Analyzers/GitHub/Events/Event.php b/app/Analyzers/GitHub/Events/Event.php --- a/app/Analyzers/GitHub/Events/Event.php +++ b/app/Analyzers/GitHub/Events/Event.php @@ -33,8 +33,12 @@ * @param string $eventName The event name (e.g. commit_comment) * @return string The event class name (e.g. CommitCommentEvent) */ - public static function getClass ($eventName) { - return __NAMESPACE__ . '\\' . studly_case($eventName) . 'Event'; + public static function getClass (string $eventName) { + return __NAMESPACE__ . '\\' . self::toCamelCase($eventName) . 'Event'; + } + + private static function toCamelCase (string $string) : string { + return str_replace(" ", "", ucwords(str_replace("_", " ", $string))); } /** @@ -43,7 +47,7 @@ * @param string $eventName The event name (e.g. commit_comment) * @return Event */ - public static function forPayload ($eventName, $payload) { + public static function forPayload (string $eventName, $payload) { $class = self::getClass($eventName); if (!class_exists($class)) { throw new \InvalidArgumentException( @@ -60,11 +64,15 @@ /** * Cuts a text * - * @param string $text The text to cut - * @param int $strLen The amount of characters to allow [optional] + * @param string $text The text to cut + * @param int $strLen The amount of characters to allow [optional] * @param string $symbol The symbol to append to a cut text [optional] */ - public static function cut ($text, $strLen = 114, $symbol = '…') { + public static function cut ( + string $text, + int $strLen = 114, + string $symbol = '…' + ) { $len = strlen($text); if ($len <= $strLen) { return $text; diff --git a/app/Analyzers/GitHub/Events/IssueCommentEvent.php b/app/Analyzers/GitHub/Events/IssueCommentEvent.php --- a/app/Analyzers/GitHub/Events/IssueCommentEvent.php +++ b/app/Analyzers/GitHub/Events/IssueCommentEvent.php @@ -15,7 +15,7 @@ * @param string $action The action to check * @return bool true if the action is valid; otherwise, false */ - protected static function isValidAction ($action) { + protected static function isValidAction (string $action) { $actions = ['created', 'edited', 'deleted']; return in_array($action, $actions); } @@ -62,4 +62,3 @@ } } - diff --git a/app/Analyzers/GitHub/Events/PullRequestEvent.php b/app/Analyzers/GitHub/Events/PullRequestEvent.php --- a/app/Analyzers/GitHub/Events/PullRequestEvent.php +++ b/app/Analyzers/GitHub/Events/PullRequestEvent.php @@ -15,7 +15,7 @@ * @param string $action The action to check * @return bool true if the action is valid; otherwise, false */ - protected static function isValidAction ($action) { + protected static function isValidAction(string $action) { $actions = [ 'assigned', 'unassigned', 'labeled', 'unlabeled', diff --git a/app/Analyzers/GitHub/Events/PushEvent.php b/app/Analyzers/GitHub/Events/PushEvent.php --- a/app/Analyzers/GitHub/Events/PushEvent.php +++ b/app/Analyzers/GitHub/Events/PushEvent.php @@ -18,7 +18,7 @@ * @param int $count The count of commits * @return string The l10n message key for description */ - private static function getDescriptionMessageKey ($count) { + private static function getDescriptionMessageKey (int $count) { $key = 'GitHub.EventsDescriptions.PushEvent'; if ($count === 0) { diff --git a/app/Analyzers/GitHub/Events/WithRef.php b/app/Analyzers/GitHub/Events/WithRef.php --- a/app/Analyzers/GitHub/Events/WithRef.php +++ b/app/Analyzers/GitHub/Events/WithRef.php @@ -19,7 +19,7 @@ * @param string $type The ref type to check * @return bool true if the ref type id valid; otherwise, false */ - protected static function isValidRefType ($type) { + protected static function isValidRefType (string $type) { $types = ['branch', 'tag']; return in_array($type, $types); } @@ -30,7 +30,7 @@ * @param string $type The reference type * @return string the part of the URL for this reference type (e.g. /tree/) */ - protected function getLinkRefSegment ($type) { + protected function getLinkRefSegment (string $type) { $segments = $this->getLinkRefSegments(); if (!array_key_exists($type, $segments)) { diff --git a/app/Analyzers/GitHub/Events/WithRepoAndBranch.php b/app/Analyzers/GitHub/Events/WithRepoAndBranch.php --- a/app/Analyzers/GitHub/Events/WithRepoAndBranch.php +++ b/app/Analyzers/GitHub/Events/WithRepoAndBranch.php @@ -28,7 +28,7 @@ return ""; } - if (starts_with($branch, "refs/heads/")) { + if (str_starts_with($branch, "refs/heads/")) { $branch = substr($branch, 11); } diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php --- a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php +++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php @@ -26,7 +26,7 @@ /** * The payload analyzer event * - * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\Event; + * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\Event */ private $analyzerEvent; diff --git a/app/Analyzers/ItemGroupMapping.php b/app/Analyzers/ItemGroupMapping.php --- a/app/Analyzers/ItemGroupMapping.php +++ b/app/Analyzers/ItemGroupMapping.php @@ -2,6 +2,8 @@ namespace Nasqueron\Notifications\Analyzers; +use Illuminate\Support\Str; + /** * Map items (repositories, projects, items, etc.) names to groups */ @@ -42,7 +44,7 @@ string $pattern, string $item ) : bool { - return str_is($pattern, $item); + return Str::is($pattern, $item); } /** diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php --- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php +++ b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php @@ -31,7 +31,7 @@ /** * Tries to get build status. * - * @param out string $status + * @param out string &$status * @return bool indicates if the build status is defined in the payload */ private function tryGetBuildStatus (string &$status) : bool { diff --git a/app/Config/Features.php b/app/Config/Features.php --- a/app/Config/Features.php +++ b/app/Config/Features.php @@ -2,7 +2,7 @@ namespace Nasqueron\Notifications\Config; -use Config; +use Illuminate\Support\Facades\Config; /** * The features class offers a sugar syntax to check if a feature is enabled diff --git a/app/Config/Reporting/ConfigReport.php b/app/Config/Reporting/ConfigReport.php --- a/app/Config/Reporting/ConfigReport.php +++ b/app/Config/Reporting/ConfigReport.php @@ -4,8 +4,8 @@ use Nasqueron\Notifications\Config\Features; -use Config; -use Services; +use Nasqueron\Notifications\Facades\Services; +use Illuminate\Support\Facades\Config; class ConfigReport { diff --git a/app/Config/Reporting/ServiceReportEntry.php b/app/Config/Reporting/ServiceReportEntry.php --- a/app/Config/Reporting/ServiceReportEntry.php +++ b/app/Config/Reporting/ServiceReportEntry.php @@ -4,7 +4,7 @@ use Nasqueron\Notifications\Config\Services\Service; -use ProjectsMap; +use Nasqueron\Notifications\Facades\ProjectsMap; final class ServiceReportEntry extends BaseReportEntry { diff --git a/app/Config/Services/Services.php b/app/Config/Services/Services.php --- a/app/Config/Services/Services.php +++ b/app/Config/Services/Services.php @@ -2,7 +2,7 @@ namespace Nasqueron\Notifications\Config\Services; -use Storage; +use Illuminate\Support\Facades\Storage; class Services { diff --git a/app/Console/Commands/ConfigValidate.php b/app/Console/Commands/ConfigValidate.php --- a/app/Console/Commands/ConfigValidate.php +++ b/app/Console/Commands/ConfigValidate.php @@ -4,8 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\FilesystemAdapter; - -use App; +use Illuminate\Support\Facades\App; class ConfigValidate extends Command { diff --git a/app/Console/Commands/PhabricatorProjectsMap.php b/app/Console/Commands/PhabricatorProjectsMap.php --- a/app/Console/Commands/PhabricatorProjectsMap.php +++ b/app/Console/Commands/PhabricatorProjectsMap.php @@ -4,8 +4,8 @@ use Illuminate\Console\Command; -use ProjectsMap; -use Services; +use Nasqueron\Notifications\Facades\ProjectsMap; +use Nasqueron\Notifications\Facades\Services; class PhabricatorProjectsMap extends Command { /** diff --git a/app/Contracts/APIClient.php b/app/Contracts/APIClient.php --- a/app/Contracts/APIClient.php +++ b/app/Contracts/APIClient.php @@ -10,7 +10,7 @@ * @param string $url The API end point URL * @return void */ - public function setEndPoint ($url); + public function setEndPoint (string $url); /** * Calls an API method @@ -19,6 +19,6 @@ * @param array $arguments The arguments to use * @return mixed The API result */ - public function call ($method, $arguments = []); + public function call (string $method, array $arguments = []); } diff --git a/app/Contracts/APIFactory.php b/app/Contracts/APIFactory.php --- a/app/Contracts/APIFactory.php +++ b/app/Contracts/APIFactory.php @@ -10,6 +10,6 @@ * @param string $endPoint The API end point * @return APIClient */ - public function get ($endPoint); + public function get (string $endPoint); } diff --git a/app/Events/DockerHubPayloadEvent.php b/app/Events/DockerHubPayloadEvent.php --- a/app/Events/DockerHubPayloadEvent.php +++ b/app/Events/DockerHubPayloadEvent.php @@ -2,7 +2,6 @@ namespace Nasqueron\Notifications\Events; -use Nasqueron\Notifications\Events\Event; use Illuminate\Queue\SerializesModels; class DockerHubPayloadEvent extends Event { diff --git a/app/Events/GitHubPayloadEvent.php b/app/Events/GitHubPayloadEvent.php --- a/app/Events/GitHubPayloadEvent.php +++ b/app/Events/GitHubPayloadEvent.php @@ -2,7 +2,6 @@ namespace Nasqueron\Notifications\Events; -use Nasqueron\Notifications\Events\Event; use Illuminate\Queue\SerializesModels; class GitHubPayloadEvent extends Event { diff --git a/app/Events/JenkinsPayloadEvent.php b/app/Events/JenkinsPayloadEvent.php --- a/app/Events/JenkinsPayloadEvent.php +++ b/app/Events/JenkinsPayloadEvent.php @@ -2,7 +2,6 @@ namespace Nasqueron\Notifications\Events; -use Nasqueron\Notifications\Events\Event; use Illuminate\Queue\SerializesModels; class JenkinsPayloadEvent extends Event { diff --git a/app/Events/NotificationEvent.php b/app/Events/NotificationEvent.php --- a/app/Events/NotificationEvent.php +++ b/app/Events/NotificationEvent.php @@ -2,7 +2,6 @@ namespace Nasqueron\Notifications\Events; -use Nasqueron\Notifications\Events\Event; use Nasqueron\Notifications\Notifications\Notification; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/PhabricatorPayloadEvent.php b/app/Events/PhabricatorPayloadEvent.php --- a/app/Events/PhabricatorPayloadEvent.php +++ b/app/Events/PhabricatorPayloadEvent.php @@ -2,8 +2,8 @@ namespace Nasqueron\Notifications\Events; -use Nasqueron\Notifications\Events\Event; use Nasqueron\Notifications\Phabricator\PhabricatorStory; + use Illuminate\Queue\SerializesModels; class PhabricatorPayloadEvent extends Event { diff --git a/app/Events/ReportEvent.php b/app/Events/ReportEvent.php --- a/app/Events/ReportEvent.php +++ b/app/Events/ReportEvent.php @@ -3,7 +3,7 @@ namespace Nasqueron\Notifications\Events; use Nasqueron\Notifications\Actions\Action; -use Nasqueron\Notifications\Events\Event; + use Illuminate\Queue\SerializesModels; class ReportEvent extends Event { diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,19 +2,18 @@ namespace Nasqueron\Notifications\Exceptions; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Nasqueron\Notifications\Facades\Raven; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Foundation\Validation\ValidationException; +use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; use Illuminate\Session\TokenMismatchException; +use Illuminate\Support\Facades\Config; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\HttpKernel\Exception\HttpException; -use Config; -use Raven; - use Exception; class Handler extends ExceptionHandler { @@ -38,9 +37,11 @@ * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $e + * @param \Exception|\Throwable $e + * + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function report(Exception $e) : void { + public function report(Exception|\Throwable $e) : void { if (!$this->shouldReport($e)) { return; } diff --git a/app/Facades/Raven.php b/app/Facades/Raven.php --- a/app/Facades/Raven.php +++ b/app/Facades/Raven.php @@ -2,10 +2,9 @@ namespace Nasqueron\Notifications\Facades; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Facade; -use Config; - /** * @see \Raven_Client */ diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,12 +2,14 @@ namespace Nasqueron\Notifications\Http\Controllers; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Routing\Controller as BaseController; abstract class Controller extends BaseController { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + use AuthorizesRequests; + use DispatchesJobs; + use ValidatesRequests; } diff --git a/app/Http/Controllers/Gate/DockerHubGateController.php b/app/Http/Controllers/Gate/DockerHubGateController.php --- a/app/Http/Controllers/Gate/DockerHubGateController.php +++ b/app/Http/Controllers/Gate/DockerHubGateController.php @@ -4,11 +4,10 @@ use Nasqueron\Notifications\Events\DockerHubPayloadEvent; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Request; use Symfony\Component\HttpFoundation\Response; -use Event; -use Request; - class DockerHubGateController extends GateController { /// @@ -75,7 +74,7 @@ protected function onPayload () : void { $this->initializeReport(); - Event::fire(new DockerHubPayloadEvent( + Event::dispatch(new DockerHubPayloadEvent( $this->door, $this->payload )); diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php --- a/app/Http/Controllers/Gate/GateController.php +++ b/app/Http/Controllers/Gate/GateController.php @@ -4,16 +4,15 @@ use Nasqueron\Notifications\Config\Features; use Nasqueron\Notifications\Config\Services\Service; +use Nasqueron\Notifications\Facades\Services; +use Nasqueron\Notifications\Facades\Report; use Nasqueron\Notifications\Http\Controllers\Controller; -use Symfony\Component\HttpFoundation\Response as BaseResponse; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Response; use Illuminate\View\View; - -use App; -use Log; -use Report; -use Response; -use Services; +use Symfony\Component\HttpFoundation\Response as BaseResponse; /** * Represents a controller handling an entry-point for API payloads diff --git a/app/Http/Controllers/Gate/GitHubGateController.php b/app/Http/Controllers/Gate/GitHubGateController.php --- a/app/Http/Controllers/Gate/GitHubGateController.php +++ b/app/Http/Controllers/Gate/GitHubGateController.php @@ -5,10 +5,10 @@ use Nasqueron\Notifications\Events\GitHubPayloadEvent; use Keruald\GitHub\XHubSignature; -use Symfony\Component\HttpFoundation\Response; -use Event; -use Request; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Request; +use Symfony\Component\HttpFoundation\Response; class GitHubGateController extends GateController { @@ -180,7 +180,7 @@ protected function onPayload () { $this->initializeReport(); - Event::fire(new GitHubPayloadEvent( + Event::dispatch(new GitHubPayloadEvent( $this->door, $this->event, $this->payload diff --git a/app/Http/Controllers/Gate/JenkinsGateController.php b/app/Http/Controllers/Gate/JenkinsGateController.php --- a/app/Http/Controllers/Gate/JenkinsGateController.php +++ b/app/Http/Controllers/Gate/JenkinsGateController.php @@ -4,11 +4,10 @@ use Nasqueron\Notifications\Events\JenkinsPayloadEvent; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Request; use Symfony\Component\HttpFoundation\Response; -use Event; -use Request; - class JenkinsGateController extends GateController { /// @@ -75,7 +74,7 @@ protected function onPayload () { $this->initializeReport(); - Event::fire(new JenkinsPayloadEvent( + Event::dispatch(new JenkinsPayloadEvent( $this->door, $this->payload )); diff --git a/app/Http/Controllers/Gate/NotificationGateController.php b/app/Http/Controllers/Gate/NotificationGateController.php --- a/app/Http/Controllers/Gate/NotificationGateController.php +++ b/app/Http/Controllers/Gate/NotificationGateController.php @@ -5,12 +5,10 @@ use Nasqueron\Notifications\Events\NotificationEvent; use Nasqueron\Notifications\Notifications\Notification; -use Symfony\Component\HttpFoundation\Response; - -use Event; -use Request; - +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Request; use InvalidArgumentException; +use Symfony\Component\HttpFoundation\Response; class NotificationGateController extends GateController { @@ -88,10 +86,10 @@ } $mapper = new \JsonMapper(); - return (Notification)($mapper->map( + return $mapper->map( $payload, new Notification - )); + ); } private function normalizePayload () : void { @@ -133,7 +131,7 @@ protected function onPayload () { $this->initializeReport(); - Event::fire(new NotificationEvent($this->payload)); + Event::dispatch(new NotificationEvent($this->payload)); } } diff --git a/app/Http/Controllers/Gate/PhabricatorGateController.php b/app/Http/Controllers/Gate/PhabricatorGateController.php --- a/app/Http/Controllers/Gate/PhabricatorGateController.php +++ b/app/Http/Controllers/Gate/PhabricatorGateController.php @@ -4,11 +4,10 @@ use Nasqueron\Notifications\Events\PhabricatorPayloadEvent; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Request; use Symfony\Component\HttpFoundation\Response; -use Event; -use Request; - class PhabricatorGateController extends GateController { /// @@ -65,7 +64,7 @@ protected function onPayload () : void { $this->initializeReport(); - Event::fire(new PhabricatorPayloadEvent( + Event::dispatch(new PhabricatorPayloadEvent( $this->door, $this->payload )); diff --git a/app/Http/routes.php b/app/Http/routes.php --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -3,6 +3,10 @@ use Nasqueron\Notifications\Config\Features; use Nasqueron\Notifications\Config\Reporting\ConfigReport; +use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Response; +use Illuminate\Support\Facades\Route; + /* |-------------------------------------------------------------------------- | Application Routes diff --git a/app/Jobs/FireDockerHubNotification.php b/app/Jobs/FireDockerHubNotification.php --- a/app/Jobs/FireDockerHubNotification.php +++ b/app/Jobs/FireDockerHubNotification.php @@ -2,17 +2,16 @@ namespace Nasqueron\Notifications\Jobs; -use Nasqueron\Notifications\Notifications\DockerHubNotification; use Nasqueron\Notifications\Events\DockerHubPayloadEvent; use Nasqueron\Notifications\Events\NotificationEvent; -use Nasqueron\Notifications\Jobs\Job; +use Nasqueron\Notifications\Notifications\DockerHubNotification; -use Event; +use Illuminate\Support\Facades\Event; class FireDockerHubNotification extends Job { /** - * @var DockerHubPayloadEvent; + * @var DockerHubPayloadEvent */ private $event; @@ -34,7 +33,7 @@ */ public function handle() : void { $notification = $this->createNotification(); - Event::fire(new NotificationEvent($notification)); + Event::dispatch(new NotificationEvent($notification)); } protected function createNotification() : DockerHubNotification { diff --git a/app/Jobs/FireGitHubNotification.php b/app/Jobs/FireGitHubNotification.php --- a/app/Jobs/FireGitHubNotification.php +++ b/app/Jobs/FireGitHubNotification.php @@ -2,17 +2,16 @@ namespace Nasqueron\Notifications\Jobs; -use Nasqueron\Notifications\Notifications\GitHubNotification; use Nasqueron\Notifications\Events\GitHubPayloadEvent; use Nasqueron\Notifications\Events\NotificationEvent; -use Nasqueron\Notifications\Jobs\Job; +use Nasqueron\Notifications\Notifications\GitHubNotification; -use Event; +use Illuminate\Support\Facades\Event; class FireGitHubNotification extends Job { /** - * @var GitHubPayloadEvent; + * @var GitHubPayloadEvent */ private $event; @@ -34,7 +33,7 @@ */ public function handle() : void { $notification = $this->createNotification(); - Event::fire(new NotificationEvent($notification)); + Event::dispatch(new NotificationEvent($notification)); } diff --git a/app/Jobs/FireJenkinsNotification.php b/app/Jobs/FireJenkinsNotification.php --- a/app/Jobs/FireJenkinsNotification.php +++ b/app/Jobs/FireJenkinsNotification.php @@ -2,17 +2,16 @@ namespace Nasqueron\Notifications\Jobs; -use Nasqueron\Notifications\Notifications\JenkinsNotification; use Nasqueron\Notifications\Events\JenkinsPayloadEvent; use Nasqueron\Notifications\Events\NotificationEvent; -use Nasqueron\Notifications\Jobs\Job; +use Nasqueron\Notifications\Notifications\JenkinsNotification; -use Event; +use Illuminate\Support\Facades\Event; class FireJenkinsNotification extends Job { /** - * @var JenkinsPayloadEvent; + * @var JenkinsPayloadEvent */ private $event; @@ -37,7 +36,7 @@ public function handle() : void { $notification = $this->createNotification(); if ($notification->shouldNotify()) { - Event::fire(new NotificationEvent($notification)); + Event::dispatch(new NotificationEvent($notification)); } } diff --git a/app/Jobs/FirePhabricatorNotification.php b/app/Jobs/FirePhabricatorNotification.php --- a/app/Jobs/FirePhabricatorNotification.php +++ b/app/Jobs/FirePhabricatorNotification.php @@ -2,17 +2,16 @@ namespace Nasqueron\Notifications\Jobs; -use Nasqueron\Notifications\Notifications\PhabricatorNotification; -use Nasqueron\Notifications\Events\PhabricatorPayloadEvent; use Nasqueron\Notifications\Events\NotificationEvent; -use Nasqueron\Notifications\Jobs\Job; +use Nasqueron\Notifications\Events\PhabricatorPayloadEvent; +use Nasqueron\Notifications\Notifications\PhabricatorNotification; -use Event; +use Illuminate\Support\Facades\Event; class FirePhabricatorNotification extends Job { /** - * @var PhabricatorPayloadEvent; + * @var PhabricatorPayloadEvent */ private $event; @@ -34,7 +33,7 @@ */ public function handle() : void { $notification = $this->createNotification(); - Event::fire(new NotificationEvent($notification)); + Event::dispatch(new NotificationEvent($notification)); } protected function createNotification() : PhabricatorNotification { diff --git a/app/Jobs/NotifyNewCommitsToDiffusion.php b/app/Jobs/NotifyNewCommitsToDiffusion.php --- a/app/Jobs/NotifyNewCommitsToDiffusion.php +++ b/app/Jobs/NotifyNewCommitsToDiffusion.php @@ -5,13 +5,12 @@ use Nasqueron\Notifications\Actions\ActionError; use Nasqueron\Notifications\Actions\NotifyNewCommitsAction; use Nasqueron\Notifications\Events\ReportEvent; +use Nasqueron\Notifications\Facades\PhabricatorAPI; use Nasqueron\Notifications\Phabricator\PhabricatorAPI as API; use Nasqueron\Notifications\Phabricator\PhabricatorAPIException; -use Event; -use Log; -use PhabricatorAPI; - +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Log; use RuntimeException; /** @@ -107,7 +106,7 @@ */ private function sendReport () : void { $event = new ReportEvent($this->actionToReport); - Event::fire($event); + Event::dispatch($event); } diff --git a/app/Jobs/SendMessageToBroker.php b/app/Jobs/SendMessageToBroker.php --- a/app/Jobs/SendMessageToBroker.php +++ b/app/Jobs/SendMessageToBroker.php @@ -5,11 +5,10 @@ use Nasqueron\Notifications\Actions\ActionError; use Nasqueron\Notifications\Actions\AMQPAction; use Nasqueron\Notifications\Events\ReportEvent; -use Nasqueron\Notifications\Jobs\Job; +use Nasqueron\Notifications\Facades\Broker; -use Broker; -use Event; -use Log; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Log; class SendMessageToBroker extends Job { @@ -108,6 +107,6 @@ if ($this->exception !== null) { $actionToReport->attachError(new ActionError($this->exception)); } - Event::fire(new ReportEvent($actionToReport)); + Event::dispatch(new ReportEvent($actionToReport)); } } diff --git a/app/Jobs/TriggerDockerHubBuild.php b/app/Jobs/TriggerDockerHubBuild.php --- a/app/Jobs/TriggerDockerHubBuild.php +++ b/app/Jobs/TriggerDockerHubBuild.php @@ -5,11 +5,10 @@ use Nasqueron\Notifications\Actions\ActionError; use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction; use Nasqueron\Notifications\Events\ReportEvent; - -use DockerHub; -use Event; +use Nasqueron\Notifications\Facades\DockerHub; use Exception; +use Illuminate\Support\Facades\Event; /** * This class allows to trigger a new Docker Hub build. @@ -80,7 +79,7 @@ */ private function sendReport () : void { $event = new ReportEvent($this->actionToReport); - Event::fire($event); + Event::dispatch($event); } } diff --git a/app/Listeners/AMQPEventListener.php b/app/Listeners/AMQPEventListener.php --- a/app/Listeners/AMQPEventListener.php +++ b/app/Listeners/AMQPEventListener.php @@ -6,9 +6,7 @@ use Nasqueron\Notifications\Jobs\SendMessageToBroker; use Nasqueron\Notifications\Notifications\Notification; -use Illuminate\Events\Dispatcher; - -use Config; +use Illuminate\Support\Facades\Config; class AMQPEventListener { @@ -21,7 +19,7 @@ * * @param NotificationEvent $event */ - public function onNotification(NotificationEvent $event) : void { + public function handle (NotificationEvent $event) : void { $this->sendNotification($event->notification); } @@ -51,22 +49,4 @@ $job = new SendMessageToBroker($target, $routingKey, $message); $job->handle(); } - - /// - /// Events listening - /// - - /** - * Registers the listeners for the subscriber. - * - * @param Dispatcher $events - */ - public function subscribe (Dispatcher $events) : void { - $class = AMQPEventListener::class; - $events->listen( - NotificationEvent::class, - "$class@onNotification" - ); - } - } diff --git a/app/Listeners/DockerHubListener.php b/app/Listeners/DockerHubListener.php --- a/app/Listeners/DockerHubListener.php +++ b/app/Listeners/DockerHubListener.php @@ -3,12 +3,9 @@ namespace Nasqueron\Notifications\Listeners; use Nasqueron\Notifications\Events\GitHubPayloadEvent; +use Nasqueron\Notifications\Facades\DockerHub; use Nasqueron\Notifications\Jobs\TriggerDockerHubBuild; -use Illuminate\Events\Dispatcher; - -use DockerHub; - /** * Listens to events Docker Hub is interested by. */ @@ -23,7 +20,7 @@ * * @param GitHubPayloadEvent $event The GitHub payload event */ - public function onGitHubPayload (GitHubPayloadEvent $event) : void { + public function handle (GitHubPayloadEvent $event) : void { if ($this->shouldNotify($event)) { $this->notifyNewCommits($event); } @@ -60,22 +57,4 @@ private function getRepository (GitHubPayloadEvent $event) : string { return $event->payload->repository->full_name; } - - /// - /// Events listening - /// - - /** - * Registers the listeners for the subscriber. - * - * @param Dispatcher $events - */ - public function subscribe (Dispatcher $events) : void { - $class = DockerHubListener::class; - $events->listen( - GitHubPayloadEvent::class, - "$class@onGitHubPayload" - ); - } - } diff --git a/app/Listeners/LastPayloadSaver.php b/app/Listeners/LastPayloadSaver.php --- a/app/Listeners/LastPayloadSaver.php +++ b/app/Listeners/LastPayloadSaver.php @@ -12,7 +12,7 @@ /** * Handles payload events */ - public function onPayload (Event $event) : void { + public function handle (Event $event) : void { self::savePayload($event->payload); } @@ -26,28 +26,4 @@ $content = json_encode($payload); file_put_contents($filename, $content); } - - /// - /// Events listening - /// - - /** - * Register the listeners for the subscriber. - * - * @param \Illuminate\Events\Dispatcher $events - */ - public function subscribe (\Illuminate\Events\Dispatcher $events) : void { - $ns = 'Nasqueron\Notifications\Events'; - $class = 'Nasqueron\Notifications\Listeners\LastPayloadSaver'; - $eventsToListen = [ - 'DockerHubPayloadEvent', - 'GitHubPayloadEvent', - 'JenkinsPayloadEvent', - 'PhabricatorPayloadEvent', - ]; - - foreach ($eventsToListen as $event) { - $events->listen("$ns\\$event", "$class@onPayload"); - } - } } diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php --- a/app/Listeners/NotificationListener.php +++ b/app/Listeners/NotificationListener.php @@ -3,6 +3,7 @@ namespace Nasqueron\Notifications\Listeners; use Nasqueron\Notifications\Events\DockerHubPayloadEvent; +use Nasqueron\Notifications\Events\Event; use Nasqueron\Notifications\Events\GitHubPayloadEvent; use Nasqueron\Notifications\Events\JenkinsPayloadEvent; use Nasqueron\Notifications\Events\PhabricatorPayloadEvent; @@ -11,6 +12,8 @@ use Nasqueron\Notifications\Jobs\FireJenkinsNotification; use Nasqueron\Notifications\Jobs\FirePhabricatorNotification; +use InvalidArgumentException; + class NotificationListener { /// @@ -64,33 +67,22 @@ } /// - /// Events listening + /// Events sorter /// - /** - * Register the listeners for the subscriber. - * - * @param \Illuminate\Events\Dispatcher $events - */ - public function subscribe (\Illuminate\Events\Dispatcher $events) : void { - $class = 'Nasqueron\Notifications\Listeners\NotificationListener'; - $events->listen( - 'Nasqueron\Notifications\Events\DockerHubPayloadEvent', - "$class@onDockerHubPayload" - ); - $events->listen( - 'Nasqueron\Notifications\Events\GitHubPayloadEvent', - "$class@onGitHubPayload" - ); - $events->listen( - 'Nasqueron\Notifications\Events\JenkinsPayloadEvent', - "$class@onJenkinsPayload" - ); - $events->listen( - 'Nasqueron\Notifications\Events\PhabricatorPayloadEvent', - "$class@onPhabricatorPayload" - ); + private static function getEventHandlerMethod (string $eventClasss) : string { + $parts = explode('\\', $eventClasss); + $className = end($parts); + + if (!str_ends_with($className, "Event")) { + throw new InvalidArgumentException("Events classes must be ended by 'Event'"); + } + return "on" . substr($className, 0, strlen($className)-5); } + public function handle (Event $event) : void { + $callable = [$this, self::getEventHandlerMethod($event::class)]; + $callable($event); + } } diff --git a/app/Listeners/PhabricatorListener.php b/app/Listeners/PhabricatorListener.php --- a/app/Listeners/PhabricatorListener.php +++ b/app/Listeners/PhabricatorListener.php @@ -5,8 +5,6 @@ use Nasqueron\Notifications\Events\GitHubPayloadEvent; use Nasqueron\Notifications\Jobs\NotifyNewCommitsToDiffusion; -use Illuminate\Events\Dispatcher; - /** * Listens to events Phabricator is interested by. */ @@ -21,7 +19,7 @@ * * @param GitHubPayloadEvent $event The GitHub payload event */ - public function onGitHubPayload (GitHubPayloadEvent $event) : void { + public function handle (GitHubPayloadEvent $event) : void { if ($event->event === 'push') { $this->notifyNewCommits($event); } @@ -39,21 +37,4 @@ ); $job->handle(); } - - /// - /// Events listening - /// - - /** - * Registers the listeners for the subscriber. - * - * @param Dispatcher $events - */ - public function subscribe (Dispatcher $events) : void { - $class = PhabricatorListener::class; - $events->listen( - GitHubPayloadEvent::class, - "$class@onGitHubPayload" - ); - } } diff --git a/app/Phabricator/PhabricatorAPI.php b/app/Phabricator/PhabricatorAPI.php --- a/app/Phabricator/PhabricatorAPI.php +++ b/app/Phabricator/PhabricatorAPI.php @@ -3,8 +3,7 @@ namespace Nasqueron\Notifications\Phabricator; use Nasqueron\Notifications\Contracts\APIClient; - -use Services; +use Nasqueron\Notifications\Facades\Services; class PhabricatorAPI implements APIClient { diff --git a/app/Phabricator/PhabricatorStory.php b/app/Phabricator/PhabricatorStory.php --- a/app/Phabricator/PhabricatorStory.php +++ b/app/Phabricator/PhabricatorStory.php @@ -321,7 +321,7 @@ return "id"; } - if (starts_with($key, "story") && strlen($key) > 5) { + if (str_starts_with($key, "story") && strlen($key) > 5) { return lcfirst(substr($key, 5)); } diff --git a/app/Phabricator/ProjectsMap.php b/app/Phabricator/ProjectsMap.php --- a/app/Phabricator/ProjectsMap.php +++ b/app/Phabricator/ProjectsMap.php @@ -4,8 +4,8 @@ use Nasqueron\Notifications\Contracts\APIClient as APIClient; -use App; -use Cache; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Cache; class ProjectsMap implements \IteratorAggregate, \ArrayAccess { diff --git a/app/Phabricator/ProjectsMapFactory.php b/app/Phabricator/ProjectsMapFactory.php --- a/app/Phabricator/ProjectsMapFactory.php +++ b/app/Phabricator/ProjectsMapFactory.php @@ -10,7 +10,7 @@ * @param string $instanceName The Phabricator instance name * @return ProjectsMap */ - public function load ($instanceName) { + public function load (string $instanceName) { return ProjectsMap::load($instanceName); } @@ -20,7 +20,7 @@ * @param string $instanceName The Phabricator instance name * @return ProjectsMap */ - public function fetch ($instanceName) { + public function fetch (string $instanceName) { return ProjectsMap::fetch($instanceName); } diff --git a/app/Providers/DockerHubServiceProvider.php b/app/Providers/DockerHubServiceProvider.php --- a/app/Providers/DockerHubServiceProvider.php +++ b/app/Providers/DockerHubServiceProvider.php @@ -2,11 +2,12 @@ namespace Nasqueron\Notifications\Providers; +use Keruald\DockerHub\Build\TriggerBuildFactory; + +use GuzzleHttp\Client; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; -use GuzzleHttp\Client; -use Keruald\DockerHub\Build\TriggerBuildFactory; class DockerHubServiceProvider extends ServiceProvider { /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,29 +2,48 @@ namespace Nasqueron\Notifications\Providers; -use Illuminate\{ - Contracts\Events\Dispatcher as DispatcherContract, - Foundation\Support\Providers\EventServiceProvider as ServiceProvider -}; +use Nasqueron\Notifications\Events\DockerHubPayloadEvent; +use Nasqueron\Notifications\Events\GitHubPayloadEvent; +use Nasqueron\Notifications\Events\JenkinsPayloadEvent; +use Nasqueron\Notifications\Events\NotificationEvent; +use Nasqueron\Notifications\Events\PhabricatorPayloadEvent; +use Nasqueron\Notifications\Listeners\AMQPEventListener; +use Nasqueron\Notifications\Listeners\DockerHubListener; +use Nasqueron\Notifications\Listeners\LastPayloadSaver; +use Nasqueron\Notifications\Listeners\NotificationListener; +use Nasqueron\Notifications\Listeners\PhabricatorListener; -use Config; +use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { /** - * Registers all our listeners as subscriber classes - */ - private function subscribeListeners () { - $this->subscribe += Config::get('app.listeners'); - } - - /** - * Register any other events for your application. + * The event listener mappings for the application. * - * @return void + * @var array */ - public function boot() { - $this->subscribeListeners(); - parent::boot(); - } + protected $listen = [ + DockerHubPayloadEvent::class => [ + LastPayloadSaver::class, + NotificationListener::class, + ], + GitHubPayloadEvent::class => [ + DockerHubListener::class, + LastPayloadSaver::class, + NotificationListener::class, + PhabricatorListener::class, + ], + JenkinsPayloadEvent::class => [ + LastPayloadSaver::class, + NotificationListener::class, + ], + NotificationEvent::class => [ + AMQPEventListener::class, + ], + PhabricatorPayloadEvent::class => [ + LastPayloadSaver::class, + NotificationListener::class, + ], + ]; + } diff --git a/app/Providers/MailgunServiceProvider.php b/app/Providers/MailgunServiceProvider.php --- a/app/Providers/MailgunServiceProvider.php +++ b/app/Providers/MailgunServiceProvider.php @@ -2,11 +2,11 @@ namespace Nasqueron\Notifications\Providers; -use Illuminate\Contracts\Foundation\Application; -use Illuminate\Support\ServiceProvider; +use Keruald\Mailgun\MailgunMessageFactory; use GuzzleHttp\Client; -use Keruald\Mailgun\MailgunMessageFactory; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Support\ServiceProvider; class MailgunServiceProvider extends ServiceProvider { /** diff --git a/app/Providers/PhabricatorAPIServiceProvider.php b/app/Providers/PhabricatorAPIServiceProvider.php --- a/app/Providers/PhabricatorAPIServiceProvider.php +++ b/app/Providers/PhabricatorAPIServiceProvider.php @@ -22,7 +22,7 @@ * @return void */ public function register() { - $this->app->singleton('phabricator-api', function () { + $this->app->singleton('phabricator-api', static function () { return new PhabricatorAPIFactory; }); } diff --git a/app/Providers/PhabricatorProjectsMapServiceProvider.php b/app/Providers/PhabricatorProjectsMapServiceProvider.php --- a/app/Providers/PhabricatorProjectsMapServiceProvider.php +++ b/app/Providers/PhabricatorProjectsMapServiceProvider.php @@ -22,7 +22,7 @@ * @return void */ public function register() { - $this->app->singleton('phabricator-projectsmap', function () { + $this->app->singleton('phabricator-projectsmap', static function () { return new ProjectsMapFactory; }); } diff --git a/app/Providers/ReportServiceProvider.php b/app/Providers/ReportServiceProvider.php --- a/app/Providers/ReportServiceProvider.php +++ b/app/Providers/ReportServiceProvider.php @@ -32,7 +32,7 @@ ) { $events->listen( 'Nasqueron\Notifications\Events\ReportEvent', - function (ReportEvent $event) use ($report) { + static function (ReportEvent $event) use ($report) { $report->addAction($event->action); } ); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,10 +2,8 @@ namespace Nasqueron\Notifications\Providers; -use Illuminate\{ - Routing\Router, - Foundation\Support\Providers\RouteServiceProvider as ServiceProvider -}; +use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Routing\Router; class RouteServiceProvider extends ServiceProvider { @@ -36,7 +34,7 @@ * @return void */ public function map(Router $router) { - $router->group(['namespace' => $this->namespace], function ($router) { + $router->group(['namespace' => $this->namespace], static function ($router) { require app_path('Http/routes.php'); }); } diff --git a/composer.json b/composer.json --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "license": "BSD-2-Clause", "type": "project", "require": { - "php": ">=7.1.0", - "laravel/framework": "5.3.*", + "php": ">=8.1.0", + "laravel/framework": "8.*", "guzzlehttp/guzzle": "^6.2", "keruald/dockerhub": "^0.0.3", "keruald/github": "^0.2.1", @@ -21,18 +21,22 @@ "sentry/sentry": "^0.13.0" }, "require-dev": { - "phan/phan": "^3.2.2", "fzaninotto/faker": "~1.4", - "mockery/mockery": "0.9.*", - "pdepend/pdepend": "^2.4.1", - "phploc/phploc": "^3.0.1", - "phpmd/phpmd" : "@stable", - "phpunit/phpunit": "~5.4", - "phpspec/phpspec": "~2.1", - "sebastian/phpcpd": "^2.0.4", - "squizlabs/php_codesniffer": "2.*", - "symfony/css-selector": "~3.0", - "symfony/dom-crawler": "~3.0" + "laravel/browser-kit-testing": "^v6.3.0", + "mockery/mockery": "^1.5.0", + "nasqueron/codestyle": "^0.1.0", + "pdepend/pdepend": "^2.10", + "phan/phan": "^5.3", + "sebastian/phpcpd": "6.0.3", + "phploc/phploc": "7.0.2", + "phpmd/phpmd": "^2.12", + "phpspec/phpspec": "^7.2", + "phpunit/phpunit": "^9.5.20", + "rector/rector": "^0.12.21", + "squizlabs/php_codesniffer": "^3.6", + "symfony/css-selector": "^6.0", + "symfony/dom-crawler": "^6.0" + }, "autoload": { "psr-4": { @@ -55,6 +59,9 @@ ] }, "config": { - "preferred-install": "dist" + "preferred-install": "dist", + "allow-plugins": { + "kylekatarnls/update-helper": true + } } } diff --git a/config/app.php b/config/app.php --- a/config/app.php +++ b/config/app.php @@ -198,24 +198,6 @@ ], - /* - |-------------------------------------------------------------------------- - | Events listeners - |-------------------------------------------------------------------------- - | - | The events listeners listed here will be automatically loaded on the - | request to your application. - | - */ - - 'listeners' => [ - Nasqueron\Notifications\Listeners\AMQPEventListener::class, - Nasqueron\Notifications\Listeners\DockerHubListener::class, - Nasqueron\Notifications\Listeners\LastPayloadSaver::class, - Nasqueron\Notifications\Listeners\NotificationListener::class, - Nasqueron\Notifications\Listeners\PhabricatorListener::class, - ], - /* |-------------------------------------------------------------------------- | Class Aliases @@ -246,7 +228,7 @@ 'File' => Illuminate\Support\Facades\File::class, 'Gate' => Illuminate\Support\Facades\Gate::class, 'Hash' => Illuminate\Support\Facades\Hash::class, - 'Input' => Illuminate\Support\Facades\Input::class, + 'Input' => \Illuminate\Support\Facades\Request::class, 'Inspiring' => Illuminate\Foundation\Inspiring::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,8 @@ + + + + + app + config + tests + diff --git a/tests/Actions/AMQPActionTest.php b/tests/Actions/AMQPActionTest.php --- a/tests/Actions/AMQPActionTest.php +++ b/tests/Actions/AMQPActionTest.php @@ -2,8 +2,6 @@ namespace Nasqueron\Notifications\Tests\Actions; -use Illuminate\Foundation\Testing\WithoutMiddleware; - use Nasqueron\Notifications\Actions\AMQPAction; use Nasqueron\Notifications\Tests\TestCase; @@ -11,7 +9,7 @@ protected $action; - public function setUp () { + public function setUp (): void { $this->action = new AMQPAction( 'method', 'target' diff --git a/tests/Actions/ActionErrorTest.php b/tests/Actions/ActionErrorTest.php --- a/tests/Actions/ActionErrorTest.php +++ b/tests/Actions/ActionErrorTest.php @@ -2,8 +2,6 @@ namespace Nasqueron\Notifications\Tests\Actions; -use Illuminate\Foundation\Testing\WithoutMiddleware; - use Nasqueron\Notifications\Actions\ActionError; use Nasqueron\Notifications\Tests\TestCase; @@ -11,7 +9,7 @@ protected $actionError; - public function setUp () { + public function setUp () : void { $ex = new \RuntimeException('Lorem ipsum dolor'); $this->actionError = new ActionError($ex); } diff --git a/tests/Actions/ActionsReportTest.php b/tests/Actions/ActionsReportTest.php --- a/tests/Actions/ActionsReportTest.php +++ b/tests/Actions/ActionsReportTest.php @@ -2,8 +2,6 @@ namespace Nasqueron\Notifications\Tests\Actions; -use Illuminate\Foundation\Testing\WithoutMiddleware; - use Nasqueron\Notifications\Actions\ActionError; use Nasqueron\Notifications\Actions\ActionsReport; use Nasqueron\Notifications\Actions\AMQPAction; @@ -13,7 +11,7 @@ protected $report; - public function setUp () { + public function setUp (): void { $this->report = new ActionsReport(); } @@ -47,17 +45,11 @@ $this->assertSame(2, count($this->report->actions)); $this->assertTrue($this->report->containsError()); + $this->assertIsNumeric($this->report->created); // Attaches to gate $this->report->attachToGate('QuuxGate', 'Quuxians'); $this->assertSame('QuuxGate', $this->report->gate); $this->assertSame('Quuxians', $this->report->door); - - // Test rendering - $actualReport = (string)$this->report; - $expectedReport = file_get_contents(__DIR__ . '/../data/report.json'); - - $score = similar_text($expectedReport, $actualReport); - $this->assertGreaterThan(550, $score, 'data/report.json and rendered report differ too much. Try $this->assertEquals($expectedReport, $actualReport) to see a diff.'); } } diff --git a/tests/Actions/NotifyNewCommitsActionTest.php b/tests/Actions/NotifyNewCommitsActionTest.php --- a/tests/Actions/NotifyNewCommitsActionTest.php +++ b/tests/Actions/NotifyNewCommitsActionTest.php @@ -2,8 +2,6 @@ namespace Nasqueron\Notifications\Tests\Actions; -use Illuminate\Foundation\Testing\WithoutMiddleware; - use Nasqueron\Notifications\Actions\NotifyNewCommitsAction; use Nasqueron\Notifications\Tests\TestCase; @@ -11,7 +9,7 @@ protected $action; - public function setUp () { + public function setUp () : void { $this->action = new NotifyNewCommitsAction( 'QUUX' ); diff --git a/tests/Actions/TriggerDockerHubBuildActionTest.php b/tests/Actions/TriggerDockerHubBuildActionTest.php --- a/tests/Actions/TriggerDockerHubBuildActionTest.php +++ b/tests/Actions/TriggerDockerHubBuildActionTest.php @@ -2,8 +2,6 @@ namespace Nasqueron\Notifications\Tests\Actions; -use Illuminate\Foundation\Testing\WithoutMiddleware; - use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction; use Nasqueron\Notifications\Tests\TestCase; @@ -11,7 +9,7 @@ protected $action; - public function setUp () { + public function setUp () : void { $this->action = new TriggerDockerHubBuildAction( 'acme/foo' ); diff --git a/tests/Analyzers/GitHub/Events/CreateEventTest.php b/tests/Analyzers/GitHub/Events/CreateEventTest.php --- a/tests/Analyzers/GitHub/Events/CreateEventTest.php +++ b/tests/Analyzers/GitHub/Events/CreateEventTest.php @@ -5,13 +5,15 @@ use Nasqueron\Notifications\Analyzers\GitHub\Events\CreateEvent; use Nasqueron\Notifications\Tests\TestCase; +use InvalidArgumentException; + class CreateEventTest extends TestCase { /** * @var CreateEvent */ private $event; - public function setUp () { + public function setUp (): void { $payload = new \stdClass; $payload->repository = new \stdClass; $payload->repository->full_name = 'baxterthehacker/public-repo'; @@ -31,10 +33,8 @@ ); } - /** - * @expectedException InvalidArgumentException - */ public function testNonExistingRefTypeLinkException () { + $this->expectException(InvalidArgumentException::class); $this->event->getLink(); } diff --git a/tests/Analyzers/GitHub/Events/DeleteEventTest.php b/tests/Analyzers/GitHub/Events/DeleteEventTest.php --- a/tests/Analyzers/GitHub/Events/DeleteEventTest.php +++ b/tests/Analyzers/GitHub/Events/DeleteEventTest.php @@ -5,13 +5,15 @@ use Nasqueron\Notifications\Analyzers\GitHub\Events\DeleteEvent; use Nasqueron\Notifications\Tests\TestCase; +use InvalidArgumentException; + class DeleteEventTest extends TestCase { /** * @var DeleteEvent */ private $event; - public function setUp () { + public function setUp (): void { $payload = new \stdClass; $payload->repository = new \stdClass; $payload->repository->full_name = 'baxterthehacker/public-repo'; @@ -31,10 +33,8 @@ ); } - /** - * @expectedException InvalidArgumentException - */ public function testNonExistingRefTypeLinkException () { + $this->expectException(InvalidArgumentException::class); $this->event->getLink(); } diff --git a/tests/Analyzers/GitHub/Events/EventTest.php b/tests/Analyzers/GitHub/Events/EventTest.php --- a/tests/Analyzers/GitHub/Events/EventTest.php +++ b/tests/Analyzers/GitHub/Events/EventTest.php @@ -5,6 +5,8 @@ use Nasqueron\Notifications\Analyzers\GitHub\Events\Event; use Nasqueron\Notifications\Tests\TestCase; +use InvalidArgumentException; + class EventTest extends TestCase { public function testGetClass () { @@ -21,10 +23,8 @@ ); } - /** - * @expectedException InvalidArgumentException - */ public function testForPayloadWithException () { + $this->expectException(InvalidArgumentException::class); Event::forPayload('not_existing', new \stdClass); } diff --git a/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php --- a/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php +++ b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php @@ -12,7 +12,7 @@ */ private $payload; - public function setUp () { + public function setUp (): void { $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/issue_comment.json"; $this->payload = json_decode(file_get_contents($filename)); diff --git a/tests/Analyzers/GitHub/Events/PullRequestEventTest.php b/tests/Analyzers/GitHub/Events/PullRequestEventTest.php --- a/tests/Analyzers/GitHub/Events/PullRequestEventTest.php +++ b/tests/Analyzers/GitHub/Events/PullRequestEventTest.php @@ -12,7 +12,7 @@ */ private $payload; - public function setUp () { + public function setUp (): void { $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/pull_request.json"; $this->payload = json_decode(file_get_contents($filename)); diff --git a/tests/Analyzers/GitHub/Events/PushEventTest.php b/tests/Analyzers/GitHub/Events/PushEventTest.php --- a/tests/Analyzers/GitHub/Events/PushEventTest.php +++ b/tests/Analyzers/GitHub/Events/PushEventTest.php @@ -12,7 +12,7 @@ */ private $payloads; - public function setUp () { + public function setUp (): void { $payloadsToPrepare = [ '0' => 'GitHubPushForceZeroPayload.json', '1' => 'GitHubEvents/push.json', @@ -84,7 +84,7 @@ "dereckson forcely updated docker-nginx-php-fpm (branch novolume)", $event->getDescription() ); - $this->assertContains("compare", $event->getLink()); + $this->assertStringContainsString("compare", $event->getLink()); } public function testOnGitPushWithSeveralCommits () { @@ -94,6 +94,6 @@ "dereckson pushed 2 commits to notifications", $event->getDescription() ); - $this->assertContains("compare", $event->getLink()); + $this->assertStringContainsString("compare", $event->getLink()); } } diff --git a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php --- a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php +++ b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php @@ -12,7 +12,7 @@ */ private $payload; - public function setUp () { + public function setUp (): void { $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/repository.json"; $this->payload = json_decode(file_get_contents($filename)); @@ -24,7 +24,7 @@ $payload->repository->fork = true; $event = new RepositoryEvent($payload); - $this->assertContains("fork", $event->getDescription()); + $this->assertStringContainsString("fork", $event->getDescription()); } public function testWhenRepositoryContainsDescription () { @@ -32,7 +32,7 @@ $payload->repository->description = "Lorem ipsum dolor"; $event = new RepositoryEvent($payload); - $this->assertContains("Lorem ipsum dolor", $event->getDescription()); + $this->assertStringContainsString("Lorem ipsum dolor", $event->getDescription()); } public function testWhenRepositoryIsForkedAndContainsDescription () { @@ -41,8 +41,8 @@ $payload->repository->description = "Lorem ipsum dolor"; $event = new RepositoryEvent($payload); - $this->assertContains("fork", $event->getDescription()); - $this->assertContains("Lorem ipsum dolor", $event->getDescription()); + $this->assertStringContainsString("fork", $event->getDescription()); + $this->assertStringContainsString("Lorem ipsum dolor", $event->getDescription()); } /** diff --git a/tests/Analyzers/GitHub/Events/StatusEventTest.php b/tests/Analyzers/GitHub/Events/StatusEventTest.php --- a/tests/Analyzers/GitHub/Events/StatusEventTest.php +++ b/tests/Analyzers/GitHub/Events/StatusEventTest.php @@ -12,7 +12,7 @@ */ private $payload; - public function setUp () { + public function setUp (): void { $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/status.json"; $this->payload = json_decode(file_get_contents($filename)); diff --git a/tests/Analyzers/GitHub/Events/UnknownEventTest.php b/tests/Analyzers/GitHub/Events/UnknownEventTest.php --- a/tests/Analyzers/GitHub/Events/UnknownEventTest.php +++ b/tests/Analyzers/GitHub/Events/UnknownEventTest.php @@ -12,7 +12,7 @@ */ private $event; - public function setUp () { + public function setUp (): void { $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/push.json"; $payload = json_decode(file_get_contents($filename)); $this->event = new UnknownEvent("quux", $payload); diff --git a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php --- a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php +++ b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php @@ -30,7 +30,7 @@ /** * Prepares the tests */ - public function setUp () { + public function setUp (): void { parent::setUp(); $this->unknownEventAnalyzer = new GitHubPayloadAnalyzer( @@ -64,14 +64,8 @@ ); } - /// - /// Test constructor - /// - - /** - * @expectedException TypeError - */ - public function testConstructorThrowsAnExceptionWhenPayloadIsInvalid () { + public function testConstructorThrowsAnExceptionWhenPayloadIsInvalid() { + $this->expectException(\TypeError::class); new GitHubPayloadAnalyzer( "Acme", "push", @@ -131,7 +125,7 @@ /// public function testDescriptionContainsTypeWhenEventTypeIsUnknown () { - $this->assertContains( + $this->assertStringContainsString( "quux", $this->unknownEventAnalyzer->getDescription() ); diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php --- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php +++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php @@ -2,10 +2,8 @@ namespace Nasqueron\Notifications\Tests\Analyzers; -use Illuminate\Foundation\Testing\WithoutMiddleware; - -use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration; use Nasqueron\Notifications\Analyzers\ItemGroupMapping; +use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration; use Nasqueron\Notifications\Tests\TestCase; class JenkinsPayloadAnalyzerConfigurationTest extends TestCase { @@ -20,7 +18,7 @@ /** * Prepares the test */ - public function setUp () { + public function setUp (): void { $filename = __DIR__ . '/../../data/JenkinsPayloadAnalyzer/Nasqueron.json'; $mapper = new \JsonMapper(); $this->configuration = $mapper->map( diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php --- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php +++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php @@ -3,7 +3,6 @@ namespace Nasqueron\Notifications\Tests\Analyzers; use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer; -use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration; use Nasqueron\Notifications\Tests\TestCase; class JenkinsPayloadAnalyzerTest extends TestCase { @@ -23,7 +22,7 @@ /** * Prepares the test */ - public function setUp () { + public function setUp (): void { parent::setUp(); $filename = __DIR__ . '/../../data/payloads/JenkinsToIgnorePayload.json'; @@ -52,7 +51,7 @@ /** * @dataProvider payloadStatusProvider */ - public function testShouldNotifyByStatus ($status, $shouldNotify) { + public function testShouldNotifyByStatus(string $status, bool $shouldNotify) { $this->payload->build->status = $status; $this->assertSame($shouldNotify, $this->analyzer->shouldNotify()); } diff --git a/tests/Analyzers/PayloadAnalyzerConfigurationTest.php b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php --- a/tests/Analyzers/PayloadAnalyzerConfigurationTest.php +++ b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php @@ -2,10 +2,8 @@ namespace Nasqueron\Notifications\Tests\Analyzers; -use Illuminate\Foundation\Testing\WithoutMiddleware; - -use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration; use Nasqueron\Notifications\Analyzers\ItemGroupMapping; +use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration; use Nasqueron\Notifications\Tests\TestCase; class PayloadAnalyzerConfigurationTest extends TestCase { @@ -20,7 +18,7 @@ /** * Prepares the test */ - public function setUp () { + public function setUp (): void { $filename = __DIR__ . '/../data/GitHubPayloadAnalyzer/Nasqueron.json'; $mapper = new \JsonMapper(); $this->configuration = $mapper->map( diff --git a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php --- a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php +++ b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php @@ -19,7 +19,7 @@ */ private $story; - public function setUp () { + public function setUp (): void { parent::setUp(); $config = $this->getPhabricatorPayloadAnalyzerConfiguration(); diff --git a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php --- a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php +++ b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php @@ -19,7 +19,7 @@ */ private $story; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->story = $this->getStory(); @@ -86,10 +86,8 @@ ); } - /** - * @expectedException \BadMethodCallException - */ - public function testGetItemThrowsBadMethodCallException () { + public function testGetItemThrowsBadMethodCallException() { + $this->expectException(\BadMethodCallException::class); $this->analyzer->getItemName(); } diff --git a/tests/Analyzers/Phabricator/WithConfiguration.php b/tests/Analyzers/Phabricator/WithConfiguration.php --- a/tests/Analyzers/Phabricator/WithConfiguration.php +++ b/tests/Analyzers/Phabricator/WithConfiguration.php @@ -3,7 +3,6 @@ namespace Nasqueron\Notifications\Tests\Analyzers\Phabricator; use Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzerConfiguration; -use Nasqueron\Notifications\Phabricator\PhabricatorStory; /** * Helper methods to construct needed objects diff --git a/tests/Config/FeaturesTest.php b/tests/Config/FeaturesTest.php --- a/tests/Config/FeaturesTest.php +++ b/tests/Config/FeaturesTest.php @@ -22,7 +22,7 @@ $this->assertFalse(Features::isEnabled('Quux')); // Count it - $this->assertContains('Quux', Features::getAll()); + $this->assertArrayHasKey('Quux', Features::getAll()); $this->assertContains('Quux', Features::getAvailable()); $this->assertNotContains('Quux', Features::getEnabled()); } diff --git a/tests/Config/Reporting/FeatureReportEntryTest.php b/tests/Config/Reporting/FeatureReportEntryTest.php --- a/tests/Config/Reporting/FeatureReportEntryTest.php +++ b/tests/Config/Reporting/FeatureReportEntryTest.php @@ -17,7 +17,7 @@ */ private $disabledFeatureEntry; - public function setUp () { + public function setUp (): void { $this->enabledFeatureEntry = new FeatureReportEntry("foo", true); $this->disabledFeatureEntry = new FeatureReportEntry("bar", false); } diff --git a/tests/Config/Reporting/IntegrationTest.php b/tests/Config/Reporting/IntegrationTest.php --- a/tests/Config/Reporting/IntegrationTest.php +++ b/tests/Config/Reporting/IntegrationTest.php @@ -6,7 +6,7 @@ class IntegrationTest extends TestCase { - public function setUp () { + public function setUp (): void { parent::setUp(); $this->mockServices() diff --git a/tests/Config/Reporting/ServiceReportEntryTest.php b/tests/Config/Reporting/ServiceReportEntryTest.php --- a/tests/Config/Reporting/ServiceReportEntryTest.php +++ b/tests/Config/Reporting/ServiceReportEntryTest.php @@ -3,7 +3,6 @@ namespace Nasqueron\Notifications\Tests\Config\Reporting; use Nasqueron\Notifications\Config\Reporting\ServiceReportEntry; -use Nasqueron\Notifications\Config\Services\Service; use Nasqueron\Notifications\Tests\TestCase; class ServiceReportEntryTest extends TestCase { @@ -13,7 +12,7 @@ */ private $serviceEntry; - public function setUp () { + public function setUp (): void { $service = $this->mockService(); $this->serviceEntry = new ServiceReportEntry($service); } diff --git a/tests/Config/Services/ServiceTest.php b/tests/Config/Services/ServiceTest.php --- a/tests/Config/Services/ServiceTest.php +++ b/tests/Config/Services/ServiceTest.php @@ -17,7 +17,7 @@ */ private $serviceWithoutInstance; - public function setUp () { + public function setUp (): void { $this->serviceWithoutInstance = new Service(); $this->serviceWithInstance = clone $this->serviceWithoutInstance; diff --git a/tests/Config/Services/ServicesTest.php b/tests/Config/Services/ServicesTest.php --- a/tests/Config/Services/ServicesTest.php +++ b/tests/Config/Services/ServicesTest.php @@ -9,7 +9,7 @@ private $services; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->services = Services::loadFromJson('credentials.json'); diff --git a/tests/Console/Commands/ConfigShowTest.php b/tests/Console/Commands/ConfigShowTest.php --- a/tests/Console/Commands/ConfigShowTest.php +++ b/tests/Console/Commands/ConfigShowTest.php @@ -3,8 +3,6 @@ namespace Nasqueron\Notifications\Tests\Console\Commands; use Nasqueron\Notifications\Config\Features; -use Nasqueron\Notifications\Config\Services\Service; - use Mockery; class ConfigShowTest extends TestCase { @@ -19,7 +17,7 @@ */ private $servicesMock; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->servicesMock = $this->mockServices(); diff --git a/tests/Console/Commands/ConfigValidateTest.php b/tests/Console/Commands/ConfigValidateTest.php --- a/tests/Console/Commands/ConfigValidateTest.php +++ b/tests/Console/Commands/ConfigValidateTest.php @@ -2,7 +2,7 @@ namespace Nasqueron\Notifications\Tests\Console\Commands; -use Storage; +use Illuminate\Support\Facades\Storage; class ConfigValidateTest extends TestCase { @@ -53,7 +53,7 @@ } } - public function tearDown () { + public function tearDown () : void { $this->deleteTestFile(); parent::tearDown(); } diff --git a/tests/Console/Commands/NotificationsPayloadTest.php b/tests/Console/Commands/NotificationsPayloadTest.php --- a/tests/Console/Commands/NotificationsPayloadTest.php +++ b/tests/Console/Commands/NotificationsPayloadTest.php @@ -44,10 +44,8 @@ $this->assertDisplayContains('"type": "PSTE"'); } - /** - * @expectedException InvalidArgumentException - */ - public function testArgumentsArrayCombine () { + public function testArgumentsArrayCombine() { + $this->expectException(\InvalidArgumentException::class); NotificationsPayload::argumentsArrayCombine(['foo'], []); } diff --git a/tests/Console/Commands/PhabricatorProjectsMapTest.php b/tests/Console/Commands/PhabricatorProjectsMapTest.php --- a/tests/Console/Commands/PhabricatorProjectsMapTest.php +++ b/tests/Console/Commands/PhabricatorProjectsMapTest.php @@ -2,7 +2,6 @@ namespace Nasqueron\Notifications\Tests\Console\Commands; -use Nasqueron\Notifications\Config\Services\Service; use Nasqueron\Notifications\Console\Commands\PhabricatorProjectsMap; class PhabricatorProjectsMapTest extends TestCase { @@ -12,7 +11,7 @@ */ protected $class = PhabricatorProjectsMap::class; - public function setUp () { + public function setUp (): void { parent::setUp(); $service = $this->mockService('Phabricator'); diff --git a/tests/Console/Commands/TestCase.php b/tests/Console/Commands/TestCase.php --- a/tests/Console/Commands/TestCase.php +++ b/tests/Console/Commands/TestCase.php @@ -2,14 +2,11 @@ namespace Nasqueron\Notifications\Tests\Console\Commands; -use Nasqueron\Notifications\Config\Services\Service; use Nasqueron\Notifications\Tests\TestCase as BaseTestCase; use Illuminate\Contracts\Console\Kernel; use Symfony\Component\Console\Tester\CommandTester; -use Mockery; - class TestCase extends BaseTestCase { /// @@ -26,7 +23,7 @@ */ protected $tester; - public function setUp () { + public function setUp (): void { parent::setUp(); $kernel = $this->app->make(Kernel::class); @@ -39,14 +36,14 @@ /// public function assertDisplayContains(string $expectedNeedle) { - $this->assertContains( + $this->assertStringContainsString( $expectedNeedle, $this->tester->getDisplay() ); } public function assertRegexpInDisplay (string $pattern) { - $this->assertRegexp($pattern, $this->tester->getDisplay()); + $this->assertMatchesRegularExpression($pattern, $this->tester->getDisplay()); } } diff --git a/tests/Console/KernelTest.php b/tests/Console/KernelTest.php --- a/tests/Console/KernelTest.php +++ b/tests/Console/KernelTest.php @@ -4,11 +4,8 @@ use Nasqueron\Notifications\Tests\TestCase; -use Nasqueron\Notifications\Console\Kernel; use Illuminate\Contracts\Console\Kernel as BaseKernel; - -use Artisan; -use File; +use Illuminate\Support\Facades\File; class KernelTest extends TestCase { /** @@ -30,7 +27,7 @@ */ private $namespace; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->kernel = $this->app->make(BaseKernel::class); @@ -59,10 +56,8 @@ ); } - /** - * @expectedException \RuntimeException - */ - public function testGetWhenCommandDoesNotExist () { + public function testGetWhenCommandDoesNotExist() { + $this->expectException(\RuntimeException::class); $this->kernel->get('notexisting'); } @@ -71,10 +66,8 @@ $this->assertInstanceOf($class, $this->kernel->getByClass($class)); } - /** - * @expectedException \RuntimeException - */ - public function testGetByClassWhenCommandDoesNotExist () { + public function testGetByClassWhenCommandDoesNotExist() { + $this->expectException(\RuntimeException::class); $this->kernel->getByClass('notexisting'); } diff --git a/tests/Exceptions/HandlerTest.php b/tests/Exceptions/HandlerTest.php --- a/tests/Exceptions/HandlerTest.php +++ b/tests/Exceptions/HandlerTest.php @@ -2,12 +2,11 @@ namespace Nasqueron\Notifications\Tests\Exceptions; -use Illuminate\Auth\Access\AuthorizationException; use Nasqueron\Notifications\Exceptions\Handler; use Nasqueron\Notifications\Tests\TestCase; -use App; -use Config; +use Illuminate\Auth\Access\AuthorizationException; +use Illuminate\Support\Facades\Config; use Mockery; class HandlerTest extends TestCase { @@ -22,7 +21,7 @@ */ private $ravenClientMock; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->handler = new Handler($this->app); diff --git a/tests/Facades/DockerHubTest.php b/tests/Facades/DockerHubTest.php --- a/tests/Facades/DockerHubTest.php +++ b/tests/Facades/DockerHubTest.php @@ -2,11 +2,9 @@ namespace Nasqueron\Notifications\Tests\Facades; +use Nasqueron\Notifications\Facades\DockerHub; use Nasqueron\Notifications\Tests\TestCase; -use Config; -use DockerHub; - use Keruald\DockerHub\Build\TriggerBuildFactory; class DockerHubTest extends TestCase { diff --git a/tests/Facades/MailgunTest.php b/tests/Facades/MailgunTest.php --- a/tests/Facades/MailgunTest.php +++ b/tests/Facades/MailgunTest.php @@ -2,11 +2,9 @@ namespace Nasqueron\Notifications\Tests\Facades; +use Nasqueron\Notifications\Facades\Mailgun; use Nasqueron\Notifications\Tests\TestCase; -use Config; -use Mailgun; - use Keruald\Mailgun\MailgunMessageFactory; class MailgunTest extends TestCase { diff --git a/tests/Facades/RavenTest.php b/tests/Facades/RavenTest.php --- a/tests/Facades/RavenTest.php +++ b/tests/Facades/RavenTest.php @@ -3,9 +3,9 @@ namespace Nasqueron\Notifications\Tests\Facades; use Nasqueron\Notifications\Tests\TestCase; +use Nasqueron\Notifications\Facades\Raven; -use Config; -use Raven; +use Illuminate\Support\Facades\Config; class RavenTest extends TestCase { diff --git a/tests/Http/Controllers/GitHubGateControllerTest.php b/tests/Http/Controllers/GitHubGateControllerTest.php --- a/tests/Http/Controllers/GitHubGateControllerTest.php +++ b/tests/Http/Controllers/GitHubGateControllerTest.php @@ -5,7 +5,7 @@ use Nasqueron\Notifications\Tests\TestCase; class GitHubGateControllerTest extends TestCase { - public function setUp () { + public function setUp (): void { parent::setUp(); $this->disableEvents(); diff --git a/tests/Http/PayloadFullTest.php b/tests/Http/PayloadFullTest.php --- a/tests/Http/PayloadFullTest.php +++ b/tests/Http/PayloadFullTest.php @@ -7,7 +7,7 @@ class PayloadFullTest extends TestCase { - public function setUp () { + public function setUp (): void { parent::setUp(); $this->disableBroker(); diff --git a/tests/Http/PlaceholderTest.php b/tests/Http/PlaceholderTest.php --- a/tests/Http/PlaceholderTest.php +++ b/tests/Http/PlaceholderTest.php @@ -2,19 +2,13 @@ namespace Nasqueron\Notifications\Tests; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; - -class PlaceholderTest extends TestCase -{ +class PlaceholderTest extends TestCase { /** * Placeholder homepage works. * * @return void */ - public function testPlaceholder() - { + public function testPlaceholder() { $this->visit('/') ->see('Notifications center'); } diff --git a/tests/Http/StatusTest.php b/tests/Http/StatusTest.php --- a/tests/Http/StatusTest.php +++ b/tests/Http/StatusTest.php @@ -2,19 +2,13 @@ namespace Nasqueron\Notifications\Tests; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; - -class StatusTest extends TestCase -{ +class StatusTest extends TestCase { /** * Status works. * * @return void */ - public function testStatus() - { + public function testStatus() { $this->visit('/status') ->see('ALIVE'); } diff --git a/tests/Jobs/NotifyNewCommitsToDiffusionTest.php b/tests/Jobs/NotifyNewCommitsToDiffusionTest.php --- a/tests/Jobs/NotifyNewCommitsToDiffusionTest.php +++ b/tests/Jobs/NotifyNewCommitsToDiffusionTest.php @@ -15,7 +15,7 @@ /** * @dataProvider apiRepositoryReplyProvider */ - public function testHandle ($apiRepositoryReply, int $apiCallCounts) { + public function testHandle(?array $apiRepositoryReply, int $apiCallCounts) { $this->mockPhabricatorAPI() ->shouldReceive('getForProject->call') ->andReturn( @@ -32,9 +32,11 @@ $job->handle(); } - public function testJobWhenThereIsNoPhabricatorInstanceForTheProject () { + public function testJobWhenThereIsNoPhabricatorInstanceForTheProject () : void { $job = $this->mockJob("not-existing-project"); $job->handle(); + + $this->markTestIncomplete(); } /// diff --git a/tests/Phabricator/PhabricatorAPIExceptionTest.php b/tests/Phabricator/PhabricatorAPIExceptionTest.php --- a/tests/Phabricator/PhabricatorAPIExceptionTest.php +++ b/tests/Phabricator/PhabricatorAPIExceptionTest.php @@ -12,7 +12,7 @@ */ private $exception; - public function setUp () { + public function setUp (): void { $this->exception = new PhabricatorAPIException( 100, "Lorem ipsum dolor" diff --git a/tests/Phabricator/PhabricatorAPIFactoryTest.php b/tests/Phabricator/PhabricatorAPIFactoryTest.php --- a/tests/Phabricator/PhabricatorAPIFactoryTest.php +++ b/tests/Phabricator/PhabricatorAPIFactoryTest.php @@ -11,7 +11,7 @@ */ private $factory; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->factory = $this->app->make('phabricator-api'); } diff --git a/tests/Phabricator/PhabricatorAPITest.php b/tests/Phabricator/PhabricatorAPITest.php --- a/tests/Phabricator/PhabricatorAPITest.php +++ b/tests/Phabricator/PhabricatorAPITest.php @@ -20,17 +20,13 @@ ); } - /** - * @expectedException \RuntimeException - */ public function testForInstanceWhere () { + $this->expectException(\RuntimeException::class); PhabricatorAPI::forInstance("https://notfound.acme.tld"); } - /** - * @expectedException \RuntimeException - */ public function testForProjectWhenProjectDoesNotExist () { + $this->expectException(\RuntimeException::class); PhabricatorAPI::forProject("NotFound"); } } diff --git a/tests/Phabricator/ProjectsMapFactoryTest.php b/tests/Phabricator/ProjectsMapFactoryTest.php --- a/tests/Phabricator/ProjectsMapFactoryTest.php +++ b/tests/Phabricator/ProjectsMapFactoryTest.php @@ -11,7 +11,7 @@ */ private $factory; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->factory = $this->app->make('phabricator-projectsmap'); diff --git a/tests/Phabricator/ProjectsMapTest.php b/tests/Phabricator/ProjectsMapTest.php --- a/tests/Phabricator/ProjectsMapTest.php +++ b/tests/Phabricator/ProjectsMapTest.php @@ -6,7 +6,8 @@ use Nasqueron\Notifications\Phabricator\ProjectsMap; use Nasqueron\Notifications\Tests\TestCase; -use Mockery; +use ErrorException; +use Exception; class ProjectsMapTest extends TestCase { @@ -15,7 +16,7 @@ */ private $map; - public function setUp () { + public function setUp (): void { parent::setUp(); // @@ -59,10 +60,8 @@ ); } - /** - * @expectedException ErrorException - */ public function testOffsetGetWhenItDoesNotExist () { + $this->expectException(ErrorException::class); $this->map->offsetGet("non-existing-key"); } @@ -184,18 +183,14 @@ }); } - /** - * @expectedException Exception - */ public function testFetchFromAPIWithoutReply () { + $this->expectException(Exception::class); $mock = $this->mockPhabricatorAPIWithReply(false); ProjectsMap::fetch("http://phabricator.acme.tld", $mock); } - /** - * @expectedException Exception - */ public function testFetchFromAPIInvalidReply () { + $this->expectException(Exception::class); $mock = $this->mockPhabricatorAPIWithReply(new \stdClass); ProjectsMap::fetch("http://phabricator.acme.tld", $mock); } diff --git a/tests/Providers/ConfigTest.php b/tests/Providers/ConfigTest.php --- a/tests/Providers/ConfigTest.php +++ b/tests/Providers/ConfigTest.php @@ -2,8 +2,8 @@ namespace Nasqueron\Notifications\Tests\Providers; -use Config; -use File; +use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\File; class ConfigTest extends TestCase { /** @@ -20,7 +20,7 @@ */ private $namespace; - public function setUp () { + public function setUp (): void { parent::setUp(); $this->providers = Config::get('app.providers'); diff --git a/tests/Providers/DockerHubServiceProviderTest.php b/tests/Providers/DockerHubServiceProviderTest.php --- a/tests/Providers/DockerHubServiceProviderTest.php +++ b/tests/Providers/DockerHubServiceProviderTest.php @@ -4,7 +4,7 @@ use Nasqueron\Notifications\Providers\DockerHubServiceProvider; -use Config; +use Illuminate\Support\Facades\Config; class DockerHubServiceProviderTest extends TestCase { diff --git a/tests/Providers/EventServiceProviderTest.php b/tests/Providers/EventServiceProviderTest.php --- a/tests/Providers/EventServiceProviderTest.php +++ b/tests/Providers/EventServiceProviderTest.php @@ -2,8 +2,9 @@ namespace Nasqueron\Notifications\Tests\Providers; -use Config; -use File; +use Nasqueron\Notifications\Providers\EventServiceProvider; + +use Illuminate\Support\Facades\File; class EventServiceProviderTest extends TestCase { @@ -28,12 +29,23 @@ $subscribe[] = $class; } - $this->assertEquals( - $subscribe, Config::get('app.listeners'), + $this->assertEqualsCanonicalizing( + $subscribe, $this->getRegisteredListeners(), 'The files in the app/Listeners folder and the array of classes ' . - 'defined in config/app.php at listeners key diverge.', - 0.0, 10, true // delta, maxDepth, canonicalize + 'defined in config/app.php at listeners key diverge.' ); } + private function getRegisteredListeners () : array { + $provider = $this->app->getProvider(EventServiceProvider::class); + $eventsMap = $provider->listens(); + $listeners = []; + + foreach ($eventsMap as $foundListeners) { + foreach ($foundListeners as $listener){ + $listeners[] = $listener; + } + } + return array_unique($listeners); + } } diff --git a/tests/Providers/ServicesServiceProviderTest.php b/tests/Providers/ServicesServiceProviderTest.php --- a/tests/Providers/ServicesServiceProviderTest.php +++ b/tests/Providers/ServicesServiceProviderTest.php @@ -4,7 +4,7 @@ use Nasqueron\Notifications\Providers\ServicesServiceProvider; -use Config; +use Illuminate\Support\Facades\Config; class ServicesServiceProviderTest extends TestCase { diff --git a/tests/TestCase.php b/tests/TestCase.php --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,12 +6,11 @@ use Illuminate\Contracts\Console\Kernel; use Keruald\Broker\BlackholeBroker; -use Keruald\Broker\Broker; - +use Laravel\BrowserKitTesting\TestCase as BaseTestCase; use Mockery; -class TestCase extends \Illuminate\Foundation\Testing\TestCase -{ + +class TestCase extends BaseTestCase { /** * The base URL to use while testing the application. * @@ -24,8 +23,7 @@ * * @return \Illuminate\Foundation\Application */ - public function createApplication() - { + public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); @@ -45,7 +43,7 @@ // This allows to test a single component and not all the application $mock = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); - $mock->shouldReceive('fire'); + $mock->shouldReceive('dispatch'); $mock->shouldReceive('listen'); $this->app->instance('events', $mock);