Completed
Pull Request — master (#1109)
by Abdeali
01:32
created

bears.tests.linters.PHPLintBearTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %
Metric Value
dl 0
loc 23
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A test_run() 0 12 1
1
import os
2
import subprocess
3
import sys
4
from queue import Queue
5
6
sys.path.insert(0, ".")
7
import unittest
8
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
9
from bears.linters.PHPLintBear import PHPLintBear
10
from coalib.settings.Section import Section
11
12
13
class PHPLintBearTest(LocalBearTestHelper):
14
    def setUp(self):
15
        self.section = Section("test section")
16
        self.uut = PHPLintBear(self.section, Queue())
17
        self.test_file1 = os.path.join(os.path.dirname(__file__),
18
                                       "test_files",
19
                                       "phplint_test1.php")
20
        self.test_file2 = os.path.join(os.path.dirname(__file__),
21
                                       "test_files",
22
                                       "phplint_test2.php")
23
24
    def test_run(self):
25
        # Test a file with errors and warnings
26
        self.assertLinesInvalid(
27
            self.uut,
28
            [],
29
            self.test_file1)
30
31
        # Test a file without any issues
32
        self.assertLinesValid(
33
            self.uut,
34
            [],
35
            self.test_file2)
36
37
38
def skip_test():
39
    try:
40
        subprocess.Popen(['php', '--version'],
41
                         stdout=subprocess.PIPE,
42
                         stderr=subprocess.PIPE)
43
        return False
44
    except OSError:
45
        return "PHP is not installed."
46
47
48
if __name__ == '__main__':
49
    unittest.main(verbosity=2)
50