Skip to content

Commit e55e4b6

Browse files
committed
update tests for phpunit
1 parent 6ab9e44 commit e55e4b6

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ CONSOLE=cd tests/Application && php bin/console -e test
66
COMPOSER=cd tests/Application && composer
77
YARN=cd tests/Application && yarn
88

9-
SYLIUS_VERSION=1.12.0
10-
SYMFONY_VERSION=6.3
9+
SYLIUS_VERSION=1.13.0
10+
SYMFONY_VERSION=6.4
1111
PHP_VERSION=8.2
1212
PLUGIN_NAME=sylius/bootstrap-theme
1313

@@ -65,6 +65,9 @@ endif
6565
echo " bootstrapTheme:" >> ${TEST_DIRECTORY}/config/packages/assets.yaml
6666
echo " json_manifest_path: '%kernel.project_dir%/public/themes/bootstrap-theme/manifest.json'" >> ${TEST_DIRECTORY}/config/packages/assets.yaml
6767
echo " bootstrapTheme: '%kernel.project_dir%/public/themes/bootstrap-theme'" >> ${TEST_DIRECTORY}/config/packages/webpack_encore.yaml
68+
# Thanks PHPUnit v10
69+
cd ${TEST_DIRECTORY} && php -r '$$json = json_decode(file_get_contents ("composer.json"), true); $$json["autoload-dev"]["psr-4"]["Tests\\BootstrapTheme\\"] = "vendor/sylius/bootstrap-theme/tests/PHPUnit/"; file_put_contents("composer.json", json_encode($$json, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));'
70+
${COMPOSER} install
6871

6972
install-sylius:
7073
${CONSOLE} doctrine:database:create --if-not-exists

tests/PHPUnit/ChangeThemeInAdminAreaTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use App\Entity\User\AdminUser;
88
use Doctrine\ORM\EntityManager;
99
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
10+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1011
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1112

1213
/**
1314
* @internal
1415
*/
15-
final class ChangeThemeInAdminAreaTest extends AbstractTest
16+
final class ChangeThemeInAdminAreaTest extends WebTestCase
1617
{
18+
use SetupTrait;
1719
private KernelBrowser $client;
1820

1921
protected function setUp(): void

tests/PHPUnit/PagesCanBeAccessedTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
use App\Entity\User\ShopUser;
1010
use Doctrine\ORM\EntityManager;
1111
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
12+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1213
use 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;
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66

77
use Doctrine\ORM\EntityManager;
88
use Sylius\Component\Core\Model\Channel;
9-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
109

1110
/**
1211
* @internal
1312
*/
14-
abstract class AbstractTest extends WebTestCase
13+
trait SetupTrait
1514
{
16-
protected function getChannel(): Channel
15+
public function getChannel(): Channel
1716
{
1817
/** @var EntityManager $manager */
1918
$manager = $this->getContainer()->get('doctrine')->getManager();
2019

2120
return $manager->getRepository(Channel::class)->findOneBy([]);
2221
}
2322

24-
protected function useNoneTheme(): void
23+
public function useNoneTheme(): void
2524
{
2625
$this->switchTheme(null);
2726
}
2827

29-
protected function useBootstrapTheme(): void
28+
public function useBootstrapTheme(): void
3029
{
3130
$this->switchTheme('sylius/bootstrap-theme');
3231
}

0 commit comments

Comments
 (0)