1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DataFlow\Writer\Dbal; |
5
|
|
|
|
6
|
|
|
use Doctrine\DBAL\Connection; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
10
|
|
|
use SlayerBirden\DataFlow\Data\SimpleBag; |
11
|
|
|
use SlayerBirden\DataFlow\EmitterInterface; |
12
|
|
|
use SlayerBirden\DataFlow\Writer\Dbal\UpdateStrategy\ConfigStrategy; |
13
|
|
|
|
14
|
|
|
class WriteTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Write |
18
|
|
|
*/ |
19
|
|
|
private $write; |
20
|
|
|
/** |
21
|
|
|
* @var ObjectProphecy |
22
|
|
|
*/ |
23
|
|
|
private $strategy; |
24
|
|
|
/** |
25
|
|
|
* @var ObjectProphecy |
26
|
|
|
*/ |
27
|
|
|
private $emitter; |
28
|
|
|
/** |
29
|
|
|
* @var ObjectProphecy |
30
|
|
|
*/ |
31
|
|
|
private $connection; |
32
|
|
|
|
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->connection = $this->prophesize(Connection::class); |
36
|
|
|
$utility = $this->prophesize(WriterUtilityInterface::class); |
37
|
|
|
$utility->getColumns(Argument::any())->willReturn([]); |
38
|
|
|
$this->strategy = $this->prophesize(ConfigStrategy::class); |
39
|
|
|
$this->emitter = $this->prophesize(EmitterInterface::class); |
40
|
|
|
$this->write = new Write( |
41
|
|
|
'test', |
42
|
|
|
$this->connection->reveal(), |
43
|
|
|
'heroes', |
44
|
|
|
$utility->reveal(), |
45
|
|
|
$this->strategy->reveal(), |
46
|
|
|
$this->emitter->reveal() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testNoId() |
51
|
|
|
{ |
52
|
|
|
$this->strategy->getRecordIdentifier(Argument::any())->willReturn([]); |
53
|
|
|
$this->emitter->emit(Argument::exact('record_insert'), Argument::any(), Argument::any())->shouldBeCalled(); |
54
|
|
|
|
55
|
|
|
$this->write->pass(new SimpleBag([])); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \SlayerBirden\DataFlow\Writer\Dbal\InvalidIdentificationException |
60
|
|
|
* |
61
|
|
|
*/ |
62
|
|
|
public function testMultipleMatches() |
63
|
|
|
{ |
64
|
|
|
$this->strategy->getRecordIdentifier(Argument::any())->willReturn([ |
65
|
|
|
'id' => 1, |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$statement = $this->prophesize(\Doctrine\DBAL\Statement::class); |
69
|
|
|
$statement->execute(Argument::any())->willReturn(); |
70
|
|
|
$statement->fetchColumn()->willReturn(2); |
71
|
|
|
|
72
|
|
|
$builder = $this->prophesize(\Doctrine\DBAL\Query\QueryBuilder::class); |
73
|
|
|
$builder->select(Argument::any())->willReturn($builder->reveal()); |
74
|
|
|
$builder->from(Argument::any())->willReturn($builder->reveal()); |
75
|
|
|
$builder->setParameters(Argument::any())->willReturn(); |
76
|
|
|
$builder->andWhere(Argument::any())->willReturn(); |
77
|
|
|
$builder->getSQL()->willReturn(''); |
78
|
|
|
|
79
|
|
|
$this->connection->createQueryBuilder()->willReturn($builder->reveal()); |
80
|
|
|
$this->connection->prepare(Argument::any())->willReturn($statement->reveal()); |
81
|
|
|
|
82
|
|
|
$this->write->pass(new SimpleBag([])); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|