Completed
Push — master ( 172340...b8107c )
by Gaetano
09:56
created

TestBenchCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 138
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 128 1
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Command;
4
5
use eZ\Publish\API\Repository\Repository;
6
use Kaliop\eZMigrationBundle\Core\MigrationService;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Kaliop\eZMigrationBundle\API\Value\Migration;
11
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
12
13
/**
14
 * Command to display the status of migrations.
15
 *
16
 * @todo add option to skip displaying already executed migrations
17
 */
18
class TestBenchCommand extends AbstractCommand
19
{
20
    protected function configure()
21
    {
22
        $this->setName('kaliop:migration:test')
23
            ->setDescription('TEST of TRANSACTIONS')
24
        ;
25
    }
26
27
    public function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        /** @var Repository $repo */
30
        $repo = $this->getContainer()->get('ezpublish.api.repository');
31
32
        $user = $repo->getUserService()->loadUser(14);
33
        $repo->setCurrentUser($user);
34
35
        $ls = $repo->getLocationService();
36
        $location = $ls->loadLocation(140);
37
        $ls->hideLocation($location);
38
        return;
39
40
        /** @var MigrationService $ms */
41
        $ms = $this->getContainer()->get('ez_migration_bundle.migration_service');
0 ignored issues
show
Unused Code introduced by
$ms = $this->getContaine...le.migration_service'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
42
/*echo 'A';
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
        $repo->commitEvent(
44
            function ( $lastEvent )
45
            {
46
                throw new \Exception('hahaha');
47
            }
48
        );
49
echo 'B';*/
50
51
        $ms->executeMigration(new MigrationDefinition(
52
            'test_'.time(),
53
            '/hello',
54
            '123',
55
            MigrationDefinition::STATUS_PARSED,
56
            array(),
57
            str_repeat('.', 4096)
58
        ));
59
60
        return;
61
        ///
62
63
        $sh = $this->getContainer()->get('ez_migration_bundle.storage_handler');
0 ignored issues
show
Unused Code introduced by
$sh = $this->getContaine...ndle.storage_handler'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
64
65
        $m1 = 'hello_'.time();
66
        $m2 = 'there_'.time();
67
        $sh->startMigration(new MigrationDefinition(
68
            $m1,
69
            '/hello',
70
            '123'
71
        ));
72
        $sh->startMigration(new MigrationDefinition(
73
            $m2,
74
            '/there',
75
            '123'
76
        ));
77
78
        $repo->beginTransaction();
79
80
        $repo->beginTransaction();
81
        //$repo->commit();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
82
        $repo->rollback();
83
84
        $sh->endMigration(new Migration(
85
            $m2,
86
            '123',
87
            '/there',
88
            time(),
89
            0
90
        ));
91
        $sh->endMigration(new Migration(
92
            $m1,
93
            '123',
94
            '/hello',
95
            time(),
96
            0
97
        ));
98
99
        $repo->commit();
100
101
        echo "OK\n";
102
103
        ///
104
105
        $dbHandler = $this->getContainer()->get('ezpublish.connection');
106
        $conn = $dbHandler->getConnection();
107
        $conn->setNestTransactionsWithSavepoints(true);
108
109
        $repo->beginTransaction();
110
        $repo->commit();
111
        $repo->beginTransaction();
112
        $repo->rollback();
113
        echo "BCBR: OK\n";
114
115
        $repo->beginTransaction();
116
        $repo->rollback();
117
        $repo->beginTransaction();
118
        $repo->commit();
119
        echo "BRBC: OK\n";
120
121
        $repo->beginTransaction();
122
        $repo->beginTransaction();
123
        $repo->commit();
124
        $repo->commit();
125
        echo "BBCC: OK\n";
126
127
        $repo->beginTransaction();
128
        $repo->beginTransaction();
129
        $repo->commit();
130
        $repo->rollback();
131
        echo "BBCR: OK\n";
132
133
        $repo->beginTransaction();
134
        $repo->beginTransaction();
135
        $repo->rollback();
136
        $repo->rollback();
137
        echo "BBRR: OK\n";
138
139
        // will throw unless partial rollbacks (savepoints) are enabled
140
        $repo->beginTransaction();
141
        $repo->beginTransaction();
142
        $repo->rollback();
143
        $repo->beginTransaction();
144
        $repo->commit();
145
        $repo->commit();
146
        echo "BBRBCC: OK\n";
147
148
        // will throw unless partial rollbacks (savepoints) are enabled
149
        $repo->beginTransaction();
150
        $repo->beginTransaction();
151
        $repo->rollback();
152
        $repo->commit();
153
        echo "BBRC: OK\n";
154
    }
155
}
156