UtilityTest::testGetGithubRevUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse(commo...\Utility::getRevHash()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
42
43
      $this->_createRevFile();
44
      expect('getRevHash should return abcdefg', $this->assertEquals('abcdefg', Utility::getRevHash()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals('abc...\Utility::getRevHash()) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
45
      chmod(Utility::$REVISION_FILE, 0222);
46
      expect('getRevHash should return false when the file is not readable', $this->assertFalse(Utility::getRevHash()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse(commo...\Utility::getRevHash()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals('abc...\Utility::getRevHash()) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse(commo...ity::getGithubRevUrl()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals('htt...ity::getGithubRevUrl()) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
60
    $this->_deleteRevFile();
61
  }
62
}
63