Passed
Pull Request — master (#10)
by Robbie
01:27
created

LicenseCheckTest::runProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ModuleRatings\Tests\Check;
4
5
use PHPUnit\Framework\TestCase;
6
use SilverStripe\ModuleRatings\Check\LicenseCheck;
7
use SilverStripe\ModuleRatings\CheckSuite;
8
use Symfony\Component\Finder\Finder;
9
10
/**
11
 * This test covers the same logic used in all file based checks
12
 */
13
class LicenseCheckTest extends TestCase
14
{
15
    /**
16
     * @covers \SilverStripe\ModuleRatings\Check\ContributingFileCheck::run
17
     * @covers \SilverStripe\ModuleRatings\Check\CodeOrSrcFolderCheck::run
18
     * @covers \SilverStripe\ModuleRatings\Check\DocumentationCheck::run
19
     * @covers \SilverStripe\ModuleRatings\Check\EditorConfigFileCheck::run
20
     * @covers \SilverStripe\ModuleRatings\Check\GitAttributesFileCheck::run
21
     * @covers \SilverStripe\ModuleRatings\Check\LicenseCheck::run
22
     * @covers \SilverStripe\ModuleRatings\Check\ReadmeCheck::run
23
     *
24
     * @param array $filenames
25
     * @param bool $expected
26
     * @dataProvider runProvider
27
     */
28
    public function testRun($filenames, $expected)
29
    {
30
        // Set up the Finder mock
31
        $finder = $this->getMockBuilder(Finder::class)
32
            ->setMethods(['files', 'in', 'name'])
33
            ->getMock();
34
35
        $finder->expects($this->once())->method('files')->will($this->returnSelf());
36
        $finder->expects($this->once())->method('in')->will($this->returnSelf());
37
        $finder->expects($this->once())->method('name')->willReturn($filenames);
38
39
        $check = new LicenseCheck();
40
        $check->setSuite(new CheckSuite());
41
        $check->setFinder($finder);
42
        $check->run();
43
44
        $this->assertSame($expected, $check->getSuccessful());
45
    }
46
47
    /**
48
     * @return array[]
49
     */
50
    public function runProvider()
51
    {
52
        return [
53
            'markdown license uppercase' => [['LICENSE.md'], true],
54
            'markdown license lowercase' => [['license.md'], true],
55
            'text license uppercase' => [['LICENSE.txt'], true],
56
            'text license lowercase' => [['license.txt'], true],
57
            'license uppercase' => [['LICENSE'], true],
58
            'license lowercase' => [['license'], true],
59
            'no license' => [[], false],
60
        ];
61
    }
62
}
63