Skip to content

Commit

Permalink
update tests for phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
oallain committed Jun 5, 2024
1 parent 6ab9e44 commit e55e4b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CONSOLE=cd tests/Application && php bin/console -e test
COMPOSER=cd tests/Application && composer
YARN=cd tests/Application && yarn

SYLIUS_VERSION=1.12.0
SYMFONY_VERSION=6.3
SYLIUS_VERSION=1.13.0
SYMFONY_VERSION=6.4
PHP_VERSION=8.2
PLUGIN_NAME=sylius/bootstrap-theme

Expand Down Expand Up @@ -65,6 +65,9 @@ endif
echo " bootstrapTheme:" >> ${TEST_DIRECTORY}/config/packages/assets.yaml
echo " json_manifest_path: '%kernel.project_dir%/public/themes/bootstrap-theme/manifest.json'" >> ${TEST_DIRECTORY}/config/packages/assets.yaml
echo " bootstrapTheme: '%kernel.project_dir%/public/themes/bootstrap-theme'" >> ${TEST_DIRECTORY}/config/packages/webpack_encore.yaml
# Thanks PHPUnit v10
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));'
${COMPOSER} install

install-sylius:
${CONSOLE} doctrine:database:create --if-not-exists
Expand Down
4 changes: 3 additions & 1 deletion tests/PHPUnit/ChangeThemeInAdminAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use App\Entity\User\AdminUser;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @internal
*/
final class ChangeThemeInAdminAreaTest extends AbstractTest
final class ChangeThemeInAdminAreaTest extends WebTestCase
{
use SetupTrait;
private KernelBrowser $client;

protected function setUp(): void
Expand Down
21 changes: 17 additions & 4 deletions tests/PHPUnit/PagesCanBeAccessedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use App\Entity\User\ShopUser;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @internal
*/
final class PagesCanBeAccessedTest extends AbstractTest
final class PagesCanBeAccessedTest extends WebTestCase
{
use SetupTrait;

private KernelBrowser $client;

protected function setUp(): void
Expand Down Expand Up @@ -64,7 +67,7 @@ public function testAccountPagesCanBeAccessed(string $routeName, array $params):
self::assertPageTitleContains('Fashion Web Store');
}

public function guestPagesProvider(): \Generator
public static function guestPagesProvider(): \Generator
{
yield 'sylius_shop_homepage' => ['sylius_shop_homepage', []];
yield 'sylius_shop_contact_request' => ['sylius_shop_contact_request', []];
Expand All @@ -81,7 +84,7 @@ public function guestPagesProvider(): \Generator
yield 'sylius_shop_cart_summary' => ['sylius_shop_cart_summary', []];
}

public function accountPagesProvider(): \Generator
public static function accountPagesProvider(): \Generator
{
yield 'sylius_shop_account_dashboard' => ['sylius_shop_account_dashboard', []];
yield 'sylius_shop_account_profile_update' => ['sylius_shop_account_profile_update', []];
Expand All @@ -100,8 +103,18 @@ private function shopUserLogin(): ShopUser
{
/** @var EntityManager $manager */
$manager = $this->getContainer()->get('doctrine')->getManager();
$customerId = 1;

do{
$user = $manager->getRepository(ShopUser::class)->find($customerId);
$orders = $manager->getRepository(Order::class)->findByCustomer($user->getCustomer());
$customerId++;

if (20 <= $customerId) {
throw new \Exception('No order found for user');
}
} while (0 === count($orders));

$user = $manager->getRepository(ShopUser::class)->findOneBy([]);
$this->client->loginUser($user, 'shop');

return $user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@

use Doctrine\ORM\EntityManager;
use Sylius\Component\Core\Model\Channel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* @internal
*/
abstract class AbstractTest extends WebTestCase
trait SetupTrait
{
protected function getChannel(): Channel
public function getChannel(): Channel
{
/** @var EntityManager $manager */
$manager = $this->getContainer()->get('doctrine')->getManager();

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

protected function useNoneTheme(): void
public function useNoneTheme(): void
{
$this->switchTheme(null);
}

protected function useBootstrapTheme(): void
public function useBootstrapTheme(): void
{
$this->switchTheme('sylius/bootstrap-theme');
}
Expand Down

0 comments on commit e55e4b6

Please sign in to comment.