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
|
|
|
/** |
21
|
|
|
* @var BulkSimpleEntityCreator |
22
|
|
|
*/ |
23
|
|
|
private $creator; |
24
|
|
|
|
25
|
|
|
public function setup() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
$this->generateTestCode(); |
29
|
|
|
$this->createDatabase(); |
30
|
|
|
$this->creator = $this->container->get(BulkSimpleEntityCreator::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
36
|
|
|
*/ |
37
|
|
|
public function itCanBulkCreateSimpleEntities(): void |
38
|
|
|
{ |
39
|
|
|
$tableName = $this->getEntityManager()->getClassMetadata(self::TEST_ENTITY)->getTableName(); |
40
|
|
|
$this->creator->setHelper(new class($tableName, self::TEST_ENTITY) implements BulkSimpleEntityCreatorHelper |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $tableName; |
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $entityFqn; |
50
|
|
|
|
51
|
|
|
public function __construct(string $tableName, string $entityFqn) |
52
|
|
|
{ |
53
|
|
|
$this->tableName = $tableName; |
54
|
|
|
$this->entityFqn = $entityFqn; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getTableName(): string |
58
|
|
|
{ |
59
|
|
|
return $this->tableName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getEntityFqn(): string |
63
|
|
|
{ |
64
|
|
|
return $this->entityFqn; |
65
|
|
|
} |
66
|
|
|
}); |
67
|
|
|
$num = 10000; |
68
|
|
|
$this->creator->startBulkProcess(); |
69
|
|
|
$this->creator->addEntitiesToSave($this->getArrayOfEntityDatas($num)); |
70
|
|
|
$this->creator->endBulkProcess(); |
71
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository(self::TEST_ENTITY)->findAll(); |
72
|
|
|
self::assertCount($num, $loaded); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function getArrayOfEntityDatas($num): array |
76
|
|
|
{ |
77
|
|
|
$return = []; |
78
|
|
|
foreach (range(1, $num) as $key) { |
79
|
|
|
$return[$key] = $this->getBulkEntityData($key); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function getBulkEntityData(int $key): array |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
'string' => md5('key:' . $key), |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
} |