-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: using factories in data providers (#707)
- Loading branch information
Showing
3 changed files
with
82 additions
and
7 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
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 |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
use Zenstruck\Foundry\Tests\Fixture\Object1; | ||
|
||
use function Zenstruck\Foundry\faker; | ||
|
||
/** | ||
* @author Nicolas PHILIPPE <[email protected]> | ||
* @requires PHPUnit 11.4 | ||
|
@@ -34,23 +36,21 @@ final class DataProviderForServiceFactoryInKernelTestCaseTest extends KernelTest | |
{ | ||
use Factories; | ||
|
||
/** | ||
* @test | ||
*/ | ||
#[Test] | ||
#[DataProvider('createObjectFromServiceFactoryInDataProvider')] | ||
public function it_can_create_one_object_in_data_provider(?Object1 $providedData): void | ||
public function it_can_create_one_object_in_data_provider(?Object1 $providedData, string $expected): void | ||
{ | ||
self::assertFalse(Configuration::instance()->inADataProvider()); | ||
|
||
self::assertInstanceOf(Object1::class, $providedData); | ||
$this->assertSame('router-constructor', $providedData->getProp1()); | ||
$this->assertSame($expected, $providedData->getProp1()); | ||
} | ||
|
||
public static function createObjectFromServiceFactoryInDataProvider(): iterable | ||
{ | ||
yield 'service factory' => [ | ||
Object1Factory::createOne(), | ||
Object1Factory::createOne(['prop1' => $prop1 = faker()->sentence()]), | ||
"$prop1-constructor" | ||
]; | ||
} | ||
} |
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