Skip to content

Commit

Permalink
Add get_issues unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
badele committed Apr 25, 2019
1 parent 61d743a commit b7052fd
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -6,6 +6,7 @@ TO=0.0.3
SHUNIT=2.1.7
SCOPE=montpellier
NOW:=$(shell date +'%Y%m%d%H%M%S')
WAIT:=8

# Database information
BKDATE=NODATE
Expand Down Expand Up @@ -81,8 +82,8 @@ unittest: env

start: env ## Start a docker compose stack
@docker-compose -f docker-compose_${ENV}.yml up -d
@echo "Waiting 10 sec for stating container and restoring database ..."
@sleep 10
@echo "Waiting ${WAIT} sec for stating container and restoring database ..."
@sleep ${WAIT}


test-webserver: shunit2
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Expand Up @@ -13,6 +13,9 @@
<testsuite name="Database">
<directory suffix="Test.php">./tests/Database</directory>
</testsuite>
<testsuite name="App">
<directory suffix="Test.php">./tests/App</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
Expand Down
141 changes: 141 additions & 0 deletions tests/App/GetIssuesTest.php
@@ -0,0 +1,141 @@
<?php
/*
Copyright (C) 2019 Velocité Montpellier
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

use PHPUnit\Framework\TestCase;

set_include_path(implode(PATH_SEPARATOR, array(
realpath(__DIR__ . '/..'),
get_include_path()
)));

require_once(realpath("app/includes/common.php"));
require_once(realpath("app/get_issues.php"));

class GetIssueTest extends TestCase
{
public static function setUpBeforeClass() : void
{
}

public static function tearDownAfterClass() : void
{
}

public function testExportSetCategorieWithNotNumericValue()
{
$export = new GetIssues();

$this->expectExceptionMessage('is not numeric value');
$export->setCategorie("ABC");
}

public function testExportSetStatusWithNotNumericValue()
{
$export = new GetIssues();

$this->expectExceptionMessage('is not numeric value');
$export->setStatus("ABC");
}

public function testExportSetTimefilterWithNotNumericValue()
{
$export = new GetIssues();

$this->expectExceptionMessage('is not numeric value');
$export->setTimefilter("ABC");
}

public function testExportSetCountWithNotNumericValue()
{
$export = new GetIssues();

$this->expectExceptionMessage('is not numeric value');
$export->setCount("ABC");
}

public function testExportSetOffsetWithNotNumericValue()
{
$export = new GetIssues();

$this->expectExceptionMessage('is not numeric value');
$export->setOffset("ABC");
}

public function testExportWithoutOptions()
{
$export = new GetIssues();
$result = $export->getIssues();

$this->assertEquals(count($result), 10);
}

public function testExportByCategorie()
{
$export = new GetIssues();
$export->setCategorie(2);
$result = $export->getIssues();

$this->assertEquals(count($result), 5);
}

public function testExportByTime()
{
$export = new GetIssues();
$export->setTimefilter(1554454520);
$result = $export->getIssues();

$this->assertEquals(count($result), 2);
}

public function testExportByStatus()
{
$export = new GetIssues();
$export->setStatus(0);
$result = $export->getIssues();

$this->assertEquals(count($result), 10);
}

public function testExportByToken()
{
$export = new GetIssues();
$export->setToken("4XUXXEUX");
$result = $export->getIssues();

$this->assertEquals(count($result), 1);
}

public function testExportByScope()
{
$export = new GetIssues();
$export->setScope("34_montpellier");
$result = $export->getIssues();

$this->assertEquals(count($result), 10);
}

public function testExportWithPager()
{
$export = new GetIssues();
$export->setCount(3);
$result = $export->getIssues();

$this->assertEquals(count($result), 3);
}
}

0 comments on commit b7052fd

Please sign in to comment.