Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
teebbstudios
teebblog
提交
1bbed3b9
T
teebblog
项目概览
teebbstudios
/
teebblog
通知
0
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
teebblog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1bbed3b9
编写于
7月 26, 2021
作者:
伟
伟伟权
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
99. modify Post status property
上级
d5121dfe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
9 deletion
+40
-9
migrations/Version20210726114032.php
migrations/Version20210726114032.php
+31
-0
src/DataFixtures/PostFixtures.php
src/DataFixtures/PostFixtures.php
+2
-2
src/Entity/Post.php
src/Entity/Post.php
+3
-3
src/Factory/PostFactory.php
src/Factory/PostFactory.php
+1
-1
tests/UnitTest/PostFactoryTest.php
tests/UnitTest/PostFactoryTest.php
+3
-3
未找到文件。
migrations/Version20210726114032.php
0 → 100644
浏览文件 @
1bbed3b9
<?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`'
);
}
}
src/DataFixtures/PostFixtures.php
浏览文件 @
1bbed3b9
...
...
@@ -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
);
...
...
src/Entity/Post.php
浏览文件 @
1bbed3b9
...
...
@@ -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
;
...
...
src/Factory/PostFactory.php
浏览文件 @
1bbed3b9
...
...
@@ -19,7 +19,7 @@ class PostFactory
}
else
{
$post
->
setSummary
(
$this
->
sliceBodyToSummary
(
$body
));
}
$post
->
setStatus
(
$status
);
$post
->
setStatus
(
[
$status
]
);
return
$post
;
}
...
...
tests/UnitTest/PostFactoryTest.php
浏览文件 @
1bbed3b9
...
...
@@ -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
->
assert
Same
(
'draft'
,
$post
->
getStatus
());
$this
->
assert
ArrayHasKey
(
'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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录