Skip to content

Commit

Permalink
Fixed standards and testing issues in Billable and tests. Added phpcs…
Browse files Browse the repository at this point in the history
… and other build files.
  • Loading branch information
justinhartman committed Nov 15, 2019
1 parent 3d4afc0 commit dd1ffcb
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ composer.phar
composer.lock
.DS_Store
Thumbs.db
# local dev ignores
coverage
.test
tests.md
patch-changes.md
docs/
32 changes: 32 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
build:
nodes:
analysis:
project_setup:
override:
- 'true'
tests:
override:
- php-scrutinizer-run
- command: phpcs-run
use_website_config: true
tests: true
filter:
excluded_paths:
- 'tests/*'
checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
coding_style:
php: { }
13 changes: 13 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
preset: laravel
risky: false
disabled:
- single_class_element_per_statement
finder:
exclude:
- modules
- node_modules
- storage
- vendor
- docs
name: "*.php"
not-name: "*.blade.php"
2 changes: 2 additions & 0 deletions LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The MIT License (MIT)

Copyright (c) 2019 22Digital. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
153 changes: 153 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Laravel"
namespace="Laravel"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
>
<!--
The name attribute of the ruleset tag is displayed
when running PHP_CodeSniffer with the -v command line
argument. The description tag below is not displayed anywhere
except in this file, so it can contain information for
developers who may change this file in the future.
-->
<description>The Laravel Coding Standards</description>
<!--
A set of custom rules as per Laravel standards.
-->
<rule ref="Generic.Classes.DuplicateClassName"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.Commenting.Fixme"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="150"/>
</properties>
</rule>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="50"/>
<property name="absoluteComplexity" value="100"/>
</properties>
</rule>
<rule ref="Generic.Metrics.NestingLevel">
<properties>
<property name="nestingLevel" value="10"/>
<property name="absoluteNestingLevel" value="30"/>
</properties>
</rule>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Generic.PHP.NoSilencedErrors"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<rule ref="MySource.PHP.EvalObjectFactory"/>
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="PSR1.Files.SideEffects"/>
<rule ref="PSR2.Classes.ClassDeclaration"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="PSR2.ControlStructures.ControlStructureSpacing"/>
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
<rule ref="PSR2.ControlStructures.SwitchDeclaration"/>
<rule ref="PSR2.Files.EndFileNewline"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
<rule ref="PSR2.Namespaces.UseDeclaration"/>
<rule ref="Zend.Files.ClosingTag"/>
<rule ref="PSR1">
<exclude-pattern>*.php</exclude-pattern>
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
</rule>
<rule ref="Generic">
<exclude-pattern>*.php</exclude-pattern>
<exclude name="Generic.Strings.UnnecessaryStringConcat.Found)"/>
</rule>
<!--
If no files or directories are specified on the command line
your custom standard can specify what files should be checked
instead.
Note that specifying any file or directory path
on the command line will ignore all file tags.
-->
<file>resources</file>
<file>src</file>
<file>tests</file>
<!--
You can hard-code ignore patterns directly into your
custom standard so you don't have to specify the
patterns on the command line.
-->
<exclude-pattern>*/database/*</exclude-pattern>
<exclude-pattern>*/cache/*</exclude-pattern>
<exclude-pattern>*/*.js</exclude-pattern>
<exclude-pattern>*/*.css</exclude-pattern>
<exclude-pattern>*/*.xml</exclude-pattern>
<exclude-pattern>*/*.blade.php</exclude-pattern>
<exclude-pattern>*/autoload.php</exclude-pattern>
<exclude-pattern>*/storage/*</exclude-pattern>
<exclude-pattern>*/docs/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/migrations/*</exclude-pattern>
<exclude-pattern>*/config/*</exclude-pattern>
<exclude-pattern>*/public/index.php</exclude-pattern>
<exclude-pattern>*/*.blade.php</exclude-pattern>
<exclude-pattern>*/Middleware/*</exclude-pattern>
<exclude-pattern>*/Console/Kernel.php</exclude-pattern>
<exclude-pattern>*/Exceptions/Handler.php</exclude-pattern>
<exclude-pattern>*/Http/Kernel.php</exclude-pattern>
<exclude-pattern>*/Providers/*</exclude-pattern>
<!--
Print either the "full", "xml", "checkstyle", "csv", "json", "junit",
"emacs", "source", "summary", "diff", "svnblame", "gitblame", "hgblame"
or "notifysend" report, or specify the path to a custom report class.
-->
<arg name="report" value="full"/>
<!--
You can hard-code command line values into your custom standard.
Note that this does not work for the command line values:
-v[v][v], -l, -d, -sniffs and -standard
The following tags are equivalent to the command line arguments:
-p
-->
<arg name="colors"/>
<arg value="spvn"/>
<!--
You can hard-code custom php.ini settings into your custom standard.
The following tag sets the memory limit to 64M.
-->
<ini name="memory_limit" value="128M"/>
<!--
Include all sniffs in the PEAR standard. Note that the
path to the standard does not have to be specified as the
PEAR standard exists inside the PHP_CodeSniffer install
directory.
-->
<rule ref="PSR2"/>
</ruleset>
32 changes: 17 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Cashier Fastspring ![Beta](https://img.shields.io/badge/status-beta-red.svg)
# Laravel Cashier Fastspring ![Beta](https://img.shields.io/badge/status-beta-red.svg)

[badge_package]: https://img.shields.io/badge/package-22digital/cashier--fastspring-blue.svg
[badge_release]: https://img.shields.io/packagist/v/22digital/cashier-fastspring.svg
[badge_license]: https://img.shields.io/github/license/22digital/cashier-fastspring.svg
[badge_coverage]: https://scrutinizer-ci.com/g/22digital/cashier-fastspring/badges/coverage.png?b=master
[badge_build]: https://scrutinizer-ci.com/g/22digital/cashier-fastspring/badges/build.png?b=master
[badge_packagist]: https://img.shields.io/badge/packagist-22digital/laravel--cashier--fastspring-yellow.svg
[badge_release]: https://img.shields.io/packagist/v/22digital/laravel-cashier-fastspring.svg
[badge_license]: https://img.shields.io/github/license/22digital/laravel-cashier-fastspring.svg
[badge_coverage]: https://scrutinizer-ci.com/g/22digital/laravel-cashier-fastspring/badges/coverage.png?b=master
[badge_build]: https://scrutinizer-ci.com/g/22digital/laravel-cashier-fastspring/badges/build.png?b=master
[badge_laravel]: https://img.shields.io/badge/Laravel-5.x-orange.svg
[badge_styleci]: https://github.styleci.io/repos/141720975/shield?branch=master

[link-contributors]: https://github.com/22digital/cashier-fastspring/graphs/contributors
[link-packagist]: https://packagist.org/packages/22digital/cashier-fastspring
[link-build]: https://scrutinizer-ci.com/g/22digital/cashier-fastspring/build-status/master
[link-coverage]: https://scrutinizer-ci.com/g/22digital/cashier-fastspring/?branch=master
[link-license]: https://github.com/22digital/cashier-fastspring/blob/master/LICENSE.md
[badge_styleci]: https://github.styleci.io/repos/219102431/shield?branch=master
[badge_travis]: https://travis-ci.org/22digital/laravel-cashier-fastspring.svg?branch=master

[link-contributors]: https://github.com/22digital/laravel-cashier-fastspring/graphs/contributors
[link-packagist]: https://packagist.org/packages/22digital/laravel-cashier-fastspring
[link-build]: https://scrutinizer-ci.com/g/22digital/laravel-cashier-fastspring/build-status/master
[link-coverage]: https://scrutinizer-ci.com/g/22digital/laravel-cashier-fastspring/?branch=master
[link-license]: https://github.com/22digital/laravel-cashier-fastspring/blob/master/LICENSE
[link-laravel]: https://laravel.com/
[link-styleci]: https://github.styleci.io/repos/141720975
[link-styleci]: https://github.styleci.io/repos/219102431
[link-travis]: https://travis-ci.org/22digital/laravel-cashier-fastspring


[![Packagist][badge_package]][link-packagist]
[![Packagist][badge_packagist]][link-packagist]
[![Build Status][badge_build]][link-build]
[![Coverage Status][badge_coverage]][link-coverage]
[![Style CI][badge_styleci]][link-styleci]
Expand Down
2 changes: 1 addition & 1 deletion src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function subscribedToPlan($plans, $subscription = 'default')
*/
public function onPlan($plan)
{
return !is_null($this->subscriptions->first(function($value) use ($plan) {
return !is_null($this->subscriptions->first(function ($value) use ($plan) {
return $value->plan === $plan && $value->valid();
}));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public function testActivePeriodOrCreateWithNonExistIntervalUnit()
'interval_unit' => 'martian-second',
]);

if ($activePeriod) {
return $activePeriod;
}

$activePeriod = $subscription->activePeriodOrCreate();
}

Expand Down
43 changes: 40 additions & 3 deletions tests/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class WebhookControllerTest extends TestCase
{
/**
* Class constructor.
*
* @return void
*/
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
Expand All @@ -20,6 +25,11 @@ public static function setUpBeforeClass()
}
}

/**
* Test HMAC.
*
* @return \Illuminate\Http\Response
*/
public function testHmac()
{
$hmacSecret = 'dontlookiamsecret';
Expand Down Expand Up @@ -50,6 +60,12 @@ public function testHmac()
$this->assertEquals($response->getStatusCode(), 202);
}

/**
* Test HMAC failed.
*
* @throws \Exception $exception
* @return \Illuminate\Http\Response
*/
public function testHmacFailed()
{
Config::set('services.fastspring.hmac_secret', 'dontlookiamsecret');
Expand Down Expand Up @@ -107,6 +123,11 @@ public function testMultipleWebhookEvents()
$this->assertEquals($content, "id-1\nid-2");
}

/**
* Test multiple webhook events by failing one.
*
* @return void
*/
public function testMultipleWebhookEventsByFailingOne()
{
$webhookRequestPayload = [
Expand Down Expand Up @@ -145,6 +166,11 @@ public function testMultipleWebhookEventsByFailingOne()
$this->assertEquals($content, 'id-1');
}

/**
* Webhook test events.
*
* @return \TwentyTwoDigital\CashierFastspring\Tests\WebhookControllerTest\sendRequestAndListenEvents
*/
public function testWebhooksEvents()
{
$webhookEvents = [
Expand Down Expand Up @@ -199,6 +225,14 @@ public function testWebhooksEvents()
}
}

/**
* Sends request and listen for events.
*
* @param array $mockEvent The mock event array
* @param array $listenEvents The listen events
*
* @return \Illuminate\Support\Facades\Event
*/
protected function sendRequestAndListenEvents($mockEvent, $listenEvents)
{
Event::fake();
Expand All @@ -215,9 +249,12 @@ protected function sendRequestAndListenEvents($mockEvent, $listenEvents)

foreach ($listenEvents as $listenEvent) {
// Assert
Event::assertDispatched($listenEvent, function ($event) use ($mockEvent) {
return (int) $event->id === (int) $mockEvent['id'];
});
Event::assertDispatched(
$listenEvent,
function ($event) use ($mockEvent) {
return (int) $event->id === (int) $mockEvent['id'];
}
);
}
}
}

0 comments on commit dd1ffcb

Please sign in to comment.