Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating carbon and phpdotenv #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": ">=7.1.3",
"illuminate/database": "~5.6",
"illuminate/support": "~5.6",
"nesbot/carbon": "~1.0",
"nesbot/carbon": "~2.0",
"symfony/http-kernel": "~2.7|~3.0|~4.0",
"guzzlehttp/guzzle": "^6.0"
},
Expand All @@ -26,7 +26,7 @@
"illuminate/routing": "~5.6",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~7.0",
"vlucas/phpdotenv": "~2.0",
"vlucas/phpdotenv": "^3.3",
"orchestra/testbench": "~3.6"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
67 changes: 38 additions & 29 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Str;
use Log;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -16,7 +17,9 @@ class WebhookController extends Controller
/**
* Handle a Fastspring webhook call.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request The webhook requet
*
* @throws Exception
*
* @return \Symfony\Component\HttpFoundation\Response
*/
Expand Down Expand Up @@ -53,11 +56,11 @@ public function handleWebhook(Request $request)
// prepare category event class names like OrderAny
$explodedType = explode('.', $event['type']);
$category = array_shift($explodedType);
$categoryEvent = '\Bgultekin\CashierFastspring\Events\\'.studly_case($category).'Any';
$categoryEvent = '\Bgultekin\CashierFastspring\Events\\'.Str::studly($category).'Any';

// prepare category event class names like activity
$activity = str_replace('.', ' ', $event['type']);
$activityEvent = '\Bgultekin\CashierFastspring\Events\\'.studly_case($activity);
$activityEvent = '\Bgultekin\CashierFastspring\Events\\'.Str::studly($activity);

// there may be some exceptions on events
// so if anything goes bad its ID won't be added on the successfullEvents
Expand All @@ -71,32 +74,38 @@ public function handleWebhook(Request $request)
}

// trigger events
Event::fire(new Events\Any(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
));

Event::fire(new $categoryEvent(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
));

Event::fire(new $activityEvent(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
));
Event::dispatch(
new Events\Any(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
)
);

Event::dispatch(
new $categoryEvent(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
)
);

Event::dispatch(
new $activityEvent(
$event['id'],
$event['type'],
$event['live'],
$event['processed'],
$event['created'],
$event['data']
)
);

// add event id to successful events
$successfulEvents[] = $event['id'];
Expand Down
4 changes: 2 additions & 2 deletions tests/CashierFastspringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class CashierFastspringTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
4 changes: 2 additions & 2 deletions tests/FastspringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class FastspringTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
// prepare class for testing
$mock = new MockHandler(array_fill(
Expand Down
4 changes: 2 additions & 2 deletions tests/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class InvoiceTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
4 changes: 2 additions & 2 deletions tests/ListenersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class ListenersTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ServiceProviderTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/SubscriptionPeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class SubscriptionPeriodTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
4 changes: 2 additions & 2 deletions tests/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class SubscriptionTest extends TestCase
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Traits/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function getEnvironmentSetUp($app)
]);
}

public function tearDown()
public function tearDown(): void
{
Schema::drop('users');
Schema::drop('subscriptions');
Expand Down
7 changes: 4 additions & 3 deletions tests/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Str;
use Orchestra\Testbench\TestCase;

class WebhookControllerTest extends TestCase
{
public static function setUpBeforeClass()
{
if (file_exists(__DIR__.'/.env')) {
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv = \Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
}
}
Expand Down Expand Up @@ -182,11 +183,11 @@ public function testWebhooksEvents()
// prepare category event class names like OrderAny
$explodedType = explode('.', $mockEvent['type']);
$category = array_shift($explodedType);
$categoryEvent = 'Bgultekin\CashierFastspring\Events\\'.studly_case($category).'Any';
$categoryEvent = 'Bgultekin\CashierFastspring\Events\\'.Str::studly($category).'Any';

// prepare category event class names like activity
$activity = str_replace('.', ' ', $mockEvent['type']);
$activityEvent = 'Bgultekin\CashierFastspring\Events\\'.studly_case($activity);
$activityEvent = 'Bgultekin\CashierFastspring\Events\\'.Str::studly($activity);

$listenEvents = [
Events\Any::class,
Expand Down