|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\D\Entity\Savers; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\BulkEntityUpdater\BulkSimpleEntityCreatorHelper; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\BulkSimpleEntityCreator; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @large |
|
12
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\BulkSimpleEntityCreator |
|
13
|
|
|
*/ |
|
14
|
|
|
class BulkSimpleEntityCreatorTest extends AbstractLargeTest |
|
15
|
|
|
{ |
|
16
|
|
|
public const WORK_DIR = self::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/BulkSimpleEntityCreatorTest'; |
|
17
|
|
|
|
|
18
|
|
|
public const TEST_ENTITY = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_SIMPLE; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var BulkSimpleEntityCreator |
|
21
|
|
|
*/ |
|
22
|
|
|
private $creator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $testEntityFqn; |
|
28
|
|
|
|
|
29
|
|
|
public function setup() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::setUp(); |
|
32
|
|
|
$this->generateTestCode(); |
|
33
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
|
34
|
|
|
$this->creator = $this->container->get(BulkSimpleEntityCreator::class); |
|
35
|
|
|
$this->testEntityFqn=$this->getCopiedFqn(self::TEST_ENTITY); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @test |
|
40
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function itCanBulkCreateSimpleEntities(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$tableName = $this->getEntityManager()->getClassMetadata($this->testEntityFqn)->getTableName(); |
|
45
|
|
|
$this->creator->setHelper(new class($tableName, $this->testEntityFqn) implements BulkSimpleEntityCreatorHelper |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $tableName; |
|
51
|
|
|
/** |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
private $entityFqn; |
|
55
|
|
|
|
|
56
|
|
|
public function __construct(string $tableName, string $entityFqn) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->tableName = $tableName; |
|
59
|
|
|
$this->entityFqn = $entityFqn; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getTableName(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->tableName; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getEntityFqn(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->entityFqn; |
|
70
|
|
|
} |
|
71
|
|
|
}); |
|
72
|
|
|
$num = 10000; |
|
73
|
|
|
$this->creator->startBulkProcess(); |
|
74
|
|
|
$this->creator->addEntitiesToSave($this->getArrayOfEntityDatas($num)); |
|
75
|
|
|
$this->creator->endBulkProcess(); |
|
76
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository($this->testEntityFqn)->findAll(); |
|
77
|
|
|
self::assertCount($num, $loaded); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private function getArrayOfEntityDatas($num): array |
|
81
|
|
|
{ |
|
82
|
|
|
$return = []; |
|
83
|
|
|
foreach (range(1, $num) as $key) { |
|
84
|
|
|
$return[$key] = $this->getBulkEntityData($key); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $return; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private function getBulkEntityData(int $key): array |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
|
|
'string' => md5('key:' . $key), |
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|