Skip to content

Commit

Permalink
Test FilterCollection and simplify test organization (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mborne committed Aug 25, 2018
1 parent 7d25029 commit 8c14ed8
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"psr-4": {"": "src/"}
},
"autoload-dev": {
"psr-4": {"MBO\\SatisGitlab\\": "test/functional"}
"psr-4": {"Tests\\SatisGitlab\\": "tests"}
},
"bin": [
"bin/satis-gitlab"
Expand Down
7 changes: 2 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
>

<testsuites>
<testsuite name="satis-gitlab-functional">
<directory>./tests/functional</directory>
</testsuite>
<testsuite name="satis-gitlab-unit">
<directory>./tests/unit</directory>
<testsuite name="satis-gitlab">
<directory>./tests</directory>
</testsuite>
</testsuites>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use PHPUnit\Framework\TestCase;
namespace Tests\SatisGitlab\Command;

use Tests\SatisGitlab\TestCase;

use Symfony\Component\Console\Tester\CommandTester;
use MBO\SatisGitlab\Command\GitlabToConfigCommand;
Expand Down
File renamed without changes.
69 changes: 69 additions & 0 deletions tests/Filter/FilterCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Tests\SatisGitlab\Filter;

use Tests\SatisGitlab\TestCase;

use Psr\Log\NullLogger;

use MBO\SatisGitlab\Filter\FilterCollection;
use MBO\SatisGitlab\Git\ProjectInterface;
use MBO\SatisGitlab\Filter\ProjectFilterInterface;

/**
* Test FilterCollection
*/
class FilterCollectionTest extends TestCase {

public function testEmpty(){
$filterCollection = new FilterCollection(new NullLogger());
$project = $this->createMockProject('test');
$this->assertTrue($filterCollection->isAccepted($project));
}

/**
* Create a fake project filter returning true or false
*
* @param boolean $accepted
* @return ProjectFilterInterface
*/
private function createMockFilter($accepted){
$filter = $this->getMockBuilder(ProjectFilterInterface::class)
->getMock()
;
$filter->expects($this->any())
->method('isAccepted')
->willReturn($accepted)
;
return $filter;
}


public function testOneTrue(){
$filterCollection = new FilterCollection(new NullLogger());
$filterCollection->addFilter($this->createMockFilter(true));
$project = $this->createMockProject('test');
$this->assertTrue($filterCollection->isAccepted($project));
}

public function testOneFalse(){
$filterCollection = new FilterCollection(new NullLogger());
$filterCollection->addFilter($this->createMockFilter(false));
$project = $this->createMockProject('test');
$this->assertFalse($filterCollection->isAccepted($project));
}

/**
* Check that isAccepted is unanymous
*/
public function testTrueFalseTrue(){
$filterCollection = new FilterCollection(new NullLogger());
$filterCollection->addFilter($this->createMockFilter(true));
$filterCollection->addFilter($this->createMockFilter(false));
$filterCollection->addFilter($this->createMockFilter(true));
$project = $this->createMockProject('test');
$this->assertFalse($filterCollection->isAccepted($project));
}

}

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use PHPUnit\Framework\TestCase;
namespace Tests\SatisGitlab\Filter;

use Tests\SatisGitlab\TestCase;

use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -12,23 +14,6 @@
*/
class IgnoreRegexpFilterTest extends TestCase {

/**
* Create a fake project with a given name
*
* @param string $projectName
* @return ProjectInterface
*/
private function createMockProject($projectName){
$project = $this->getMockBuilder(ProjectInterface::class)
->getMock()
;
$project->expects($this->any())
->method('getName')
->willReturn($projectName)
;
return $project;
}

public function testExample(){
$filter = new IgnoreRegexpFilter('(^phpstorm|^typo3\/library)');

Expand All @@ -46,7 +31,6 @@ public function testExample(){
'unexpected result for '.$projectName
);
}


}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
namespace Tests\SatisGitlab\Git;

use Tests\SatisGitlab\TestCase;

use GuzzleHttp\Client as GuzzleHttpClient;
use MBO\SatisGitlab\Git\GitlabClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
namespace Tests\SatisGitlab\Satis;

use Tests\SatisGitlab\TestCase;

use Symfony\Component\Console\Tester\CommandTester;
use MBO\SatisGitlab\Satis\ConfigBuilder;


class ConfigBuilderTest extends TestCase {

public function testDefaultConstructor(){
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tests\SatisGitlab;

use PHPUnit\Framework\TestCase as BaseTestCase;

use MBO\SatisGitlab\Git\ProjectInterface;

class TestCase extends BaseTestCase {

/**
* Create a fake project with a given name
*
* @param string $projectName
* @return ProjectInterface
*/
protected function createMockProject($projectName){
$project = $this->getMockBuilder(ProjectInterface::class)
->getMock()
;
$project->expects($this->any())
->method('getName')
->willReturn($projectName)
;
return $project;
}

}

0 comments on commit 8c14ed8

Please sign in to comment.