Skip to content

Commit

Permalink
added test database; added user and client fixtures; added client ind…
Browse files Browse the repository at this point in the history
…ex and client creation tests
  • Loading branch information
msalakhov committed Mar 31, 2022
1 parent 6fd6b5c commit de1b859
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.idea
app/var/*
app/vendor/*
!db
db/*
!app/public
app/public/*
db_test
4 changes: 2 additions & 2 deletions app/.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ APP_SECRET=ccd80113c9ecc72e222101920ae5aa0a
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"
DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
DATABASE_URL="mysql://lux_admin:&pHDG3%LcV@database:3306/lux?serverVersion=8.0"
# DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/lock ###
Expand Down
1 change: 1 addition & 0 deletions app/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
DATABASE_URL="mysql://lux_admin:&pHDG3%LcV@database_test:3306/lux?serverVersion=8.0"
3 changes: 2 additions & 1 deletion app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"doctrine/orm": "^2.9",
"easycorp/easyadmin-bundle": "3.*",
"imagine/imagine": "^1.2",
"paragonie/sodium_compat": "^1.17",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^6.1",
"symfony/asset": "5.3.*",
Expand Down Expand Up @@ -52,7 +53,7 @@
"doctrine/doctrine-fixtures-bundle": "^3.4",
"fakerphp/faker": "^1.15",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.3",
"symfony/browser-kit": "5.3.*",
"symfony/css-selector": "^5.3",
"symfony/debug-bundle": "^5.3",
"symfony/maker-bundle": "^1.0",
Expand Down
138 changes: 137 additions & 1 deletion app/composer.lock

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

3 changes: 3 additions & 0 deletions app/config/secrets/test/test.AKISMET_KEY.ca01fb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php // test.AKISMET_KEY.ca01fb on Tue, 29 Mar 2022 12:35:58 +0000

return "\x2C\xAE\x2AX\x3F\x90\x93\x18\x15\x20\x01\x02\xE1r\xADA\xF4\x3A\xDC\xAF\x7C\x20\xD2\x89V\xE7\x06\x7Dn\x9C\x5Da\x88_\x01\xDB\xD9\x96w\x5Ej\xAB\xA5s\x8C\xD8\x8BTB\x80\xAF\x86q\xB14\x03G";
3 changes: 3 additions & 0 deletions app/config/secrets/test/test.decrypt.private.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php // test.decrypt.private on Tue, 29 Mar 2022 12:35:57 +0000

return "\x86\xF8\x3Bz\xBB9\x3F\x10\x8F\x1C\x96\xF3\xD8\x84\xAFW\x18\xE6_X\x85\x86\x85\x9EZ\x3AJ.\x8B\xE5\x98\xEA\x11\x80\xA8\xECL\x5E\x3C\x1A\xF1O\x9E\xD7\xBC\xBEw\xFC\x25\x0C\xC9d\xF6\x2Ad\xF1g\xD9\x12\xA4R\x0F\x29t";
3 changes: 3 additions & 0 deletions app/config/secrets/test/test.encrypt.public.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php // test.encrypt.public on Tue, 29 Mar 2022 12:35:57 +0000

return "\x11\x80\xA8\xECL\x5E\x3C\x1A\xF1O\x9E\xD7\xBC\xBEw\xFC\x25\x0C\xC9d\xF6\x2Ad\xF1g\xD9\x12\xA4R\x0F\x29t";
5 changes: 5 additions & 0 deletions app/config/secrets/test/test.list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'AKISMET_KEY' => null,
];
28 changes: 18 additions & 10 deletions app/src/DataFixtures/ClientFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace App\DataFixtures;

use App\ImageOptimizer;
use App\Entity\Client;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
use Faker\Generator;
use Symfony\Component\HttpFoundation\File\Exception\FileException;

class ClientFixture extends Fixture
class ClientFixture extends Fixture implements DependentFixtureInterface
{
private $faker;
private Generator $faker;

public function __construct()
{
Expand All @@ -19,19 +23,23 @@ public function __construct()
public function load(ObjectManager $manager)
{
for ($i = 0; $i < 4; $i++) {
$manager->persist($this->getClient());

$client = new Client();
$client->setName($this->faker->name);
$client->setCity($this->faker->city);
$client->setPhoto($this->faker->image);
$client->setEmail($this->faker->email);
$client->setUser($this->getReference(UserFixtures::USER_REFERENCE));

$manager->persist($client);
}

$manager->flush();
}

private function getClient()
public function getDependencies()
{
return new Client(
$this->faker->name(),
$this->faker->city(),
$this->faker->image()
);
return [
UserFixtures::class,
];
}
}
21 changes: 0 additions & 21 deletions app/src/DataFixtures/InsuranceObjectsTypesFixture.php

This file was deleted.

39 changes: 15 additions & 24 deletions app/src/DataFixtures/UserFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@

use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

class UserFixtures extends Fixture
{
private $encoder;
private $em;
public const USER_REFERENCE = 'user';
private UserPasswordHasherInterface $hasher;

public function __construct(UserPasswordEncoderInterface $encoder, EntityManagerInterface $entityManager)
public function __construct(UserPasswordHasherInterface $hasher, EntityManagerInterface $entityManager)
{
$this->encoder = $encoder;
$this->em = $entityManager;
$this->hasher = $hasher;
}

public function load(\Doctrine\Persistence\ObjectManager $manager)
public function load(ObjectManager $manager)
{
$usersData = [
0 => [
'email' => '[email protected]',
'role' => ['ROLE_USER'],
'password' => 123456
]
];
$user = new User();
$user->setEmail('[email protected]');
$user->setPassword($this->hasher->hashPassword($user, 'qwerty123456'));
$user->setRoles(['ROLE_USER']);

$manager->persist($user);
$manager->flush();

foreach ($usersData as $user) {
$newUser = new User();
$newUser->setEmail($user['email']);
$newUser->setPassword($this->encoder->encodePassword($newUser, $user['password']));
$newUser->setRoles($user['role']);
$this->em->persist($newUser);
}

$this->em->flush();
$this->addReference(self::USER_REFERENCE, $user);
}
}
6 changes: 6 additions & 0 deletions app/symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
"nikic/php-parser": {
"version": "v4.12.0"
},
"paragonie/random_compat": {
"version": "v9.99.100"
},
"paragonie/sodium_compat": {
"version": "v1.17.1"
},
"phar-io/manifest": {
"version": "2.0.3"
},
Expand Down
Loading

0 comments on commit de1b859

Please sign in to comment.