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.

WorkflowConfigTest::tearDown()   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\XMLWorkflowFactory;
7
8
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
9
use OldTown\Workflow\Loader\XMLWorkflowFactory\WorkflowConfig;
10
use PHPUnit_Framework_TestCase as TestCase;
11
use OldTown\Workflow\PhpUnit\Test\Paths;
12
use Zend\Diactoros\Uri;
13
14
/**
15
 * Class WorkflowConfigTest
16
 *
17
 * @package OldTown\Workflow\PhpUnitTest\Loader
18
 */
19
class WorkflowConfigTest extends TestCase
20
{
21
    use HttpMockTrait;
22
23
    /**
24
     * @var WorkflowConfig
25
     */
26
    private $workflowConfig;
27
28
29
    /**
30
     * @var string
31
     */
32
    private static $exampleWorkflowConfig;
33
34
    /**
35
     * Путь до файла с тестовым workflow
36
     *
37
     * @var string
38
     */
39
    private static $pathToExampleWorkflowConfig;
40
41
    /**
42
     * @return void
43
     */
44 View Code Duplication
    public static function setUpBeforeClass()
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...
45
    {
46
        static::setUpHttpMockBeforeClass('8082', 'localhost');
47
        if (!static::$pathToExampleWorkflowConfig) {
0 ignored issues
show
Bug introduced by
Since $pathToExampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $pathToExampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
48
            $path = Paths::getPathToCommonDataDir() . DIRECTORY_SEPARATOR . 'osworkflow.xml';
49
            static::$pathToExampleWorkflowConfig = $path;
0 ignored issues
show
Bug introduced by
Since $pathToExampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $pathToExampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
50
        }
51
52
        if (!static::$exampleWorkflowConfig) {
0 ignored issues
show
Bug introduced by
Since $exampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $exampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
53
            static::$exampleWorkflowConfig = file_get_contents(static::$pathToExampleWorkflowConfig);
0 ignored issues
show
Bug introduced by
Since $exampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $exampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since $pathToExampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $pathToExampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
54
        }
55
    }
56
57
    /**
58
     *
59
     */
60
    public static function tearDownAfterClass()
61
    {
62
        static::tearDownHttpMockAfterClass();
63
    }
64
65
    /**
66
     *
67
     */
68
    public function tearDown()
69
    {
70
        $this->tearDownHttpMock();
71
    }
72
73
    /**
74
     * @return void
75
     */
76
    protected function setUp()
77
    {
78
        $this->setUpHttpMock();
79
80
        $this->workflowConfig = $this->getMockBuilder(WorkflowConfig::class)
81
            ->disableOriginalConstructor()
82
            ->getMock();
83
    }
84
85
    /**
86
     * Тестируем установку корректных св-тв при передаче корректного файла
87
     */
88
    public function testCorrectSetFileType()
89
    {
90
        $workflowConfig = new WorkflowConfig(Paths::getPathToCommonDataDir(), 'file', 'example.xml');
91
92
        static::assertEquals('example.xml', $workflowConfig->location);
93
        static::assertTrue(file_exists($workflowConfig->url));
94
        static::assertGreaterThan(0, $workflowConfig->lastModified);
95
        static::assertEquals('file', $workflowConfig->type);
96
    }
97
98
99
    /**
100
     * Тестируем установку корректных св-тв при передаче корректного урл
101
     */
102
    public function testCorrectSetUrlType()
103
    {
104
        $expectedTime = time();
105
106
        $lastModified = new \DateTime();
107
        $lastModified->setTimestamp($expectedTime);
108
        $lastModifiedStr = $lastModified->format("D, d M Y H:i:s \G\M\T");
109
110
111
        $this->http->mock
112
            ->when()
113
            ->methodIs('GET')
114
            ->pathIs('/foo')
115
            ->then()
116
            ->body(static::$exampleWorkflowConfig)
0 ignored issues
show
Bug introduced by
Since $exampleWorkflowConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $exampleWorkflowConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
117
            ->header('Last-Modified', $lastModifiedStr)
118
            ->end();
119
        $this->http->setUp();
120
121
        $url = 'http://localhost:8082/foo';
122
123
        $workflowConfig = new WorkflowConfig(null, WorkflowConfig::URL_TYPE, $url);
124
125
        static::assertEquals($expectedTime, $workflowConfig->lastModified);
126
        static::assertEquals(WorkflowConfig::URL_TYPE, $workflowConfig->type);
127
        static::assertEquals($url, $workflowConfig->location);
128
        static::assertEquals(true, $workflowConfig->url instanceof Uri);
129
    }
130
131
132
    /**
133
     * Тестируем установку корректных св-тв в случае если не указан тип ресурса
134
     */
135
    public function testCorrectSetDefaultType()
136
    {
137
        $path = Paths::getPathToCommonDataDir() . DIRECTORY_SEPARATOR . 'osworkflow.xml';
138
        $workflowConfig = new WorkflowConfig(null, null, $path);
139
140
        static::assertEquals(filemtime($path), $workflowConfig->lastModified);
141
        static::assertEquals(null, $workflowConfig->type);
142
        static::assertEquals($path, $workflowConfig->location);
143
        static::assertEquals(realpath($path), $workflowConfig->url);
144
    }
145
146
    /**
147
     * Тестируем установку имени класса реализующего обертку для uri
148
     */
149 View Code Duplication
    public function testGetterSetterUriClassName()
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...
150
    {
151
        $original = WorkflowConfig::getUriClassName();
152
        $expected = 'test';
153
        WorkflowConfig::setUriClassName($expected);
154
        $actual = WorkflowConfig::getUriClassName();
155
        WorkflowConfig::setUriClassName($original);
156
157
        static::assertEquals($expected, $actual);
158
    }
159
}
160