GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

XMLWorkflowFactoryTest::tearDownAfterClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/old-town/old-town-workflow
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\PhpUnitTest\Loader;
7
8
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
9
use OldTown\Workflow\Loader\WorkflowDescriptor;
10
use OldTown\Workflow\PhpUnit\Test\Paths;
11
use PHPUnit_Framework_TestCase as TestCase;
12
use OldTown\Workflow\Loader\XmlWorkflowFactory;
13
use OldTown\Workflow\Loader\XMLWorkflowFactory\WorkflowConfig;
14
use OldTown\Workflow\PhpUnit\Utils\DirUtilTrait;
15
16
/**
17
 * Class XMLWorkflowFactoryTest
18
 *
19
 * @package OldTown\Workflow\PhpUnitTest\Loader
20
 */
21
class XMLWorkflowFactoryTest extends TestCase
22
{
23
    use HttpMockTrait, DirUtilTrait;
24
25
    /**
26
     * @var XmlWorkflowFactory
27
     */
28
    private $xmlWorkflowFactory;
29
30
    /**
31
     * @var mixed
32
     */
33
    private $originalDefaultPathsToWorkflows;
34
35
    /**
36
     *
37
     */
38
    public static function setUpBeforeClass()
39
    {
40
        static::setUpHttpMockBeforeClass('8082', 'localhost');
41
    }
42
43
    /**
44
     *
45
     */
46
    public static function tearDownAfterClass()
47
    {
48
        static::tearDownHttpMockAfterClass();
49
    }
50
51
    /**
52
     *
53
     */
54
    public function setUp()
55
    {
56
        $this->setUpHttpMock();
57
        $this->originalDefaultPathsToWorkflows = XmlWorkflowFactory::getDefaultPathsToWorkflows();
58
        $this->xmlWorkflowFactory = new XmlWorkflowFactory();
59
    }
60
61
    /**
62
     *
63
     */
64
    public function tearDown()
65
    {
66
        XmlWorkflowFactory::setDefaultPathsToWorkflows($this->originalDefaultPathsToWorkflows);
67
        $this->tearDownHttpMock();
68
    }
69
70
71
72
    /**
73
     * Проверка работы с layout
74
     *
75
     * @return void
76
     */
77
    public function testSetterGetterLayout()
78
    {
79
        $this->xmlWorkflowFactory->setLayout('test', 'test');
80
81
        static::assertNull($this->xmlWorkflowFactory->getLayout('example'));
82
    }
83
84
85
    /**
86
     * Проверка работы с isModifiable
87
     *
88
     * @return void
89
     */
90
    public function testIsModifiable()
91
    {
92
        static::assertTrue($this->xmlWorkflowFactory->isModifiable('example'));
93
    }
94
95
96
    /**
97
     * Проверка работы с getName
98
     *
99
     * @return void
100
     */
101
    public function testGetName()
102
    {
103
        $expected = '';
104
        $actual = $this->xmlWorkflowFactory->getName();
105
        static::assertEquals($expected, $actual);
106
    }
107
108
109
    /**
110
     * Проверка работы с serialize
111
     *
112
     * @return void
113
     */
114
    public function testSerialize()
115
    {
116
        static::assertNull($this->xmlWorkflowFactory->serialize());
117
    }
118
119
120
    /**
121
     * Проверка работы с Unserialize
122
     *
123
     * @return void
124
     */
125
    public function testUnserialize()
126
    {
127
128
        /** @noinspection PhpVoidFunctionResultUsedInspection */
129
        $actual = $this->xmlWorkflowFactory->unserialize('example');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $actual is correct as $this->xmlWorkflowFactory->unserialize('example') (which targets OldTown\Workflow\Loader\...wFactory::unserialize()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
130
131
        static::assertNull($actual);
132
    }
133
134
135
    /**
136
     * Получение имен workflow
137
     *
138
     * @return void
139
     */
140
    public function testGetWorkflowNames()
141
    {
142
        static::assertEmpty($this->xmlWorkflowFactory->getWorkflowNames());
143
    }
144
145
146
    /**
147
     * Удаление workflow
148
     *
149
     * @expectedException \OldTown\Workflow\Exception\FactoryException
150
     * @expectedExceptionMessage Удаление workflow не поддерживается
151
     *
152
     * @return void
153
     */
154
    public function testRemoveWorkflow()
155
    {
156
        $this->xmlWorkflowFactory->removeWorkflow('example');
157
    }
158
159
160
    /**
161
     * Переименовывание workflow
162
     *
163
     * @return void
164
     */
165
    public function testRenameWorkflow()
166
    {
167
        /** @noinspection PhpVoidFunctionResultUsedInspection */
168
        $actual = $this->xmlWorkflowFactory->renameWorkflow('example');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $actual is correct as $this->xmlWorkflowFactor...nameWorkflow('example') (which targets OldTown\Workflow\Loader\...ctory::renameWorkflow()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
169
170
        static::assertNull($actual);
171
    }
172
173
174
    /**
175
     * Сохранение
176
     *
177
     *
178
     * @return void
179
     */
180
    public function testSave()
181
    {
182
        /** @noinspection PhpVoidFunctionResultUsedInspection */
183
        $actual = $this->xmlWorkflowFactory->save();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $actual is correct as $this->xmlWorkflowFactory->save() (which targets OldTown\Workflow\Loader\XmlWorkflowFactory::save()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
184
185
        static::assertNull($actual);
186
    }
187
188
189
190
    /**
191
     * Проверка создания Workflow
192
     *
193
     * @return void
194
     */
195
    public function testCreateWorkflow()
196
    {
197
198
        /** @noinspection PhpVoidFunctionResultUsedInspection */
199
        $actual = $this->xmlWorkflowFactory->createWorkflow('example');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $actual is correct as $this->xmlWorkflowFactor...eateWorkflow('example') (which targets OldTown\Workflow\Loader\...ctory::createWorkflow()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
200
201
        static::assertNull($actual);
202
    }
203
204
    /**
205
     *
206
     *
207
     */
208 View Code Duplication
    public function testInitDone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
    {
210
        XmlWorkflowFactory::addDefaultPathToWorkflows(Paths::getPathToCommonDataDir());
211
212
        $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
213
214
        $this->xmlWorkflowFactory->initDone();
215
216
        $workflow = $this->xmlWorkflowFactory->getWorkflow('example');
217
218
219
        static::assertEquals(true, $workflow instanceof WorkflowDescriptor);
220
    }
221
222
    /**
223
     * @expectedException \OldTown\Workflow\Exception\InvalidParsingWorkflowException
224
     *
225
     */
226
    public function testInvalidConfig()
227
    {
228
        $this->http->mock
229
            ->when()
230
            ->methodIs('GET')
231
            ->pathIs('/foo')
232
            ->then()
233
            ->body('invalid content')
234
            ->end();
235
        $this->http->setUp();
236
237
        $url = 'http://localhost:8082/foo';
238
239
240
        /** @var XmlWorkflowFactory|\PHPUnit_Framework_MockObject_MockObject $xmlWorkflowFactoryMock */
241
        $xmlWorkflowFactoryMock = $this->getMock(XmlWorkflowFactory::class, [
242
            'getPathWorkflowFile'
243
        ]);
244
245
        $xmlWorkflowFactoryMock->expects(static::once())->method('getPathWorkflowFile')->will(static::returnValue($url));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in OldTown\Workflow\Loader\XmlWorkflowFactory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
246
247
248
        $xmlWorkflowFactoryMock->initDone();
0 ignored issues
show
Bug introduced by
The method initDone does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
249
    }
250
251
252
    /**
253
     * @expectedException \OldTown\Workflow\Exception\FactoryException
254
     * @expectedExceptionMessage Нет workflow с именем invalid-name
255
     *
256
     */
257
    public function testGetWorkflowInvalidName()
258
    {
259
        $this->xmlWorkflowFactory->getWorkflow('invalid-name');
260
    }
261
262
263
264
    /**
265
     * Тестирование кеша при получение дескриптора workflow
266
     *
267
     *
268
     */
269
    public function testGetWorkflowReload()
270
    {
271
        try {
272
            $testDir = $this->setUpTestDir([
273
                'workflows.xml',
274
                'example.xml'
275
            ], Paths::getPathToCommonDataDir());
276
277
278
            XmlWorkflowFactory::addDefaultPathToWorkflows($testDir);
279
            $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
280
            $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RELOAD_PROPERTY, 'true');
281
282
            $this->xmlWorkflowFactory->initDone();
283
            $this->xmlWorkflowFactory->getWorkflow('example');
284
285
            $pathToTestWorkflow = $testDir . DIRECTORY_SEPARATOR . 'example.xml';
286
287
            $dom = new \DOMDocument();
288
            $dom->load($pathToTestWorkflow);
289
            $xpath = new \DOMXpath($dom);
290
            $meta = $xpath->query('//workflow/meta[@name="lastModified"]')->item(0);
291
292
            $expected = 'test';
293
            $meta->nodeValue = $expected;
294
            sleep(1);
295
            $dom->save($pathToTestWorkflow);
296
            clearstatcache();
297
            $descriptor = $this->xmlWorkflowFactory->getWorkflow('example');
298
            $metaAttributes = $descriptor->getMetaAttributes();
299
300
            static::assertEquals($expected, $metaAttributes['lastModified']);
301
        } finally {
302
            $this->tearDownTestDir();
303
        }
304
    }
305
306
    /**
307
     * Попытка загрузить некорректный workflow файл
308
     *
309
     * @expectedException \OldTown\Workflow\Exception\FactoryException
310
     * @expectedExceptionMessageRegExp /Некорректный дескрипторв workflow:.*+/
311
     */
312 View Code Duplication
    public function testLoadInvalidWorkflow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
313
    {
314
        XmlWorkflowFactory::addDefaultPathToWorkflows(Paths::getPathToInvalidWorkflowDir());
315
316
        $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
317
318
        $this->xmlWorkflowFactory->initDone();
319
320
        $workflow = $this->xmlWorkflowFactory->getWorkflow('example');
321
322
323
        static::assertEquals(true, $workflow instanceof WorkflowDescriptor);
324
    }
325
326
327
    /**
328
     * Проверка ситуации когда в конфиге workflow не задана атрибут baseDir
329
     *
330
     */
331
    public function testNoBaseDir()
332
    {
333
        XmlWorkflowFactory::addDefaultPathToWorkflows(Paths::getPathToInvalidWorkflowConfig());
334
335
336
        /** @var XmlWorkflowFactory|\PHPUnit_Framework_MockObject_MockObject $xmlWorkflowFactory */
337
        $xmlWorkflowFactory = $this->getMock(XmlWorkflowFactory::class, ['buildWorkflowConfig']);
338
        /** @var WorkflowConfig $mockConfig */
339
        $mockConfig = $this->getMock(WorkflowConfig::class, [], [], '', false);
340
        $mockConfig->url = Paths::getPathToInvalidWorkflowConfig() . DIRECTORY_SEPARATOR . 'example.xml';
0 ignored issues
show
Documentation Bug introduced by
It seems like \OldTown\Workflow\PhpUni...PARATOR . 'example.xml' of type string is incompatible with the declared type object<Psr\Http\Message\UriInterface> of property $url.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
341
342
        $xmlWorkflowFactory->expects(static::once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in OldTown\Workflow\Loader\XmlWorkflowFactory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
343
                           ->method('buildWorkflowConfig')
344
                           ->with(static::isNull(), static::equalTo('file'), static::equalTo('example.xml'))
345
                           ->will(static::returnValue($mockConfig));
346
347
348
        $xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows-no-base-dir.xml');
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
349
        $xmlWorkflowFactory->initDone();
0 ignored issues
show
Bug introduced by
The method initDone does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
350
351
        $xmlWorkflowFactory->getWorkflow('example');
0 ignored issues
show
Bug introduced by
The method getWorkflow does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
352
    }
353
354
355
    /**
356
     * Проверка ситуации когда отсутствует файл с описанием используемых workflow
357
     *
358
     * @expectedException \OldTown\Workflow\Exception\FactoryException
359
     * @expectedExceptionMessage Не удалось найти файл workflow
360
     */
361
    public function testNotFoundWorkflowsFile()
362
    {
363
        $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'not exists file');
364
365
        $this->xmlWorkflowFactory->initDone();
366
    }
367
368
369
    /**
370
     * Проверка ситуации когда в конфиге workflow  задана некорректынй атрибут baseDir
371
     *
372
     * @expectedException \OldTown\Workflow\Exception\RuntimeException
373
     * @expectedExceptionMessage Отсутствует ресурс ./invalid-base-dir
374
     */
375
    public function testInvalidBaseDir()
376
    {
377
        XmlWorkflowFactory::addDefaultPathToWorkflows(Paths::getPathToInvalidWorkflowConfig());
378
        $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows-invalid-base-dir.xml');
379
380
        $this->xmlWorkflowFactory->initDone();
381
    }
382
383
384
    /**
385
     * Сохранение workflow
386
     *
387
     *
388
     * @return void
389
     */
390
    public function testSaveWorkflow()
391
    {
392
        try {
393
            $testDir = $this->setUpTestDir([
394
                'workflows.xml',
395
                'example.xml',
396
                'new-example.xml'
397
            ], Paths::getPathToSaveWorkflowDir());
398
399
400
            XmlWorkflowFactory::addDefaultPathToWorkflows($testDir);
401
            $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
402
403
            $this->xmlWorkflowFactory->initDone();
404
            $workflow = $this->xmlWorkflowFactory->getWorkflow('newExample');
405
            $this->xmlWorkflowFactory->saveWorkflow('example', $workflow, true);
406
407
            $path = $testDir . DIRECTORY_SEPARATOR;
408
            static::assertXmlFileEqualsXmlFile($path . 'new-example.xml', $path . 'example.xml');
409
        } finally {
410
            $this->tearDownTestDir();
411
        }
412
    }
413
414
    /**
415
     * Сохранение workflow
416
     *
417
     * @expectedException \OldTown\Workflow\Exception\InvalidWriteWorkflowException
418
     * @expectedExceptionMessageRegExp /Ошибка при архивирование оригинального файла workflow .*+/
419
     *
420
     * @return void
421
     */
422 View Code Duplication
    public function testSaveWorkflowInvalidBackup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
423
    {
424
        try {
425
            $testDir = $this->setUpTestDir([
426
                'workflows.xml',
427
                'example.xml',
428
                'new-example.xml'
429
            ], Paths::getPathToSaveWorkflowDir());
430
431
432
            XmlWorkflowFactory::addDefaultPathToWorkflows($testDir);
433
            /** @var XmlWorkflowFactory|\PHPUnit_Framework_MockObject_MockObject $xmlWorkflowFactory */
434
            $xmlWorkflowFactory = $this->getMock(XmlWorkflowFactory::class, ['createBackupFile']);
435
            $xmlWorkflowFactory->expects(static::once())->method('createBackupFile')->will(static::returnValue(false));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in OldTown\Workflow\Loader\XmlWorkflowFactory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
436
437
            $xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
438
439
            $xmlWorkflowFactory->initDone();
0 ignored issues
show
Bug introduced by
The method initDone does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
440
            $workflow = $xmlWorkflowFactory->getWorkflow('newExample');
0 ignored issues
show
Bug introduced by
The method getWorkflow does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
441
            $xmlWorkflowFactory->saveWorkflow('example', $workflow, true);
0 ignored issues
show
Bug introduced by
The method saveWorkflow does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
442
        } finally {
443
            $this->tearDownTestDir();
444
        }
445
    }
446
447
448
    /**
449
     * Сохранение workflow
450
     *
451
     * @expectedException \OldTown\Workflow\Exception\InvalidWriteWorkflowException
452
     * @expectedExceptionMessageRegExp /Ошибка при переименовывание нового файла workflow .*+/
453
     *
454
     * @return void
455
     */
456 View Code Duplication
    public function testSaveWorkflowInvalidCreateNewFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
457
    {
458
        try {
459
            $testDir = $this->setUpTestDir([
460
                'workflows.xml',
461
                'example.xml',
462
                'new-example.xml'
463
            ], Paths::getPathToSaveWorkflowDir());
464
465
466
            XmlWorkflowFactory::addDefaultPathToWorkflows($testDir);
467
            /** @var XmlWorkflowFactory|\PHPUnit_Framework_MockObject_MockObject $xmlWorkflowFactory */
468
            $xmlWorkflowFactory = $this->getMock(XmlWorkflowFactory::class, ['createNewWorkflowFile']);
469
            $xmlWorkflowFactory->expects(static::once())->method('createNewWorkflowFile')->will(static::returnValue(false));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in OldTown\Workflow\Loader\XmlWorkflowFactory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
470
471
            $xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
472
473
            $xmlWorkflowFactory->initDone();
0 ignored issues
show
Bug introduced by
The method initDone does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
474
            $workflow = $xmlWorkflowFactory->getWorkflow('newExample');
0 ignored issues
show
Bug introduced by
The method getWorkflow does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
475
            $xmlWorkflowFactory->saveWorkflow('example', $workflow, true);
0 ignored issues
show
Bug introduced by
The method saveWorkflow does only exist in OldTown\Workflow\Loader\XmlWorkflowFactory, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
476
        } finally {
477
            $this->tearDownTestDir();
478
        }
479
    }
480
481
482
483
    /**
484
     * Сохранение workflow. Указано незарегестрированное имя workflow
485
     *
486
     * @expectedException \OldTown\Workflow\Exception\UnsupportedOperationException
487
     * @expectedExceptionMessage Сохранение workflow не поддерживается
488
     *
489
     * @return void
490
     */
491
    public function testSaveWorkflowIncorrectName()
492
    {
493
        /** @var  WorkflowDescriptor $descriptor */
494
        $descriptor = $this->getMock(WorkflowDescriptor::class);
495
        $this->xmlWorkflowFactory->saveWorkflow('example', $descriptor);
496
    }
497
498
499
    /**
500
     * Сохранение workflow. Проверка варианта когда указан флаг, не позволяющий перезаписывать существующее workflow
501
     *
502
     *
503
     * @return void
504
     */
505
    public function testSaveWorkflowReplace()
506
    {
507
        try {
508
            $testDir = $this->setUpTestDir([
509
                'workflows.xml',
510
                'example.xml',
511
                'new-example.xml'
512
            ], Paths::getPathToSaveWorkflowDir());
513
514
515
            XmlWorkflowFactory::addDefaultPathToWorkflows($testDir);
516
            $this->xmlWorkflowFactory->getProperties()->setProperty(XmlWorkflowFactory::RESOURCE_PROPERTY, 'workflows.xml');
517
518
            $this->xmlWorkflowFactory->initDone();
519
            $workflow = $this->xmlWorkflowFactory->getWorkflow('newExample');
520
            $result = $this->xmlWorkflowFactory->saveWorkflow('example', $workflow, false);
521
522
            static::assertEquals(false, $result);
523
        } finally {
524
            $this->tearDownTestDir();
525
        }
526
    }
527
}
528