|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace common\tests\unit\components; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use Codeception\Specify; |
|
7
|
|
|
use common\components\Utility; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Utility test |
|
11
|
|
|
* |
|
12
|
|
|
* NOTE: |
|
13
|
|
|
* If these tests seem bizarre, a stray REVISION file might exist in the |
|
14
|
|
|
* same directory you're running the codecept command in. Delete that, |
|
15
|
|
|
* then run these tests again. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
class UtilityTest extends \Codeception\Test\Unit |
|
19
|
|
|
{ |
|
20
|
|
|
use Specify; |
|
21
|
|
|
|
|
22
|
|
|
protected function tearDown() |
|
23
|
|
|
{ |
|
24
|
|
|
// just in case we're forgetful :) |
|
25
|
|
|
if(file_exists(Utility::$REVISION_FILE)) $this->_deleteRevFile(); |
|
26
|
|
|
parent::tearDown(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function _createRevFile($data = false) { |
|
30
|
|
|
$data = $data ?: "abcdefghijklmnop"; |
|
31
|
|
|
file_put_contents(Utility::$REVISION_FILE, $data); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
private function _deleteRevFile() { |
|
35
|
|
|
unlink(Utility::$REVISION_FILE); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetRevHash() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->specify('getRevHash should function correctly', function () { |
|
41
|
|
|
expect('getRevHash should return false when the file does not exist', $this->assertFalse(Utility::getRevHash())); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->_createRevFile(); |
|
44
|
|
|
expect('getRevHash should return abcdefg', $this->assertEquals('abcdefg', Utility::getRevHash())); |
|
|
|
|
|
|
45
|
|
|
chmod(Utility::$REVISION_FILE, 0222); |
|
46
|
|
|
expect('getRevHash should return false when the file is not readable', $this->assertFalse(Utility::getRevHash())); |
|
|
|
|
|
|
47
|
|
|
$this->_deleteRevFile(); |
|
48
|
|
|
|
|
49
|
|
|
$this->_createRevFile('abc'); |
|
50
|
|
|
expect('getRevHash should return abc when there are less than 7 chars', $this->assertEquals('abc', Utility::getRevHash())); |
|
|
|
|
|
|
51
|
|
|
$this->_deleteRevFile(); |
|
52
|
|
|
}); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGetGithubRevUrl() |
|
56
|
|
|
{ |
|
57
|
|
|
expect('getRevHash should return false when the getRevHash() returns false', $this->assertFalse(Utility::getGithubRevUrl())); |
|
|
|
|
|
|
58
|
|
|
$this->_createRevFile(); |
|
59
|
|
|
expect('getRevHash should return the correct Github url when the getRevHash() returns data', $this->assertEquals("https://github.com/CorWatts/fasterscale/commit/abcdefg", Utility::getGithubRevUrl())); |
|
|
|
|
|
|
60
|
|
|
$this->_deleteRevFile(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.