I have an acceptance test that requires some setup before it runs. Specifically, I need to start a new subscription in Stripe. I have a class that does this, but when I run the test, Codeception complains that core Laravel classes such as Config cannot be found.
Here's some code, reduced for clarity. First the test:
<?php
// app/tests/browser/stopAndResumeSubscriptionCept.php
use BBapp\providers\payment\stripe\StripeTestBiller;
use BBapp\providers\payment\SubscriptionPlan as Plan;
use BBapp\models\User;
$I = new WebGuy($scenario);
$I->wantTo('stop and then resume my subscription');
// First we need to make a subscription
$biller = new StripeTestBiller;
$user = User::whereEmail('foo@example.com')->first();
$result = $biller->startSubscription( Plan::monthly(), $user, null );
// Now do acceptance testing stuff
// ...
And here's the StripeTestBiller:
<?php namespace BBapp\providers\payment\stripe;
use BBapp\providers\payment\SubscriptionPlan as Plan;
use BBapp\models\User;
use App;
use Carbon\Carbon;
class StripeTestBiller extends StripeApi {
public function __construct()
{
parent::__construct();
}
public function startSubscription( Plan $plan, User $user, $token = null )
{
$subscription = Stripe_Customer::create([
'card' => [
'number' => '4242424242424242',
'exp_month' => '01',
'exp_year' => Carbon::now()->addYears(1)->year,
'cvc' => '123',
],
'plan' => $plan->id,
'email' => $user->email,
'metadata' => [
'user_id' => $user->id,
'environment' => App::environment(),
],
]);
return $subscription;
}
// Other methods here
}
Finally, the StripeApi class that StripeTestBiller extends:
<?php namespace BBapp\providers\payment\stripe;
use Config;
use Stripe;
class StripeApi implements StripeInterface {
public function __construct()
{
Stripe::setApiKey( Config::get('stripe.secretKey') );
}
// A load of API wrapper methods here
}
The error from the console says:
FATAL ERROR. TESTS NOT FINISHED.
Class 'Config' not found
in *[Path to laravel]*\laravel\app\BBapp\providers\payment\stripe\StripeApi.php:24
...where line 24 is the line in the constructor above.
Is this an autoloading issue? How can I get these classes loaded during acceptance tests?