|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebnetFr\DatabaseAnonymizerBundle\Tests\System\Command; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Symfony\Component\Console\Application; |
|
7
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
8
|
|
|
use WebnetFr\DatabaseAnonymizer\GeneratorFactory\ChainGeneratorFactory; |
|
9
|
|
|
use WebnetFr\DatabaseAnonymizer\GeneratorFactory\ConstantGeneratorFactory; |
|
10
|
|
|
use WebnetFr\DatabaseAnonymizer\GeneratorFactory\FakerGeneratorFactory; |
|
11
|
|
|
use WebnetFr\DatabaseAnonymizerBundle\Command\AnonymizeCommand; |
|
12
|
|
|
use WebnetFr\DatabaseAnonymizerBundle\Tests\System\SystemTestTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Vlad Riabchenko <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class AnonymizeCommandTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use SystemTestTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->regenerateUsersOrders(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testExecute() |
|
31
|
|
|
{ |
|
32
|
|
|
$generator = new ChainGeneratorFactory(); |
|
33
|
|
|
$generator->addFactory(new ConstantGeneratorFactory()) |
|
34
|
|
|
->addFactory(new FakerGeneratorFactory()); |
|
35
|
|
|
|
|
36
|
|
|
$command = (new Application('Database anonymizer', '0.0.1')) |
|
37
|
|
|
->add(new AnonymizeCommand($generator)); |
|
38
|
|
|
|
|
39
|
|
|
$commandTester = new CommandTester($command); |
|
40
|
|
|
|
|
41
|
|
|
$commandTester->setInputs(array('y')); |
|
42
|
|
|
$commandTester->execute([ |
|
43
|
|
|
'command' => $command->getName(), |
|
44
|
|
|
'--config' => realpath(__DIR__.'/../../config/config.yaml'), |
|
45
|
|
|
'--type' => $GLOBALS['db_type'], |
|
46
|
|
|
'--host' => $GLOBALS['db_host'], |
|
47
|
|
|
'--port' => $GLOBALS['db_port'], |
|
48
|
|
|
'--database' => $GLOBALS['db_name'], |
|
49
|
|
|
'--user' => $GLOBALS['db_username'], |
|
50
|
|
|
'--password' => $GLOBALS['db_password'], |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
$connection = $this->getConnection(); |
|
54
|
|
|
|
|
55
|
|
|
$selectSQL = $connection->createQueryBuilder() |
|
56
|
|
|
->select('email, firstname, lastname, birthdate, phone, password') |
|
57
|
|
|
->from('users') |
|
58
|
|
|
->getSQL(); |
|
59
|
|
|
$selectStmt = $connection->prepare($selectSQL); |
|
60
|
|
|
$selectStmt->execute(); |
|
61
|
|
|
|
|
62
|
|
|
while ($row = $selectStmt->fetch()) { |
|
63
|
|
|
$this->assertTrue(is_string($row['email'])); |
|
64
|
|
|
$this->assertTrue(is_string($row['firstname'])); |
|
65
|
|
|
$this->assertTrue(is_string($row['lastname'])); |
|
66
|
|
|
$this->assertTrue(is_string($row['birthdate'])); |
|
67
|
|
|
$this->assertTrue(is_string($row['phone']) || is_null($row['phone'])); |
|
68
|
|
|
$this->assertTrue(is_string($row['password'])); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$selectSQL = $connection->createQueryBuilder() |
|
72
|
|
|
->select('address, street_address, zip_code, city, country, comment, comment, created_at') |
|
73
|
|
|
->from('orders') |
|
74
|
|
|
->getSQL(); |
|
75
|
|
|
$selectStmt = $connection->prepare($selectSQL); |
|
76
|
|
|
$selectStmt->execute(); |
|
77
|
|
|
|
|
78
|
|
|
while ($row = $selectStmt->fetch()) { |
|
79
|
|
|
$this->assertTrue(is_string($row['address'])); |
|
80
|
|
|
$this->assertTrue(is_string($row['street_address'])); |
|
81
|
|
|
$this->assertTrue(is_string($row['zip_code'])); |
|
82
|
|
|
$this->assertTrue(is_string($row['city'])); |
|
83
|
|
|
$this->assertTrue(is_string($row['country'])); |
|
84
|
|
|
$this->assertTrue(is_string($row['comment'])); |
|
85
|
|
|
$this->assertTrue(is_string($row['created_at'])); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|