99use App \Entity \User \ShopUser ;
1010use Doctrine \ORM \EntityManager ;
1111use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
12+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
1213use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
1314
1415/**
1516 * @internal
1617 */
17- final class PagesCanBeAccessedTest extends AbstractTest
18+ final class PagesCanBeAccessedTest extends WebTestCase
1819{
20+ use SetupTrait;
21+
1922 private KernelBrowser $ client ;
2023
2124 protected function setUp (): void
@@ -64,7 +67,7 @@ public function testAccountPagesCanBeAccessed(string $routeName, array $params):
6467 self ::assertPageTitleContains ('Fashion Web Store ' );
6568 }
6669
67- public function guestPagesProvider (): \Generator
70+ public static function guestPagesProvider (): \Generator
6871 {
6972 yield 'sylius_shop_homepage ' => ['sylius_shop_homepage ' , []];
7073 yield 'sylius_shop_contact_request ' => ['sylius_shop_contact_request ' , []];
@@ -81,7 +84,7 @@ public function guestPagesProvider(): \Generator
8184 yield 'sylius_shop_cart_summary ' => ['sylius_shop_cart_summary ' , []];
8285 }
8386
84- public function accountPagesProvider (): \Generator
87+ public static function accountPagesProvider (): \Generator
8588 {
8689 yield 'sylius_shop_account_dashboard ' => ['sylius_shop_account_dashboard ' , []];
8790 yield 'sylius_shop_account_profile_update ' => ['sylius_shop_account_profile_update ' , []];
@@ -100,8 +103,18 @@ private function shopUserLogin(): ShopUser
100103 {
101104 /** @var EntityManager $manager */
102105 $ manager = $ this ->getContainer ()->get ('doctrine ' )->getManager ();
106+ $ customerId = 1 ;
107+
108+ do {
109+ $ user = $ manager ->getRepository (ShopUser::class)->find ($ customerId );
110+ $ orders = $ manager ->getRepository (Order::class)->findByCustomer ($ user ->getCustomer ());
111+ $ customerId ++;
112+
113+ if (20 <= $ customerId ) {
114+ throw new \Exception ('No order found for user ' );
115+ }
116+ } while (0 === count ($ orders ));
103117
104- $ user = $ manager ->getRepository (ShopUser::class)->findOneBy ([]);
105118 $ this ->client ->loginUser ($ user , 'shop ' );
106119
107120 return $ user ;
0 commit comments