Skip to content

Commit

Permalink
✅ [Admin] Add smoke tests for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAresu committed Mar 15, 2024
1 parent 89d67f1 commit f1b939d
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
run: vendor/bin/php-cs-fixer fix src -v --dry-run --stop-on-violation --using-cache=no
- name: Run Php-cs-fixer on tests
run: vendor/bin/php-cs-fixer fix tests -v --dry-run --stop-on-violation --using-cache=no
- name: Load fixtures
run: php bin/console doctrine:fixtures:load --env=test -n
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/simple-phpunit tests
- name: Run PhpStan
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SYMFONY = symfony
CONSOLE = $(SYMFONY) console
BIN = ./vendor/bin
RECTOR = $(BIN)/rector
PHPSTAN = $(BIN)/phpstan
Expand All @@ -9,6 +11,9 @@ DEPLOYER = $(BIN)/dep

cs: rector fix stan test

fixture:
@$(CONSOLE) doctrine:fixtures:load --env=test -n

test:
@$(PHPUNIT) tests

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"require-dev": {
"deployer/deployer": "^7.0.0",
"doctrine/doctrine-fixtures-bundle": "^3.5",
"friendsofphp/php-cs-fixer": "3.*",
"phpstan/phpstan": "1.10.*",
"phpstan/phpstan-doctrine": "1.3.*",
Expand Down
175 changes: 173 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ parameters:
level: 7
paths:
- ./src
- ./tests
bootstrapFiles:
- ./vendor/bin/.phpunit/phpunit/vendor/autoload.php
- ./vendor/autoload.php
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="disabled=1"/>
<server name="APP_DEBUG" value="false" force="true"/>
</php>

<testsuites>
Expand Down
30 changes: 30 additions & 0 deletions src/DataFixtures/UserFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\DataFixtures;

use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class UserFixtures extends Fixture
{
final public const PASSWORD_HASH = '$2y$13$te1UUDYPXELYC9jcVmil0.XQcmPValnWUN10VqDAJsh5zpnkiT9fm'; // = 'StrongPassword1!'
final public const ADMIN_USER_MAIL = '[email protected]';
final public const SUPER_ADMIN_USER_MAIL = '[email protected]';

public function load(ObjectManager $manager): void
{
$manager->persist($this->createUser(self::ADMIN_USER_MAIL, ['ROLE_ADMIN']));
$manager->persist($this->createUser(self::SUPER_ADMIN_USER_MAIL, ['ROLE_SUPER_ADMIN']));

$manager->flush();
}

/**
* @param string[] $roles
*/
private function createUser(string $email, array $roles): User
{
return (new User())->setEmail($email)->setRoles($roles)->setPassword(self::PASSWORD_HASH);
}
}
24 changes: 24 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
},
"files": [
"src/DataFixtures/AppFixtures.php"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.2",
"recipe": {
Expand Down Expand Up @@ -178,6 +190,18 @@
"phpdocumentor/type-resolver": {
"version": "1.0.1"
},
"phpstan/phpstan": {
"version": "1.10",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "1.0",
"ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767"
},
"files": [
"phpstan.dist.neon"
]
},
"psr/cache": {
"version": "1.0.1"
},
Expand Down
20 changes: 20 additions & 0 deletions tests/AuthenticatedTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Tests;

use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AuthenticatedTestCase extends WebTestCase
{
public function login(KernelBrowser $client, string $email): void
{
$userRepository = static::getContainer()->get(UserRepository::class);
$user = $userRepository->findOneBy(['email' => $email]);

if ($user) {
$client->loginUser($user);
}
}
}
Loading

0 comments on commit f1b939d

Please sign in to comment.