File tree 9 files changed +126
-0
lines changed
9 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 15
15
/phpstan.neon export-ignore
16
16
/phpunit-dama-doctrine.xml.dist export-ignore
17
17
/phpunit.xml.dist export-ignore
18
+ /behat.yml.dist export-ignore
18
19
/tests export-ignore
20
+ /features export-ignore
Original file line number Diff line number Diff line change 1
1
/composer.lock
2
2
/phpunit.xml
3
3
/phpunit-dama-doctrine.xml
4
+ /behat.yml
4
5
/vendor /
5
6
/bin /tools /* /vendor /
6
7
/build /
Original file line number Diff line number Diff line change
1
+ default:
2
+ suites:
3
+ default:
4
+ contexts:
5
+ - Zenstruck\Foundry\Tests\Behat\TestContext
6
+ - Zenstruck\Foundry\Test\Behat\FactoriesContext
7
+ extensions:
8
+ FriendsOfBehat\SymfonyExtension:
9
+ kernel:
10
+ class: Zenstruck\Foundry\Tests\Fixtures\Kernel
Original file line number Diff line number Diff line change 28
28
"doctrine/doctrine-migrations-bundle" : " ^2.2|^3.0" ,
29
29
"doctrine/mongodb-odm-bundle" : " ^3.1|^4.2" ,
30
30
"doctrine/orm" : " ^2.7" ,
31
+ "friends-of-behat/symfony-extension" : " ^2.4" ,
31
32
"matthiasnoback/symfony-dependency-injection-test" : " ^4.1" ,
32
33
"symfony/framework-bundle" : " ^4.4|^5.0|^6.0" ,
33
34
"symfony/maker-bundle" : " ^1.30" ,
54
55
"App\\ Tests\\ " : " tests/Fixtures/tmp/tests"
55
56
}
56
57
},
58
+ "suggest" : {
59
+ "friends-of-behat/symfony-extension" : " To use the Behat contexts"
60
+ },
57
61
"extra" : {
58
62
"bamarni-bin" : {
59
63
"target-directory" : " bin/tools" ,
Original file line number Diff line number Diff line change
1
+ Feature : Foundry
2
+ Scenario : Ensure can create factories
3
+ Given there is 1 category
4
+ Then there is 1 category in the database
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Zenstruck \Foundry \Test \Behat ;
4
+
5
+ use Behat \Behat \Context \Context ;
6
+ use Psr \Container \ContainerInterface ;
7
+ use Zenstruck \Foundry \ChainManagerRegistry ;
8
+ use Zenstruck \Foundry \Factory ;
9
+ use Zenstruck \Foundry \Test \LazyManagerRegistry ;
10
+ use Zenstruck \Foundry \Test \TestState ;
11
+
12
+ /**
13
+ * @author Kevin Bond <[email protected] >
14
+ */
15
+ final class FactoriesContext implements Context
16
+ {
17
+ public function __construct (private ContainerInterface $ container )
18
+ {
19
+ }
20
+
21
+ /**
22
+ * @BeforeScenario
23
+ */
24
+ public function setUpFactories (): void
25
+ {
26
+ TestState::bootFromContainer ($ this ->container );
27
+ Factory::configuration ()->setManagerRegistry (
28
+ new LazyManagerRegistry (function (): ChainManagerRegistry {
29
+ return TestState::initializeChainManagerRegistry ($ this ->container );
30
+ })
31
+ );
32
+ }
33
+
34
+ /**
35
+ * @AfterScenario
36
+ */
37
+ public function tearDownFactories (): void
38
+ {
39
+ TestState::shutdownFoundry ();
40
+ }
41
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Zenstruck \Foundry \Test \Behat ;
4
+
5
+ use Behat \Behat \Context \Context ;
6
+ use Psr \Container \ContainerInterface ;
7
+ use Zenstruck \Foundry \Test \DatabaseResetter ;
8
+
9
+ /**
10
+ * @author Kevin Bond <[email protected] >
11
+ */
12
+ final class ResetDatabaseContext implements Context
13
+ {
14
+ public function __construct (private ContainerInterface $ container )
15
+ {
16
+ }
17
+
18
+ /**
19
+ * @BeforeSuite
20
+ */
21
+ public function resetDatabase (): void
22
+ {
23
+ DatabaseResetter::resetDatabase ($ this ->container ->get ('kernel ' ));
24
+ }
25
+
26
+ /**
27
+ * @BeforeScenario
28
+ */
29
+ public function resetSchema (): void
30
+ {
31
+ DatabaseResetter::resetSchema ($ this ->container ->get ('kernel ' ));
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Zenstruck \Foundry \Tests \Behat ;
4
+
5
+ use Behat \Behat \Context \Context ;
6
+ use Zenstruck \Foundry \Tests \Fixtures \Factories \CategoryFactory ;
7
+
8
+ /**
9
+ * @author Kevin Bond <[email protected] >
10
+ */
11
+ final class TestContext implements Context
12
+ {
13
+ /**
14
+ * @Given there is :count category
15
+ */
16
+ public function thereIsCategory (int $ count ): void
17
+ {
18
+ CategoryFactory::createMany ($ count );
19
+ }
20
+
21
+ /**
22
+ * @Then there is :count category in the database
23
+ */
24
+ public function thereIsCategoryInTheDatabase (int $ count ): void
25
+ {
26
+ CategoryFactory::assert ()->count ($ count );
27
+ }
28
+ }
Original file line number Diff line number Diff line change 6
6
use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
7
7
use Doctrine \Bundle \MigrationsBundle \DoctrineMigrationsBundle ;
8
8
use Doctrine \Bundle \MongoDBBundle \DoctrineMongoDBBundle ;
9
+ use FriendsOfBehat \SymfonyExtension \Bundle \FriendsOfBehatSymfonyExtensionBundle ;
9
10
use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
10
11
use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
11
12
use Symfony \Bundle \MakerBundle \MakerBundle ;
@@ -79,6 +80,8 @@ public function registerBundles(): iterable
79
80
if ($ this ->enableDoctrine && \getenv ('USE_ODM ' )) {
80
81
yield new DoctrineMongoDBBundle ();
81
82
}
83
+
84
+ yield new FriendsOfBehatSymfonyExtensionBundle ();
82
85
}
83
86
84
87
public function getCacheDir (): string
You can’t perform that action at this time.
0 commit comments