/
AddSuggestionsListenerTest.php
120 lines (110 loc) · 3.34 KB
/
AddSuggestionsListenerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace TheRestartProject\RepairDirectory\Tests\Integration\Infrastructure\Doctrine\Listeners;
use Doctrine\ORM\EntityManager;
use TheRestartProject\RepairDirectory\Domain\Models\Business;
use TheRestartProject\RepairDirectory\Domain\Models\Suggestion;
use TheRestartProject\RepairDirectory\Testing\DatabaseMigrations;
use TheRestartProject\RepairDirectory\Tests\IntegrationTestCase;
/**
* AddSuggestionsListener Test
*
* @category Test
* @package TheRestartProject\RepairDirectory\Tests\Integration\Infrastructure\Doctrine\Listeners
* @author Joaquim d'Souza <joaquim@outlandish.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://www.outlandish.com/
*/
class AddSuggestionsListenerTest extends IntegrationTestCase
{
use DatabaseMigrations;
/**
* Store a reference to the entity manager so that it can
* be used to create and update entities and persist
* the changes.
*
* @var EntityManager
*/
private $entityManager;
/**
* Set up the test
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->entityManager = $this->app->make(EntityManager::class);
}
/**
* Asserts that persisting and flushing a business creates suggestions
*
* @return void
*
* @test
*/
public function it_adds_suggestions_when_businesses_are_created()
{
$business = new Business();
$business->setName('Repair Ltd');
$business->setDescription('Repair your devices');
$business->setPostcode('BA2 6PA');
$business->setAddress('34 Bristol Road');
$business->setProductsRepaired(['NewTestPhone', 'NewTestPhoneX']);
$business->setAuthorisedBrands(['Outlandish', 'Unit4']);
$this->entityManager->persist($business);
$this->entityManager->flush();
$this->assertTestSuggestions();
}
/**
* Asserts that updating and flushing a business creates suggestions
*
* @test
*
* @return void
*/
public function it_adds_suggestions_when_businesses_are_updated()
{
entity(Business::class)->create();
$business = $this->entityManager->getRepository(Business::class)->find(1);
$business->setProductsRepaired(['NewTestPhone', 'NewTestPhoneX']);
$business->setAuthorisedBrands(['Outlandish', 'Unit4']);
$this->entityManager->flush();
$this->assertTestSuggestions();
}
/**
* Assert that the test suggestions exist
*
* @return void
*/
private function assertTestSuggestions()
{
$this->assertDatabaseHas(
'suggestions',
[
'field' => 'productsRepaired',
'value' => 'NewTestPhone'
]
);
$this->assertDatabaseHas(
'suggestions',
[
'field' => 'productsRepaired',
'value' => 'NewTestPhoneX'
]
);
$this->assertDatabaseHas(
'suggestions',
[
'field' => 'authorisedBrands',
'value' => 'Outlandish'
]
);
$this->assertDatabaseHas(
'suggestions',
[
'field' => 'authorisedBrands',
'value' => 'Unit4'
]
);
}
}