-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ondřej Ešler
committed
Jun 25, 2024
1 parent
41b1ff5
commit fd966a4
Showing
7 changed files
with
101 additions
and
52 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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: '2' | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
|
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace IW\PHPUnit\DbFixtures; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final readonly class Fixtures | ||
{ | ||
public array $files; | ||
|
||
public function __construct(public string $label, public string $mode, string ...$files) { | ||
assert(!empty($label), 'No label given'); | ||
assert(in_array($mode, ['read-only', 'write']), 'Mode must be either "read-only" or "write"'); | ||
assert(!empty($files), 'No fixture files given'); | ||
|
||
foreach ($files as $file) { | ||
assert(!empty($file), 'Empty fixture file given'); | ||
} | ||
|
||
$this->files = $files; | ||
} | ||
|
||
public function mergeWith(Fixtures $fixtures) : Fixtures { | ||
assert($fixtures->label === $this->label, 'Cannot merge fixtures with different labels'); | ||
|
||
return new Fixtures( | ||
$this->label, | ||
in_array('write', [$fixtures->mode, $this->mode]) ? 'write' : 'read-only', | ||
array_values(array_unique(array_merge($fixtures->files, $this->files))), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace IW\PHPUnit\DbFixtures; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FixturesTest extends TestCase | ||
{ | ||
public function testCreate() : void { | ||
$fixtures = new Fixtures('mysql', 'write', 'foo.yaml', 'bar.json'); | ||
|
||
$this->assertSame('mysql', $fixtures->label); | ||
$this->assertSame('write', $fixtures->mode); | ||
$this->assertSame(['foo.yaml', 'bar.json'], $fixtures->files); | ||
} | ||
} |
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