Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPurvis committed May 15, 2023
1 parent 2910673 commit 16a49b2
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
vendor
.idea
37 changes: 37 additions & 0 deletions composer.json
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
}
}
}
15 changes: 15 additions & 0 deletions phpunit.xml
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>
53 changes: 53 additions & 0 deletions src/Stripe.php
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();
}
}
37 changes: 37 additions & 0 deletions tests/StripeTest.php
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);
});

0 comments on commit 16a49b2

Please sign in to comment.