|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kreta\Bundle\CommentBundle\Behat\Context; |
|
14
|
|
|
|
|
15
|
|
|
use Behat\Gherkin\Node\TableNode; |
|
16
|
|
|
use Kreta\Bundle\CoreBundle\Behat\Context\DefaultContext; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Comment Behat context class. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Beñat Espiña <[email protected]> |
|
22
|
|
|
* @author Gorka Laucirica <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class CommentContext extends DefaultContext |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Populates the database with comments. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Behat\Gherkin\Node\TableNode $comments The comments |
|
30
|
|
|
* |
|
31
|
|
|
* @Given /^the following comments exist:$/ |
|
32
|
|
|
*/ |
|
33
|
|
|
public function theFollowingCommentsExist(TableNode $comments) |
|
34
|
|
|
{ |
|
35
|
|
|
foreach ($comments as $commentData) { |
|
36
|
|
|
$issue = $this->get('kreta_issue.repository.issue')->findOneBy(['title' => $commentData['issue']], false); |
|
37
|
|
|
$user = $this->get('kreta_user.repository.user')->findOneBy(['email' => $commentData['user']], false); |
|
38
|
|
|
|
|
39
|
|
|
$comment = $this->get('kreta_comment.factory.comment')->create($issue, $user); |
|
40
|
|
|
$comment->setDescription($commentData['description']); |
|
41
|
|
|
if (isset($commentData['updatedAt'])) { |
|
42
|
|
|
$this->setField($comment, 'updatedAt', new \DateTime($commentData['updatedAt'])); |
|
43
|
|
|
} |
|
44
|
|
|
if (isset($commentData['createdAt'])) { |
|
45
|
|
|
$this->setField($comment, 'createdAt', new \DateTime($commentData['createdAt'])); |
|
46
|
|
|
} |
|
47
|
|
|
if (isset($commentData['id'])) { |
|
48
|
|
|
$this->setId($comment, $commentData['id']); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$this->get('kreta_comment.repository.comment')->persist($comment); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|