Skip to content

πŸ‘“ Provides a composer package with generic data providers for use with phpunit/phpunit.

License

Notifications You must be signed in to change notification settings

ergebnis/data-provider

Repository files navigation

data-provider

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with generic data providers for use with phpunit/phpunit.

Installation

Run

composer require ergebnis/data-provider

Usage

This package provides the following generic data providers:

Since it is possible to use multiple @dataProvider annotations or PHPUnit\Framework\Attribute\DataProviderExternal attributes for test methods, these generic data providers allow for reuse and composition of data providers:

<?php

declare(strict_types=1);

namespace Example\Test;

use Ergebnis\DataProvider;
use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    /**
     * @dataProvider \Ergebnis\DataProvider\StringProvider::blank()
     * @dataProvider \Ergebnis\DataProvider\StringProvider::empty()
     */
    public function testFromNameRejectsInvalidValueWithAnnotation(string $value): void
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Value can not be an empty or blank string.');

        UserName::fromString($value);
    }

    #[Framework\DataProviderExternal(DataProvider\StringProvider::class, 'blank')]
    #[Framework\DataProviderExternal(DataProvider\StringProvider::class, 'empty')]
    public function testFromNameRejectsInvalidValueWithAttribute(string $value): void
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Value can not be an empty or blank string.');

        UserName::fromString($value);
    }
}

DataProvider\BoolProvider

  • arbitrary() provides true, false
  • false() provides false
  • true() provides true

For examples, see Ergebnis\DataProvider\Test\Unit\BoolProviderTest.

DataProvider\FloatProvider

  • arbitrary() provides arbitrary floats
  • greaterThanOne() provides ints greater than 1.0
  • greaterThanZero() provides ints greater than 0.0
  • lessThanOne() provides ints less than 1.0
  • lessThanZero() provides ints less than 0.0
  • one() provides 1.0
  • zero() provides 0.0

For examples, see Ergebnis\DataProvider\Test\Unit\FloatProviderTest.

DataProvider\IntProvider

  • arbitrary() provides arbitrary ints
  • greaterThanOne() provides ints greater than 1
  • greaterThanZero() provides ints greater than 0
  • lessThanOne() provides ints less than 1
  • lessThanZero() provides ints less than 0
  • one() provides 1
  • zero() provides 0

For examples, see Ergebnis\DataProvider\Test\Unit\IntProviderTest.

DataProvider\NullProvider

  • null() provides null

For examples, see Ergebnis\DataProvider\Test\Unit\NullProviderTest.

DataProvider\ObjectProvider

  • object() provides an instance of stdClass

For examples, see Ergebnis\DataProvider\Test\Unit\ObjectProviderTest.

DataProvider\ResourceProvider

  • resource() provides a resource

For examples, see Ergebnis\DataProvider\Test\Unit\ResourceProviderTest.

DataProvider\StringProvider

  • arbitrary() provides arbitrary strings
  • blank() provides strings consisting of whitespace characters only
  • empty() provides an empty string
  • trimmed() provides non-empty, non-blank strings without leading and trailing whitespace
  • untrimmed() provides non-empty, non-blank strings with additional leading and trailing whitespace
  • withWhitespace() provides non-empty, non-blank, trimmed strings containing whitespace

For examples, see Ergebnis\DataProvider\Test\Unit\StringProviderTest.

DataProvider\UuidProvider

  • arbitrary() provides lower- and upper-case UUIDs
  • caseLower() provides a lower-case UUIDs
  • caseUpper() provides an upper-case UUIDs

For examples, see Ergebnis\DataProvider\Test\Unit\UuidProviderTest.

Changelog

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

Social

Follow @localheinz and @ergebnis on Twitter.

About

πŸ‘“ Provides a composer package with generic data providers for use with phpunit/phpunit.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published