generated from dev/symfony-5-cli-template
15 changed files with 2599 additions and 220 deletions
-
2Makefile
-
9README.md
-
16composer.json
-
2359composer.lock
-
4config/bundles.php
-
14config/packages/doctrine.yaml
-
3config/packages/doctrine_migrations.yaml
-
20config/packages/prod/doctrine.yaml
-
4devops/docker/.env
-
29migrations/Version20210129121632.php
-
35src/DataFixtures/HistoryFixtures.php
-
59src/Entity/History.php
-
21src/Repository/HistoryRepository.php
-
109symfony.lock
-
135tests/unit/Entity/HistoryTest.php
2359
composer.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,14 @@ |
|||
doctrine: |
|||
dbal: |
|||
url: '%env(resolve:DATABASE_URL)%' |
|||
orm: |
|||
auto_generate_proxy_classes: true |
|||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware |
|||
auto_mapping: true |
|||
mappings: |
|||
App: |
|||
is_bundle: false |
|||
type: annotation |
|||
dir: '%kernel.project_dir%/src/Entity' |
|||
prefix: 'App\Entity' |
|||
alias: App |
@ -0,0 +1,3 @@ |
|||
doctrine_migrations: |
|||
migrations_paths: |
|||
'DoctrineMigrations': '%kernel.project_dir%/migrations' |
@ -0,0 +1,20 @@ |
|||
doctrine: |
|||
orm: |
|||
auto_generate_proxy_classes: false |
|||
metadata_cache_driver: |
|||
type: pool |
|||
pool: doctrine.system_cache_pool |
|||
query_cache_driver: |
|||
type: pool |
|||
pool: doctrine.system_cache_pool |
|||
result_cache_driver: |
|||
type: pool |
|||
pool: doctrine.result_cache_pool |
|||
|
|||
framework: |
|||
cache: |
|||
pools: |
|||
doctrine.result_cache_pool: |
|||
adapter: cache.app |
|||
doctrine.system_cache_pool: |
|||
adapter: cache.system |
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace DoctrineMigrations; |
|||
|
|||
use Doctrine\DBAL\Schema\Schema; |
|||
use Doctrine\Migrations\AbstractMigration; |
|||
|
|||
final class Version20210129121632 extends AbstractMigration |
|||
{ |
|||
public function up(Schema $schema) : void |
|||
{ |
|||
$this->addSql(' |
|||
CREATE TABLE history ( |
|||
id INT AUTO_INCREMENT NOT NULL, |
|||
temp FLOAT NOT NULL, |
|||
date_at DATE NOT NULL, PRIMARY KEY(id) |
|||
) |
|||
DEFAULT CHARACTER SET utf8mb4 |
|||
COLLATE `utf8mb4_unicode_ci` |
|||
ENGINE = InnoDB'); |
|||
} |
|||
|
|||
public function down(Schema $schema) : void |
|||
{ |
|||
$this->addSql('DROP TABLE history'); |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
namespace App\DataFixtures; |
|||
|
|||
use App\Entity\History; |
|||
use DateTime; |
|||
use Doctrine\Bundle\FixturesBundle\Fixture; |
|||
use Doctrine\Persistence\ObjectManager; |
|||
use Faker\Factory; |
|||
|
|||
class HistoryFixtures extends Fixture |
|||
{ |
|||
public function load(ObjectManager $manager): void |
|||
{ |
|||
$now = new DateTime(); |
|||
$past = (new DateTime())->sub(new \DateInterval('P6M')); |
|||
$interval = $now->diff($past); |
|||
|
|||
for ($i = (int) $interval->format('%a'); $i >= 0; --$i) { |
|||
$dayOffset = sprintf('P%dD', $i); |
|||
|
|||
$history = new History(); |
|||
$history |
|||
->setTemp( |
|||
(Factory::create('en_EN')) |
|||
->randomFloat(1, -50, 50) |
|||
) |
|||
->setDateAt((new DateTime()) |
|||
->sub(new \DateInterval($dayOffset)) |
|||
); |
|||
$manager->persist($history); |
|||
$manager->flush(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
<?php |
|||
|
|||
namespace App\Entity; |
|||
|
|||
use App\Repository\HistoryRepository; |
|||
use DateTimeInterface; |
|||
use Doctrine\ORM\Mapping as ORM; |
|||
|
|||
/** |
|||
* @ORM\Entity(repositoryClass=HistoryRepository::class) |
|||
*/ |
|||
class History |
|||
{ |
|||
/** |
|||
* @ORM\Id |
|||
* @ORM\GeneratedValue |
|||
* @ORM\Column(type="integer") |
|||
*/ |
|||
private ?int $id; |
|||
|
|||
/** |
|||
* @ORM\Column(type="float") |
|||
*/ |
|||
private ?float $temp; |
|||
|
|||
/** |
|||
* @ORM\Column(type="date") |
|||
*/ |
|||
private ?DateTimeInterface $date_at; |
|||
|
|||
public function getId(): ?int |
|||
{ |
|||
return $this->id; |
|||
} |
|||
|
|||
public function getTemp(): ?float |
|||
{ |
|||
return $this->temp; |
|||
} |
|||
|
|||
public function setTemp(float $temp): self |
|||
{ |
|||
$this->temp = $temp; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
public function getDateAt(): ?DateTimeInterface |
|||
{ |
|||
return $this->date_at; |
|||
} |
|||
|
|||
public function setDateAt(DateTimeInterface $date_at): self |
|||
{ |
|||
$this->date_at = $date_at; |
|||
|
|||
return $this; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace App\Repository; |
|||
|
|||
use App\Entity\History; |
|||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|||
use Doctrine\Persistence\ManagerRegistry; |
|||
|
|||
/** |
|||
* @method History|null find($id, $lockMode = null, $lockVersion = null) |
|||
* @method History|null findOneBy(array $criteria, array $orderBy = null) |
|||
* @method History[] findAll() |
|||
* @method History[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|||
*/ |
|||
class HistoryRepository extends ServiceEntityRepository |
|||
{ |
|||
public function __construct(ManagerRegistry $registry) |
|||
{ |
|||
parent::__construct($registry, History::class); |
|||
} |
|||
} |
@ -0,0 +1,135 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Tests\unit\Entity; |
|||
|
|||
use App\Entity\History; |
|||
use App\Tests\UnitTester; |
|||
use Codeception\Test\Unit; |
|||
use DateTimeInterface; |
|||
use Faker\Factory; |
|||
use ReflectionException; |
|||
|
|||
/** |
|||
* @internal |
|||
*/ |
|||
class HistoryTest extends Unit |
|||
{ |
|||
protected UnitTester $tester; |
|||
|
|||
/** |
|||
* @dataProvider dataGetId |
|||
* |
|||
* @throws ReflectionException |
|||
* @test |
|||
*/ |
|||
public function getId(?int $id): void |
|||
{ |
|||
$entity = new History(); |
|||
$property = $this->tester->getClassProperty($entity, 'id'); |
|||
|
|||
$property->setValue($entity, $id); |
|||
$result = $entity->getId(); |
|||
|
|||
self::assertEquals($id, $result); |
|||
} |
|||
|
|||
public static function dataGetId(): array |
|||
{ |
|||
$faker = Factory::create('en_EN'); |
|||
|
|||
return [ |
|||
['id' => null], |
|||
['id' => $faker->randomNumber()], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @dataProvider dataGetTemp |
|||
* |
|||
* @throws ReflectionException |
|||
* @test |
|||
*/ |
|||
public function getTemp(?float $temp): void |
|||
{ |
|||
$entity = new History(); |
|||
$property = $this->tester->getClassProperty($entity, 'temp'); |
|||
|
|||
$property->setValue($entity, $temp); |
|||
$result = $entity->getTemp(); |
|||
|
|||
self::assertEquals($temp, $result); |
|||
} |
|||
|
|||
public static function dataGetTemp(): array |
|||
{ |
|||
$faker = Factory::create('en_EN'); |
|||
|
|||
return [ |
|||
['temp' => null], |
|||
['temp' => $faker->randomFloat()], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @throws ReflectionException |
|||
* @test |
|||
*/ |
|||
public function setTemp(): void |
|||
{ |
|||
$entity = new History(); |
|||
$property = $this->tester->getClassProperty($entity, 'temp'); |
|||
$temp = (Factory::create('en_EN'))->randomFloat(); |
|||
|
|||
$resultSet = $entity->setTemp($temp); |
|||
$result = $property->getValue($entity); |
|||
|
|||
self::assertEquals($temp, $result); |
|||
self::assertEquals($entity, $resultSet); |
|||
} |
|||
|
|||
/** |
|||
* @dataProvider dataGetDateAt |
|||
* |
|||
* @throws ReflectionException |
|||
* @test |
|||
*/ |
|||
public function getDateAt(?DateTimeInterface $date_at): void |
|||
{ |
|||
$entity = new History(); |
|||
$property = $this->tester->getClassProperty($entity, 'date_at'); |
|||
|
|||
$property->setValue($entity, $date_at); |
|||
$result = $entity->getDateAt(); |
|||
|
|||
self::assertEquals($date_at, $result); |
|||
} |
|||
|
|||
public static function dataGetDateAt(): array |
|||
{ |
|||
$faker = Factory::create('en_EN'); |
|||
|
|||
return [ |
|||
['date_at' => null], |
|||
['date_at' => $faker->dateTime()], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @throws ReflectionException |
|||
* @test |
|||
*/ |
|||
public function setDateAt(): void |
|||
{ |
|||
$entity = new History(); |
|||
$property = $this->tester->getClassProperty($entity, 'date_at'); |
|||
$date_at = (Factory::create('en_EN'))->dateTime(); |
|||
|
|||
$resultSet = $entity->setDateAt($date_at); |
|||
$result = $property->getValue($entity); |
|||
|
|||
self::assertEquals($date_at, $result); |
|||
self::assertEquals($entity, $resultSet); |
|||
} |
|||
} |
Reference in new issue