-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Showing
10 changed files
with
137 additions
and
0 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/composer.lock | ||
/phpunit.xml | ||
/phpunit-dama-doctrine.xml | ||
/behat.yml | ||
/vendor/ | ||
/bin/tools/*/vendor/ | ||
/build/ | ||
|
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,11 @@ | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- Zenstruck\Foundry\Tests\Behat\TestContext | ||
- Zenstruck\Foundry\Test\Behat\FactoriesContext | ||
extensions: | ||
FriendsOfBehat\SymfonyExtension: | ||
kernel: | ||
class: Zenstruck\Foundry\Tests\Fixtures\Kernel | ||
bootstrap: tests/bootstrap.php |
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,4 @@ | ||
Feature: Foundry | ||
Scenario: Ensure can create factories | ||
Given there is 1 category | ||
Then there is 1 category in the database |
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,41 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Foundry\Test\Behat; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Psr\Container\ContainerInterface; | ||
use Zenstruck\Foundry\ChainManagerRegistry; | ||
use Zenstruck\Foundry\Factory; | ||
use Zenstruck\Foundry\Test\LazyManagerRegistry; | ||
use Zenstruck\Foundry\Test\TestState; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class FactoriesContext implements Context | ||
{ | ||
public function __construct(private ContainerInterface $container) | ||
{ | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
public function setUpFactories(): void | ||
{ | ||
TestState::bootFromContainer($this->container); | ||
Factory::configuration()->setManagerRegistry( | ||
new LazyManagerRegistry(function (): ChainManagerRegistry { | ||
return TestState::initializeChainManagerRegistry($this->container); | ||
}) | ||
); | ||
} | ||
|
||
/** | ||
* @AfterScenario | ||
*/ | ||
public function tearDownFactories(): void | ||
{ | ||
TestState::shutdownFoundry(); | ||
} | ||
} |
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 | ||
|
||
namespace Zenstruck\Foundry\Test\Behat; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Psr\Container\ContainerInterface; | ||
use Zenstruck\Foundry\Test\DatabaseResetter; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class ResetDatabaseContext implements Context | ||
{ | ||
public function __construct(private ContainerInterface $container) | ||
{ | ||
} | ||
|
||
/** | ||
* @BeforeSuite | ||
*/ | ||
public function resetDatabase(): void | ||
{ | ||
DatabaseResetter::resetDatabase($this->container->get('kernel')); | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
public function resetSchema(): void | ||
{ | ||
DatabaseResetter::resetSchema($this->container->get('kernel')); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Foundry\Tests\Behat; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class TestContext implements Context | ||
{ | ||
/** | ||
* @Given there is :count category | ||
*/ | ||
public function thereIsCategory(int $count): void | ||
{ | ||
CategoryFactory::createMany($count); | ||
} | ||
|
||
/** | ||
* @Then there is :count category in the database | ||
*/ | ||
public function thereIsCategoryInTheDatabase(int $count): void | ||
{ | ||
CategoryFactory::assert()->count($count); | ||
} | ||
} |
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