File tree 4 files changed +57
-5
lines changed
4 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,15 @@ public function setCreatedAt(\DateTimeImmutable $dateTime = null)
58
58
return $ this ;
59
59
}
60
60
61
+ /**
62
+ * @ORM\PrePersist()
63
+ * @return $this
64
+ */
65
+ public function setCreatedAtViaPrePersist ()
66
+ {
67
+ return $ this ->setCreatedAt ();
68
+ }
69
+
61
70
/**
62
71
* Get updated at
63
72
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace AppBundle \Entity ;
4
4
5
+ use AppBundle \Entity \Traits \TimestampableTrait ;
5
6
use Doctrine \ORM \Mapping as ORM ;
6
7
use JMS \Serializer \Annotation as JMSSerializer ;
7
8
8
9
/**
9
10
* @ORM\Entity()
10
11
* @ORM\Table(name="widget")
12
+ * @ORM\HasLifecycleCallbacks()
11
13
* @JMSSerializer\ExclusionPolicy("all")
12
14
*/
13
15
class Widget
14
16
{
17
+ use TimestampableTrait;
18
+
15
19
/**
16
20
* @ORM\Id
17
21
* @ORM\Column(type="integer")
Original file line number Diff line number Diff line change @@ -40,6 +40,29 @@ public function thereAreWidgetsWithTheFollowingDetails(TableNode $widgets)
40
40
41
41
$ this ->em ->persist ($ widget );
42
42
$ this ->em ->flush ();
43
+
44
+
45
+ $ qb = $ this ->em ->createQueryBuilder ();
46
+
47
+ $ query = $ qb ->update ('AppBundle:Widget ' , 'w ' )
48
+ ->set (
49
+ 'w.createdAt ' ,
50
+ $ qb ->expr ()->literal (
51
+ (new \DateTimeImmutable ($ val ['created_at ' ]))->format ('c ' )
52
+ )
53
+ )
54
+ ->set (
55
+ 'w.updatedAt ' ,
56
+ $ qb ->expr ()->literal (
57
+ (new \DateTimeImmutable ($ val ['updated_at ' ]))->format ('c ' )
58
+ )
59
+ )
60
+ ->where ('w.id = :id ' )
61
+ ->setParameter ('id ' , $ widget ->getId ())
62
+ ->getQuery ()
63
+ ;
64
+
65
+ $ query ->execute ();
43
66
}
44
67
}
45
68
}
Original file line number Diff line number Diff line change @@ -7,10 +7,10 @@ Feature: Manage Widget data via a JSON API
7
7
8
8
Background :
9
9
Given there are Widgets with the following details:
10
- | id | name |
11
- | 1 | Widget A |
12
- | 2 | Widget B |
13
- | 3 | Widget C |
10
+ | id | name | created_at | updated_at |
11
+ | 1 | Widget A | - 4 days | - 5 minutes |
12
+ | 2 | Widget B | - 1 day | - 1 day |
13
+ | 3 | Widget C | - 6 months | - 3 weeks |
14
14
And I set header "Content-Type" with value "application/json"
15
15
16
16
@@ -21,6 +21,22 @@ Feature: Manage Widget data via a JSON API
21
21
"""
22
22
{
23
23
"id": 1,
24
- "name": "Widget A"
24
+ "name": "Widget A",
25
+ features: [
26
+ {
27
+ "id": 1,
28
+ "name": "some feature",
29
+ "created_at": "2015-01-01T00:00:00+0000",
30
+ "updated_at": "2015-01-01T00:00:00+0000",
31
+ },
32
+ {
33
+ "id": 1,
34
+ "name": "another feature",
35
+ "created_at": "2016-01-01T00:00:00+0000",
36
+ "updated_at": "2016-01-01T00:00:00+0000",
37
+ }
38
+ ]
25
39
}
26
40
"""
41
+ And the "created_at" date should be approximately "-4 days"
42
+ And the "updated_at" date should be approximately "-5 minutes"
You can’t perform that action at this time.
0 commit comments