All Projects → helpscout → specter-php

helpscout / specter-php

Licence: MIT license
JSON Mocking and Testing for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to specter-php

php-test-generator
Generate test cases for existing PHP files
Stars: ✭ 47 (+161.11%)
Mutual labels:  phpunit, mocking
Bypass Finals
Removes final keywords from source code on-the-fly and allows mocking of final methods and classes. It can be used together with any test tool such as PHPUnit or Mockery.
Stars: ✭ 228 (+1166.67%)
Mutual labels:  phpunit, mocking
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+55722.22%)
Mutual labels:  phpunit, mocking
Phpunit Pretty Print
✅  Make your PHPUnit output beautiful
Stars: ✭ 149 (+727.78%)
Mutual labels:  phpunit
Phpunit Bridge
Provides utilities for PHPUnit, especially user deprecation notices management.
Stars: ✭ 2,150 (+11844.44%)
Mutual labels:  phpunit
aem-stubs
Tool for providing sample data for AEM applications in a simple and flexible way. Stubbing server on AEM, no separate needed.
Stars: ✭ 40 (+122.22%)
Mutual labels:  mocking
intellij-drupal-run-tests
Provides a run configuration that executes Drupal's test runner (for Simpletest, Unit, Kernel, Functional, FunctionalJavascript.)
Stars: ✭ 24 (+33.33%)
Mutual labels:  phpunit
Phpunit Accelerator
Listeners to speed up PHPUnit tests
Stars: ✭ 139 (+672.22%)
Mutual labels:  phpunit
universalmock
A universal mock class in Apex
Stars: ✭ 55 (+205.56%)
Mutual labels:  mocking
go-github-mock
A library to aid unittesting code that uses Golang's Github SDK
Stars: ✭ 63 (+250%)
Mutual labels:  mocking
Phpstan Phpunit
PHPUnit extensions and rules for PHPStan
Stars: ✭ 247 (+1272.22%)
Mutual labels:  phpunit
Brainmonkey
Mocking utility for PHP functions and WordPress plugin API
Stars: ✭ 191 (+961.11%)
Mutual labels:  phpunit
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+311.11%)
Mutual labels:  mocking
Coveragechecker
Allows old code to use new standards
Stars: ✭ 159 (+783.33%)
Mutual labels:  phpunit
dummy
Run mock server based off an API contract with one command
Stars: ✭ 170 (+844.44%)
Mutual labels:  mocking
Specify
BDD style code blocks for PHPUnit / Codeception
Stars: ✭ 141 (+683.33%)
Mutual labels:  phpunit
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (+72.22%)
Mutual labels:  mocking
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+1177.78%)
Mutual labels:  phpunit
PhpUnitAssertException
Assert exception/throwable/error PHPUnit trait
Stars: ✭ 18 (+0%)
Mutual labels:  phpunit
Deflector.NET
A library for intercepting all method calls at runtime in nearly any .NET application.
Stars: ✭ 80 (+344.44%)
Mutual labels:  mocking

Specter Build Status Code Climate Test Coverage

Mocking and Testing for PHP Use a single JSON file to generate mock data and as an integration test assertion

Modern development is complicated. This project decouples front end and back end development by providing fixture data and a testing spec with a single file.

  1. Client and Server teams build a JSON spec file together
  2. Mock the endpoint, and have it return that spec file and add the Specter Middleware to convert that spec file into a response filled with random, but sane, data
  3. The client team can begin development with this endpoint, and iterate over any changes with the JSON spec. The endpoint delivers real data, and they can set a SpecterSeed header to get repeatable results.
  4. The server team can then implement the actual endpoint to meet that spec at their own pace, perhaps in the next sprint. They can use the same spec file to drive an PHPUnit integration test by handing the spec file to the SpecterTestTrait

This lets the teams rapidly create an endpoint specification together, the front end team uses the data from it, and the platform team tests with it.

Installation

This is available through composer as helpscout/specter-php.

Contributing

  1. git clone
  2. composer install
  3. It will prompt you to please install our commit hooks driven by pre-commit.

Demonstration

Work together among your development teams to spec a new endpoint and create a Specter JSON file that defines your new endpoint. This is a Specter JSON file:

{
  "__specter": "Sample customer record",
  "id": "@randomDigitNotNull@",
  "fname": "@firstName@",
  "lname": "@lastName@",
  "company": "@company@",
  "jobTitle": "@jobTitle@",
  "background": "@catchPhrase@",
  "address": {
    "city": "@city@",
    "state": "@stateAbbr@",
    "zip": "@postcode@",
    "country": "@country@"
  },
  "emails": ["@companyEmail@", "@freeEmail@", "@email@" ]
}

Add a route to return it and use SpecterMiddleware to process it:

$app->get('/api/v1/customer/{id}', function ($request, $response, $args) {
    return $response->withJson(getFixture('customer'));
})->add(new \HelpScout\Specter\SpecterMiddleware);

Receive random data from your endpoint that fulfills the JSON and use it to build out your interface:

{
   "__specter":"Sample customer record",
   "id":6,
   "fname":"Glenda",
   "lname":"Trantow",
   "company":"Kerluke, Rodriguez and Wisoky",
   "jobTitle":"Power Generating Plant Operator",
   "background":"Configurable multi-state standardization",
   "address":{
      "city":"Georgiannachester",
      "state":"TX",
      "zip":"89501",
      "country":"Afghanistan"
   },
   "emails":[
      "[email protected]",
      "[email protected]",
      "[email protected]"
   ]
}

Write a unit test for the endpoint to confirm that it's meeting the spec, and then implement the endpoint for real:

use SpecterTestTrait;

public function testCustomerRouteMeetsSpec()
{
    self::assertResponseContent(
        $this->client->get('/api/v1/customer/37'),
        'customer'
    );
}

Custom Formatters

In addition to the Faker library, Specter provides a few other fomatters that offer some useful mocking.

  • randomRobotAvatar
  • randomGravatar
  • relatedElement
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].