1 | <?php |
||||
2 | |||||
3 | namespace WebnetFr\DatabaseAnonymizerBundle\Tests\System\Command; |
||||
4 | |||||
5 | use Doctrine\Bundle\DoctrineBundle\Registry; |
||||
6 | use Doctrine\Common\Annotations\AnnotationReader; |
||||
7 | use PHPUnit\Framework\TestCase; |
||||
8 | use Symfony\Component\Console\Application; |
||||
9 | use Symfony\Component\Console\Tester\CommandTester; |
||||
10 | use WebnetFr\DatabaseAnonymizer\ConfigGuesser\ConfigGuesser; |
||||
11 | use WebnetFr\DatabaseAnonymizer\GeneratorFactory\ChainGeneratorFactory; |
||||
12 | use WebnetFr\DatabaseAnonymizer\GeneratorFactory\ConstantGeneratorFactory; |
||||
13 | use WebnetFr\DatabaseAnonymizer\GeneratorFactory\FakerGeneratorFactory; |
||||
14 | use WebnetFr\DatabaseAnonymizerBundle\Command\AnonymizeCommand; |
||||
15 | use WebnetFr\DatabaseAnonymizerBundle\Config\AnnotationConfigFactory; |
||||
16 | use WebnetFr\DatabaseAnonymizerBundle\Tests\System\SystemTestTrait; |
||||
17 | |||||
18 | /** |
||||
19 | * @author Vlad Riabchenko <[email protected]> |
||||
20 | */ |
||||
21 | class AnonymizeCommandTest extends TestCase |
||||
22 | { |
||||
23 | use SystemTestTrait; |
||||
24 | |||||
25 | /** |
||||
26 | * {@inheritdoc} |
||||
27 | * @throws \Doctrine\DBAL\DBALException |
||||
28 | */ |
||||
29 | protected function setUp() |
||||
30 | { |
||||
31 | $this->regenerateUsersOrders(); |
||||
32 | } |
||||
33 | |||||
34 | public function testWithConfigFile() |
||||
35 | { |
||||
36 | $generator = new ChainGeneratorFactory(); |
||||
37 | $generator->addFactory(new ConstantGeneratorFactory()) |
||||
38 | ->addFactory(new FakerGeneratorFactory()); |
||||
39 | |||||
40 | $command = (new Application('Database anonymizer', '0.0.1')) |
||||
41 | ->add(new AnonymizeCommand($generator)); |
||||
42 | |||||
43 | $commandTester = new CommandTester($command); |
||||
44 | $commandTester->setInputs(array('y')); |
||||
45 | $commandTester->execute([ |
||||
46 | 'command' => $command->getName(), |
||||
47 | '--config' => realpath(__DIR__.'/../../config/config.yaml'), |
||||
48 | '--type' => $GLOBALS['db_type'], |
||||
49 | '--host' => $GLOBALS['db_host'], |
||||
50 | '--port' => $GLOBALS['db_port'], |
||||
51 | '--database' => $GLOBALS['db_name'], |
||||
52 | '--user' => $GLOBALS['db_username'], |
||||
53 | '--password' => $GLOBALS['db_password'], |
||||
54 | ]); |
||||
55 | |||||
56 | $this->doTestValues(); |
||||
57 | } |
||||
58 | |||||
59 | public function testWithAnnotations() |
||||
60 | { |
||||
61 | $generator = new ChainGeneratorFactory(); |
||||
62 | $generator->addFactory(new ConstantGeneratorFactory()) |
||||
63 | ->addFactory(new FakerGeneratorFactory()); |
||||
64 | |||||
65 | $annotationReader = new AnnotationReader(); |
||||
66 | $configGuesser = new ConfigGuesser(); |
||||
67 | $annotationConfigFactory = new AnnotationConfigFactory($annotationReader, $configGuesser); |
||||
68 | $anonymizeCommand = new AnonymizeCommand($generator); |
||||
69 | $anonymizeCommand->enableAnnotations($annotationConfigFactory); |
||||
70 | |||||
71 | $registry = new Registry(); |
||||
0 ignored issues
–
show
Unused Code
introduced
by
![]() The call to
Doctrine\Bundle\Doctrine...Registry::__construct() has too few arguments starting with container .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
72 | |||||
73 | $command = (new Application('Database anonymizer', '0.0.1')) |
||||
74 | ->add($anonymizeCommand); |
||||
75 | |||||
76 | $commandTester = new CommandTester($command); |
||||
77 | $commandTester->setInputs(array('y')); |
||||
78 | $commandTester->execute([ |
||||
79 | 'command' => $command->getName(), |
||||
80 | '--annotations' => true, |
||||
81 | '--em' => 'default', |
||||
82 | ]); |
||||
83 | |||||
84 | $this->doTestValues(); |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * Test actual values. |
||||
89 | */ |
||||
90 | private function doTestValues() |
||||
91 | { |
||||
92 | $connection = $this->getConnection(); |
||||
93 | |||||
94 | $selectSQL = $connection->createQueryBuilder() |
||||
95 | ->select('email, firstname, lastname, birthdate, phone, password') |
||||
96 | ->from('users') |
||||
97 | ->getSQL(); |
||||
98 | $selectStmt = $connection->prepare($selectSQL); |
||||
99 | $selectStmt->execute(); |
||||
100 | |||||
101 | while ($row = $selectStmt->fetch()) { |
||||
102 | $this->assertTrue(is_string($row['email'])); |
||||
103 | $this->assertTrue(is_string($row['firstname'])); |
||||
104 | $this->assertTrue(is_string($row['lastname'])); |
||||
105 | $this->assertTrue(is_string($row['birthdate'])); |
||||
106 | $this->assertTrue(is_string($row['phone']) || is_null($row['phone'])); |
||||
107 | $this->assertTrue(is_string($row['password'])); |
||||
108 | } |
||||
109 | |||||
110 | $selectSQL = $connection->createQueryBuilder() |
||||
111 | ->select('address, street_address, zip_code, city, country, comment, comment, created_at') |
||||
112 | ->from('orders') |
||||
113 | ->getSQL(); |
||||
114 | $selectStmt = $connection->prepare($selectSQL); |
||||
115 | $selectStmt->execute(); |
||||
116 | |||||
117 | while ($row = $selectStmt->fetch()) { |
||||
118 | $this->assertTrue(is_string($row['address'])); |
||||
119 | $this->assertTrue(is_string($row['street_address'])); |
||||
120 | $this->assertTrue(is_string($row['zip_code'])); |
||||
121 | $this->assertTrue(is_string($row['city'])); |
||||
122 | $this->assertTrue(is_string($row['country'])); |
||||
123 | $this->assertTrue(is_string($row['comment'])); |
||||
124 | $this->assertTrue(is_string($row['created_at'])); |
||||
125 | } |
||||
126 | } |
||||
127 | } |
||||
128 |