|
@@ -5,12 +5,19 @@ namespace Test\PhpDevCommunity\PaperORM\Helper;
|
|
|
use DateTime;
|
|
use DateTime;
|
|
|
use PhpDevCommunity\PaperORM\EntityManagerInterface;
|
|
use PhpDevCommunity\PaperORM\EntityManagerInterface;
|
|
|
use PhpDevCommunity\PaperORM\Generator\SchemaDiffGenerator;
|
|
use PhpDevCommunity\PaperORM\Generator\SchemaDiffGenerator;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Internal\Entity\PaperKeyValue;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Mapper\ColumnMapper;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\BoolColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\BoolColumn;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\DateTimeColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\DateTimeColumn;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Mapping\Column\SlugColumn;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
|
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\TimestampColumn;
|
|
use PhpDevCommunity\PaperORM\Mapping\Column\TimestampColumn;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Mapping\Column\TokenColumn;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Mapping\Column\UuidColumn;
|
|
|
|
|
+use PhpDevCommunity\PaperORM\Tools\IDBuilder;
|
|
|
|
|
+use Test\PhpDevCommunity\PaperORM\Entity\InvoiceTest;
|
|
|
use Test\PhpDevCommunity\PaperORM\Entity\PostTest;
|
|
use Test\PhpDevCommunity\PaperORM\Entity\PostTest;
|
|
|
use Test\PhpDevCommunity\PaperORM\Entity\UserTest;
|
|
use Test\PhpDevCommunity\PaperORM\Entity\UserTest;
|
|
|
|
|
|
|
@@ -46,6 +53,7 @@ class DataBaseHelperTest
|
|
|
new StringColumn('lastname'),
|
|
new StringColumn('lastname'),
|
|
|
new StringColumn('email'),
|
|
new StringColumn('email'),
|
|
|
new StringColumn('password'),
|
|
new StringColumn('password'),
|
|
|
|
|
+ new TokenColumn('token', 32),
|
|
|
new BoolColumn('is_active'),
|
|
new BoolColumn('is_active'),
|
|
|
new TimestampColumn('created_at', true),
|
|
new TimestampColumn('created_at', true),
|
|
|
];
|
|
];
|
|
@@ -54,6 +62,7 @@ class DataBaseHelperTest
|
|
|
(new JoinColumn('user_id', UserTest::class, 'id', true, false, JoinColumn::SET_NULL)),
|
|
(new JoinColumn('user_id', UserTest::class, 'id', true, false, JoinColumn::SET_NULL)),
|
|
|
new StringColumn('title'),
|
|
new StringColumn('title'),
|
|
|
new StringColumn('content'),
|
|
new StringColumn('content'),
|
|
|
|
|
+ new SlugColumn('slug', ['title']),
|
|
|
new TimestampColumn('created_at', true),
|
|
new TimestampColumn('created_at', true),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
@@ -66,7 +75,10 @@ class DataBaseHelperTest
|
|
|
new PrimaryKeyColumn('id'),
|
|
new PrimaryKeyColumn('id'),
|
|
|
(new JoinColumn('post_id', PostTest::class, 'id', true, false, JoinColumn::SET_NULL)),
|
|
(new JoinColumn('post_id', PostTest::class, 'id', true, false, JoinColumn::SET_NULL)),
|
|
|
new StringColumn('body'),
|
|
new StringColumn('body'),
|
|
|
|
|
+ new UuidColumn('uuid'),
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
$platform = $entityManager->getPlatform();
|
|
$platform = $entityManager->getPlatform();
|
|
|
$platform->createDatabaseIfNotExists();
|
|
$platform->createDatabaseIfNotExists();
|
|
|
$platform->dropDatabase();
|
|
$platform->dropDatabase();
|
|
@@ -88,6 +100,14 @@ class DataBaseHelperTest
|
|
|
'columns' => $commentColumns,
|
|
'columns' => $commentColumns,
|
|
|
'indexes' => [],
|
|
'indexes' => [],
|
|
|
],
|
|
],
|
|
|
|
|
+ 'invoice' => [
|
|
|
|
|
+ 'columns' => ColumnMapper::getColumns(InvoiceTest::class),
|
|
|
|
|
+ 'indexes' => [],
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'paper_key_value' => [
|
|
|
|
|
+ 'columns' => ColumnMapper::getColumns(PaperKeyValue::class),
|
|
|
|
|
+ 'indexes' => [],
|
|
|
|
|
+ ]
|
|
|
]
|
|
]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -105,16 +125,18 @@ class DataBaseHelperTest
|
|
|
'lastname' => 'Doe' . $i,
|
|
'lastname' => 'Doe' . $i,
|
|
|
'email' => $i . 'bqQpB@example.com',
|
|
'email' => $i . 'bqQpB@example.com',
|
|
|
'password' => 'password123',
|
|
'password' => 'password123',
|
|
|
|
|
+ 'token' => bin2hex(random_bytes(16)),
|
|
|
'is_active' => true,
|
|
'is_active' => true,
|
|
|
'created_at' => (new DateTime())->format($platform->getSchema()->getDateTimeFormatString()),
|
|
'created_at' => (new DateTime())->format($platform->getSchema()->getDateTimeFormatString()),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $stmt = $connection->getPdo()->prepare("INSERT INTO user (firstname, lastname, email, password, is_active, created_at) VALUES (:firstname, :lastname, :email, :password, :is_active, :created_at)");
|
|
|
|
|
|
|
+ $stmt = $connection->getPdo()->prepare("INSERT INTO user (firstname, lastname, email, password, token, is_active, created_at) VALUES (:firstname, :lastname, :email, :password, :token,:is_active, :created_at)");
|
|
|
$stmt->execute([
|
|
$stmt->execute([
|
|
|
'firstname' => $user['firstname'],
|
|
'firstname' => $user['firstname'],
|
|
|
'lastname' => $user['lastname'],
|
|
'lastname' => $user['lastname'],
|
|
|
'email' => $user['email'],
|
|
'email' => $user['email'],
|
|
|
'password' => $user['password'],
|
|
'password' => $user['password'],
|
|
|
|
|
+ 'token' => $user['token'],
|
|
|
'is_active' => $user['is_active'],
|
|
'is_active' => $user['is_active'],
|
|
|
'created_at' => $user['created_at']
|
|
'created_at' => $user['created_at']
|
|
|
]);
|
|
]);
|
|
@@ -128,14 +150,16 @@ class DataBaseHelperTest
|
|
|
'user_id' => $i + 1,
|
|
'user_id' => $i + 1,
|
|
|
'title' => 'Post ' . $id,
|
|
'title' => 'Post ' . $id,
|
|
|
'content' => 'Content ' . $id,
|
|
'content' => 'Content ' . $id,
|
|
|
|
|
+ 'slug' => 'post-' . $id,
|
|
|
'created_at' => (new DateTime())->format($platform->getSchema()->getDateTimeFormatString()),
|
|
'created_at' => (new DateTime())->format($platform->getSchema()->getDateTimeFormatString()),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $stmt = $connection->getPdo()->prepare("INSERT INTO post (user_id, title, content, created_at) VALUES (:user_id, :title, :content, :created_at)");
|
|
|
|
|
|
|
+ $stmt = $connection->getPdo()->prepare("INSERT INTO post (user_id, title, content, slug, created_at) VALUES (:user_id, :title, :content, :slug, :created_at)");
|
|
|
$stmt->execute([
|
|
$stmt->execute([
|
|
|
'user_id' => $post['user_id'],
|
|
'user_id' => $post['user_id'],
|
|
|
'title' => $post['title'],
|
|
'title' => $post['title'],
|
|
|
'content' => $post['content'],
|
|
'content' => $post['content'],
|
|
|
|
|
+ 'slug' => $post['slug'],
|
|
|
'created_at' => $post['created_at']
|
|
'created_at' => $post['created_at']
|
|
|
]);
|
|
]);
|
|
|
$id = uniqid('post_', true);
|
|
$id = uniqid('post_', true);
|
|
@@ -143,11 +167,13 @@ class DataBaseHelperTest
|
|
|
'user_id' => $i + 1,
|
|
'user_id' => $i + 1,
|
|
|
'title' => 'Post ' . $id,
|
|
'title' => 'Post ' . $id,
|
|
|
'content' => 'Content ' . $id,
|
|
'content' => 'Content ' . $id,
|
|
|
|
|
+ 'slug' => 'post-' . $id,
|
|
|
];
|
|
];
|
|
|
- $connection->executeStatement("INSERT INTO post (user_id, title, content) VALUES (
|
|
|
|
|
|
|
+ $connection->executeStatement("INSERT INTO post (user_id, title, content, slug) VALUES (
|
|
|
'{$post['user_id']}',
|
|
'{$post['user_id']}',
|
|
|
'{$post['title']}',
|
|
'{$post['title']}',
|
|
|
- '{$post['content']}'
|
|
|
|
|
|
|
+ '{$post['content']}',
|
|
|
|
|
+ '{$post['slug']}'
|
|
|
)");
|
|
)");
|
|
|
|
|
|
|
|
$lastId = $connection->getPdo()->lastInsertId();
|
|
$lastId = $connection->getPdo()->lastInsertId();
|
|
@@ -183,16 +209,22 @@ class DataBaseHelperTest
|
|
|
$comment = [
|
|
$comment = [
|
|
|
'post_id' => $i + 1,
|
|
'post_id' => $i + 1,
|
|
|
'body' => 'Comment ' . $id,
|
|
'body' => 'Comment ' . $id,
|
|
|
|
|
+ 'uuid' => IDBuilder::generate('{UUID}')
|
|
|
];
|
|
];
|
|
|
- $connection->executeStatement("INSERT INTO comment (post_id, body) VALUES (
|
|
|
|
|
|
|
+ $connection->executeStatement("INSERT INTO comment (post_id, body, uuid) VALUES (
|
|
|
'{$comment['post_id']}',
|
|
'{$comment['post_id']}',
|
|
|
- '{$comment['body']} '
|
|
|
|
|
|
|
+ '{$comment['body']}',
|
|
|
|
|
+ '{$comment['uuid']}'
|
|
|
)");
|
|
)");
|
|
|
|
|
|
|
|
|
|
+
|
|
|
$comment['body'] = 'Comment ' . $id . ' 2';
|
|
$comment['body'] = 'Comment ' . $id . ' 2';
|
|
|
- $connection->executeStatement("INSERT INTO comment (post_id, body) VALUES (
|
|
|
|
|
|
|
+ $comment['uuid'] = IDBuilder::generate('{UUID}');
|
|
|
|
|
+
|
|
|
|
|
+ $connection->executeStatement("INSERT INTO comment (post_id, body, uuid) VALUES (
|
|
|
'{$comment['post_id']}',
|
|
'{$comment['post_id']}',
|
|
|
- '{$comment['body']} '
|
|
|
|
|
|
|
+ '{$comment['body']}',
|
|
|
|
|
+ '{$comment['uuid']}'
|
|
|
)");
|
|
)");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|