henryruhs / phpunit-autoprovide
Magic helper to autoload CSV, JSON, PHP, XML and YAML data provider in PHPUnit
Fund package maintenance!
henryruhs
paypal.me/henryruhs
Requires
- php: ^8
- phpunit/phpunit: ^9
- symfony/property-access: ^6
- symfony/serializer: ^6
- symfony/yaml: ^6
Requires (Dev)
- isnotdefined/phpcs-config: 2.0.0
- squizlabs/php_codesniffer: 3.6.2
This package is auto-updated.
Last update: 2024-05-14 11:03:34 UTC
README
Magic helper to autoload CSV, JSON, PHP, XML and YAML data provider in PHPUnit.
Installation
composer require henryruhs/phpunit-autoprovide
Setup
Create the TestCaseAbstract
for your testing suite:
<?php namespace ExampleProject\Tests; use PHPUnitAutoProvide; /** * TestCaseAbstract * * @package ExampleProject * @category Tests */ abstract class TestCaseAbstract extends PHPUnitAutoProvide\TestCaseAbstract { /** * directory of the provider */ protected $_providerDirectory = 'tests' . DIRECTORY_SEPARATOR . 'provider'; /** * namespace of the testing suite */ protected $_testNamespace = __NAMESPACE__; }
Usage
Extend ExampleTest
from TestCaseAbstract
and set @dataProvider
as needed:
<?php namespace ExampleProject\Tests; /** * ExampleTest * * @package ExampleProject * @category Tests */ class ExampleTest extends TestCaseAbstract { /** * testMethod * * @param string $expect * * @dataProvider autoProvide */ public function testMethod(string $expect) : void { $this->assertEquals($expect, 'test'); } }
Create the ExampleTest{_testMethod}.{csv|json|php|xml|yml}
file:
[
[
"test"
]
]