提交 1bbed3b9 编写于 作者: 伟伟权

99. modify Post status property

上级 d5121dfe
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210726114032 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE post CHANGE status status LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\'');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE post CHANGE status status VARCHAR(20) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
}
}
......@@ -35,14 +35,14 @@ class PostFixtures extends Fixture
for ($i = 0; $i < 20; $i++) {
$post = $this->postFactory->create($this->faker->sentence(), $this->faker->paragraph());
if ($this->faker->boolean()) {
$post->setStatus('published');
$post->setStatus(['published']);
}
$image = '00' . $this->faker->randomDigit() . '.jpg';
$post->setPostImage($image);
if ($i == 19) {
$post->setStatus('published');
$post->setStatus(['published']);
$lastPost=$post;
}
$authorIndex = array_rand($userArray);
......
......@@ -39,7 +39,7 @@ class Post
private $body;
/**
* @ORM\Column(type="string", length=20, nullable=true)
* @ORM\Column(type="array", nullable=true)
*/
private $status;
......@@ -116,12 +116,12 @@ class Post
return $this;
}
public function getStatus(): ?string
public function getStatus(): ?array
{
return $this->status;
}
public function setStatus(?string $status): self
public function setStatus(?array $status, $context = []): self
{
$this->status = $status;
......
......@@ -19,7 +19,7 @@ class PostFactory
} else {
$post->setSummary($this->sliceBodyToSummary($body));
}
$post->setStatus($status);
$post->setStatus([$status]);
return $post;
}
......
......@@ -17,7 +17,7 @@ class PostFactoryTest extends TestCase
$postObj->setTitle('这是一个标题');
$postObj->setSummary("这是摘要");
$postObj->setBody('这是正文');
$postObj->setStatus('draft');
$postObj->setStatus(['draft']);
// $factory->expects($this->once())->method('create')
// ->with("这是一个标题", "这是正文", "这是摘要")
......@@ -26,7 +26,7 @@ class PostFactoryTest extends TestCase
$postObj2->setTitle('这是第二个文章标题');
$postObj2->setBody('<h1>这是第二个文章正文</h1>');
$postObj2->setSummary('这是第二个文章正文');
$postObj2->setStatus('draft');
$postObj2->setStatus(['draft']);
$factory->expects($this->exactly(2))->method('create')
->withConsecutive(["这是一个标题", "这是正文", "这是摘要"], ['这是第二个文章标题', '<h1>这是第二个文章正文</h1>'])
......@@ -36,7 +36,7 @@ class PostFactoryTest extends TestCase
$this->assertInstanceOf(Post::class, $post);
$this->assertSame($postObj, $post);
$this->assertSame('draft', $post->getStatus());
$this->assertArrayHasKey('draft', $post->getStatus());
$post2 = $factory->create('这是第二个文章标题', '<h1>这是第二个文章正文</h1>');
$this->assertSame($postObj2, $post2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册