new: pkg: add test cases to back-end w/ real database connection in it #10
This commit is contained in:
55
tests/Factory/ContactMessageFactory.php
Normal file
55
tests/Factory/ContactMessageFactory.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\ContactMessage;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class ContactMessageFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<ContactMessage>
|
||||
*/
|
||||
class ContactMessageFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'name' => self::faker()->name(),
|
||||
'email' => self::faker()->safeEmail(),
|
||||
'content' => self::faker()->paragraph(3),
|
||||
'consent' => true,
|
||||
'ipAddress' => self::faker()->ipv4(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return ContactMessage::class;
|
||||
}
|
||||
|
||||
public function withoutConsent(): self
|
||||
{
|
||||
return $this->with(['consent' => false]);
|
||||
}
|
||||
|
||||
public function anonymous(): self
|
||||
{
|
||||
return $this->with(['ipAddress' => null]);
|
||||
}
|
||||
}
|
||||
51
tests/Factory/GamerFactory.php
Normal file
51
tests/Factory/GamerFactory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\Gamer;
|
||||
use DateTime;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class GamerFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<Gamer>
|
||||
*/
|
||||
class GamerFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'userName' => self::faker()->userName(),
|
||||
'ip' => self::faker()->ipv4(),
|
||||
'country' => self::faker()->countryCode(),
|
||||
'userAgent' => self::faker()->userAgent(),
|
||||
'connTimestamp' => new DateTime(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return Gamer::class;
|
||||
}
|
||||
|
||||
public function anonymous(): self
|
||||
{
|
||||
return $this->with(['userName' => sprintf('Guest_%d', self::faker()->randomNumber(5))]);
|
||||
}
|
||||
}
|
||||
53
tests/Factory/GridFactory.php
Normal file
53
tests/Factory/GridFactory.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\Grid;
|
||||
use App\Entity\GridRow;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class GridFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<Grid>
|
||||
*/
|
||||
class GridFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'playedGame' => PlayedGameFactory::new(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return Grid::class;
|
||||
}
|
||||
|
||||
protected function initialize(): static
|
||||
{
|
||||
return $this->afterInstantiate(function (Grid $grid): void {
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
/** @var GridRow $factory */
|
||||
$factory = GridRowFactory::new()->create()->_real();
|
||||
$grid->addGridRow($factory);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
52
tests/Factory/GridRowFactory.php
Normal file
52
tests/Factory/GridRowFactory.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\GridRow;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class GridRowFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<GridRow>
|
||||
*/
|
||||
class GridRowFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$columns[] = self::faker()->numberBetween(0, 8);
|
||||
}
|
||||
|
||||
return [
|
||||
'gridCol' => $columns,
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return GridRow::class;
|
||||
}
|
||||
|
||||
public function withColumns(array $columns): self
|
||||
{
|
||||
return $this->with(['gridCol' => $columns]);
|
||||
}
|
||||
}
|
||||
108
tests/Factory/PlayedGameFactory.php
Normal file
108
tests/Factory/PlayedGameFactory.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\PlayedGame;
|
||||
use DateTime;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class PlayedGameFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<PlayedGame>
|
||||
*/
|
||||
class PlayedGameFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => Uuid::v4(),
|
||||
'gameAssoc' => self::faker()->uuid(),
|
||||
'redPoints' => self::faker()->numberBetween(0, 51),
|
||||
'bluePoints' => self::faker()->numberBetween(0, 51),
|
||||
'redExplodedBomb' => false,
|
||||
'blueExplodedBomb' => false,
|
||||
'resign' => null,
|
||||
'redBonusPoints' => self::faker()->randomFloat(2, 0, 100),
|
||||
'blueBonusPoints' => self::faker()->randomFloat(2, 0, 100),
|
||||
'redBonusStats' => null,
|
||||
'blueBonusStats' => null,
|
||||
'created' => new DateTime(),
|
||||
'updated' => new DateTime(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return PlayedGame::class;
|
||||
}
|
||||
|
||||
public function withRegisteredPlayers(): self
|
||||
{
|
||||
return $this->with([
|
||||
'red' => UserFactory::new(),
|
||||
'blue' => UserFactory::new(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withAnonymousPlayers(): self
|
||||
{
|
||||
return $this->with([
|
||||
'redAnon' => GamerFactory::new(),
|
||||
'blueAnon' => GamerFactory::new(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withMixedPlayers(): self
|
||||
{
|
||||
return $this->with([
|
||||
'red' => UserFactory::new(),
|
||||
'blueAnon' => GamerFactory::new(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function finished(): self
|
||||
{
|
||||
return $this->with([
|
||||
'redPoints' => 26,
|
||||
'bluePoints' => 25,
|
||||
]);
|
||||
}
|
||||
|
||||
public function redWins(): self
|
||||
{
|
||||
return $this->with([
|
||||
'redPoints' => 26,
|
||||
'bluePoints' => self::faker()->numberBetween(0, 25),
|
||||
]);
|
||||
}
|
||||
|
||||
public function blueWins(): self
|
||||
{
|
||||
return $this->with([
|
||||
'redPoints' => self::faker()->numberBetween(0, 25),
|
||||
'bluePoints' => 26,
|
||||
]);
|
||||
}
|
||||
|
||||
public function resigned(string $player): self
|
||||
{
|
||||
return $this->with(['resign' => $player]);
|
||||
}
|
||||
}
|
||||
68
tests/Factory/StepFactory.php
Normal file
68
tests/Factory/StepFactory.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\Step;
|
||||
use DateTime;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class StepFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<Step>
|
||||
*/
|
||||
class StepFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'row' => self::faker()->numberBetween(0, 15),
|
||||
'col' => self::faker()->numberBetween(0, 15),
|
||||
'wBomb' => self::faker()->boolean(),
|
||||
'player' => self::faker()->randomElement(['red', 'blue']),
|
||||
'revealedCells' => null,
|
||||
'playedGame' => PlayedGameFactory::new(),
|
||||
'created' => new DateTime(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return Step::class;
|
||||
}
|
||||
|
||||
public function mine(): self
|
||||
{
|
||||
return $this->with(['wBomb' => true]);
|
||||
}
|
||||
|
||||
public function safe(): self
|
||||
{
|
||||
return $this->with(['wBomb' => false]);
|
||||
}
|
||||
|
||||
public function forPlayer(string $player): self
|
||||
{
|
||||
return $this->with(['player' => $player]);
|
||||
}
|
||||
|
||||
public function withRevealedCells(array $cells): self
|
||||
{
|
||||
return $this->with(['revealedCells' => $cells]);
|
||||
}
|
||||
}
|
||||
60
tests/Factory/UserFactory.php
Normal file
60
tests/Factory/UserFactory.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\User;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class UserFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<User>
|
||||
*/
|
||||
class UserFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'username' => self::faker()->unique()->userName(),
|
||||
'email' => self::faker()->unique()->safeEmail(),
|
||||
'password' => 'hashedpassword',
|
||||
'isVerified' => true,
|
||||
'roles' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return User::class;
|
||||
}
|
||||
|
||||
public function withPassword(string $hashedPassword): self
|
||||
{
|
||||
return $this->with(['password' => $hashedPassword]);
|
||||
}
|
||||
|
||||
public function unverified(): self
|
||||
{
|
||||
return $this->with(['isVerified' => false]);
|
||||
}
|
||||
|
||||
public function withRoles(array $roles): self
|
||||
{
|
||||
return $this->with(['roles' => $roles]);
|
||||
}
|
||||
}
|
||||
62
tests/Factory/WebAuthnCredentialFactory.php
Normal file
62
tests/Factory/WebAuthnCredentialFactory.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Factory;
|
||||
|
||||
use App\Entity\WebAuthnCredential;
|
||||
use DateTime;
|
||||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
|
||||
|
||||
/**
|
||||
* Class WebAuthnCredentialFactory
|
||||
*
|
||||
* @package App\Tests\Factory
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*
|
||||
* @extends PersistentProxyObjectFactory<WebAuthnCredential>
|
||||
*/
|
||||
class WebAuthnCredentialFactory extends PersistentProxyObjectFactory
|
||||
{
|
||||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'user' => UserFactory::new(),
|
||||
'credentialData' => json_encode([
|
||||
'type' => 'public-key',
|
||||
'id' => base64_encode(self::faker()->uuid()),
|
||||
'transports' => ['usb', 'nfc'],
|
||||
], JSON_THROW_ON_ERROR),
|
||||
'credentialName' => self::faker()->words(3, true),
|
||||
'createdAt' => new DateTime(),
|
||||
'lastUsedAt' => null,
|
||||
'isBackupEligible' => self::faker()->boolean(),
|
||||
'isBackupAuthenticated' => self::faker()->boolean(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function class(): string
|
||||
{
|
||||
return WebAuthnCredential::class;
|
||||
}
|
||||
|
||||
public function withName(string $name): self
|
||||
{
|
||||
return $this->with(['credentialName' => $name]);
|
||||
}
|
||||
|
||||
public function recentlyUsed(): self
|
||||
{
|
||||
return $this->with(['lastUsedAt' => new DateTime()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user