-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
on: push | ||
name: CI | ||
jobs: | ||
pest: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: kirschbaumdevelopment/laravel-test-runner:8.1 | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Install composer dependencies | ||
run: | | ||
composer install --no-scripts | ||
- name: Run Testsuite | ||
run: vendor/bin/pest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
vendor | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "jonpurvis/faker-stripe", | ||
"description": "Faker provider for generating fake Stripe IDs", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jon Purvis" | ||
} | ||
], | ||
"keywords": [ | ||
"stripe", | ||
"faker" | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"fakerphp/faker": "^1.10" | ||
}, | ||
"require-dev": { | ||
"pestphp/pest": "^2.6", | ||
"pestphp/pest-plugin-faker": "^2.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Faker\\Provider\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Faker\\Tests\\Provider\\": "tests/Faker" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage/> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Faker\Provider; | ||
|
||
class Stripe extends Base | ||
{ | ||
private function generateRandomString($length = 24): string | ||
{ | ||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
$string = ''; | ||
$max = strlen($characters) - 1; | ||
|
||
for ($i = 0; $i < $length; $i++) { | ||
$string .= $characters[mt_rand(0, $max)]; | ||
} | ||
|
||
return $string; | ||
} | ||
public function stripeAccountId(): string | ||
{ | ||
return 'acct_'.$this->generateRandomString(16); | ||
} | ||
|
||
public function stripeBalanceTransactionId(): string | ||
{ | ||
return 'txn_'.$this->generateRandomString(25); | ||
} | ||
|
||
public function stripeChargeId(): string | ||
{ | ||
return 'ch_'.$this->generateRandomString(); | ||
} | ||
|
||
public function stripeCustomerId(): string | ||
{ | ||
return 'cus_'.$this->generateRandomString(14); | ||
} | ||
|
||
public function stripeFeeId(): string | ||
{ | ||
return 'fee_'.$this->generateRandomString(); | ||
} | ||
|
||
public function stripeInvoiceId(): string | ||
{ | ||
return 'in_'.$this->generateRandomString(); | ||
} | ||
|
||
public function stripeInvoiceItemId(): string | ||
{ | ||
return 'ii_'.$this->generateRandomString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Faker\Provider\Stripe; | ||
use function Pest\Faker\fake; | ||
|
||
beforeEach(function () { | ||
$this->fake = fake(); | ||
$this->fake->addProvider(new Stripe($this->fake)); | ||
}); | ||
|
||
it('generates an account id', function () { | ||
expect($this->fake->stripeAccountId())->toStartWith('acct_')->toHaveLength(21); | ||
}); | ||
|
||
it('generates a balance transaction id', function () { | ||
expect($this->fake->stripeBalanceTransactionId())->toStartWith('txn_')->toHaveLength(29); | ||
}); | ||
|
||
it('generates a charge id', function () { | ||
expect($this->fake->stripeChargeId())->toStartWith('ch_')->toHaveLength(27); | ||
}); | ||
|
||
it('generates a customer id', function () { | ||
expect($this->fake->stripeCustomerId())->toStartWith('cus_')->toHaveLength(18); | ||
}); | ||
|
||
it('generates a fee id', function () { | ||
expect($this->fake->stripeFeeId())->toStartWith('fee_')->toHaveLength(28); | ||
}); | ||
|
||
it('generates an invoice id', function () { | ||
expect($this->fake->stripeInvoiceId())->toStartWith('in_')->toHaveLength(27); | ||
}); | ||
|
||
it('generates an invoice item id', function () { | ||
expect($this->fake->stripeInvoiceItemId())->toStartWith('ii_')->toHaveLength(27); | ||
}); |