use codecov for code coverage (#833)
This commit is contained in:
29
.codecov.yml
Normal file
29
.codecov.yml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
codecov:
|
||||||
|
notify:
|
||||||
|
require_ci_to_pass: yes
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
precision: 2
|
||||||
|
round: down
|
||||||
|
range: "80...100"
|
||||||
|
|
||||||
|
status:
|
||||||
|
project: yes
|
||||||
|
patch: yes
|
||||||
|
changes: no
|
||||||
|
|
||||||
|
parsers:
|
||||||
|
gcov:
|
||||||
|
branch_detection:
|
||||||
|
conditional: yes
|
||||||
|
loop: yes
|
||||||
|
method: no
|
||||||
|
macro: no
|
||||||
|
|
||||||
|
comment:
|
||||||
|
layout: "diff, flags, files"
|
||||||
|
behavior: default
|
||||||
|
require_changes: yes
|
||||||
|
require_base: no
|
||||||
|
require_head: yes
|
||||||
|
branches: null
|
||||||
15
.travis.yml
15
.travis.yml
@@ -11,14 +11,19 @@ addons:
|
|||||||
services:
|
services:
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- CODECOVERAGE=0
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
- php: 7.3
|
- php: 7.3
|
||||||
|
env: CODECOVERAGE=1
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- phpenv config-rm xdebug.ini
|
# - phpenv config-rm xdebug.ini
|
||||||
- composer self-update
|
- composer self-update
|
||||||
- php -i
|
- php -i
|
||||||
|
|
||||||
@@ -26,8 +31,9 @@ install:
|
|||||||
- composer install
|
- composer install
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- php -r "echo date(DATE_RFC850);"
|
- composer codestyle
|
||||||
- composer code-check
|
- composer phpstan
|
||||||
|
- if [[ $CODECOVERAGE == 1 ]]; then vendor/bin/phpunit tests/ --coverage-clover=coverage.xml; else vendor/bin/phpunit tests/; fi;
|
||||||
- cp tests/.env.dist.sqlite .env
|
- cp tests/.env.dist.sqlite .env
|
||||||
- bin/console doctrine:database:create -n
|
- bin/console doctrine:database:create -n
|
||||||
- bin/console doctrine:migrations:migrate -n
|
- bin/console doctrine:migrations:migrate -n
|
||||||
@@ -36,3 +42,6 @@ script:
|
|||||||
- bin/console doctrine:database:create -n
|
- bin/console doctrine:database:create -n
|
||||||
- bin/console doctrine:migrations:migrate -n
|
- bin/console doctrine:migrations:migrate -n
|
||||||
- bin/console doctrine:migrations:migrate first -n
|
- bin/console doctrine:migrations:migrate first -n
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- if [[ $CODECOVERAGE == 1 ]]; then bash <(curl -s https://codecov.io/bash); fi
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ Kimai - the open source time-tracker application with a mobile-first approach (r
|
|||||||
[](https://packagist.org/packages/kevinpapst/kimai2)
|
[](https://packagist.org/packages/kevinpapst/kimai2)
|
||||||
[](https://packagist.org/packages/kevinpapst/kimai2)
|
[](https://packagist.org/packages/kevinpapst/kimai2)
|
||||||
[](https://travis-ci.org/kevinpapst/kimai2)
|
[](https://travis-ci.org/kevinpapst/kimai2)
|
||||||
[](https://scrutinizer-ci.com/g/kevinpapst/kimai2/?branch=master)
|
[](https://codecov.io/gh/kevinpapst/kimai2)
|
||||||
[](https://scrutinizer-ci.com/g/kevinpapst/kimai2/build-status/master)
|
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ use App\Entity\Project;
|
|||||||
use App\Entity\Timesheet;
|
use App\Entity\Timesheet;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||||
|
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
|
||||||
|
use App\Timesheet\UserDateTimeFactory;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,10 +26,17 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
|||||||
{
|
{
|
||||||
public const DATE_FORMAT = 'Y-m-d H:i:s';
|
public const DATE_FORMAT = 'Y-m-d H:i:s';
|
||||||
public const DATE_FORMAT_HTML5 = 'Y-m-d\TH:i:s';
|
public const DATE_FORMAT_HTML5 = 'Y-m-d\TH:i:s';
|
||||||
|
public const TEST_TIMEZONE = 'Europe/London';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var UserDateTimeFactory
|
||||||
|
*/
|
||||||
|
protected $dateTime;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->importFixtureForUser(User::ROLE_USER);
|
$this->importFixtureForUser(User::ROLE_USER);
|
||||||
|
$this->dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function importFixtureForUser(string $role)
|
protected function importFixtureForUser(string $role)
|
||||||
@@ -278,8 +287,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
|||||||
$data = [
|
$data = [
|
||||||
'activity' => 1,
|
'activity' => 1,
|
||||||
'project' => 1,
|
'project' => 1,
|
||||||
'begin' => (new \DateTime('- 8 hours'))->format('Y-m-d H:m'),
|
'begin' => ($this->dateTime->createDateTime('- 16 hours'))->format('Y-m-d H:m:0'),
|
||||||
'end' => (new \DateTime())->format('Y-m-d H:m'),
|
'end' => ($this->dateTime->createDateTime())->format('Y-m-d H:m:0'),
|
||||||
'description' => 'foo',
|
'description' => 'foo',
|
||||||
'fixedRate' => 2016,
|
'fixedRate' => 2016,
|
||||||
'hourlyRate' => 127
|
'hourlyRate' => 127
|
||||||
@@ -291,7 +300,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
|||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
$this->assertDefaultStructure($result);
|
$this->assertDefaultStructure($result);
|
||||||
$this->assertNotEmpty($result['id']);
|
$this->assertNotEmpty($result['id']);
|
||||||
$this->assertEquals(28800, $result['duration']);
|
$this->assertTrue($result['duration'] == 57600 || $result['duration'] == 57660); // 1 minute rounding might be applied
|
||||||
$this->assertEquals(2016, $result['rate']);
|
$this->assertEquals(2016, $result['rate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,8 +366,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
|||||||
$data = [
|
$data = [
|
||||||
'activity' => 1,
|
'activity' => 1,
|
||||||
'project' => 1,
|
'project' => 1,
|
||||||
'begin' => (new \DateTime('- 7 hours'))->format('Y-m-d\TH:m'),
|
'begin' => ($this->dateTime->createDateTime('- 7 hours'))->format('Y-m-d\TH:m:0'),
|
||||||
'end' => (new \DateTime())->format('Y-m-d\TH:m'),
|
'end' => ($this->dateTime->createDateTime())->format('Y-m-d\TH:m:0'),
|
||||||
'description' => 'foo',
|
'description' => 'foo',
|
||||||
'exported' => true,
|
'exported' => true,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -9,16 +9,11 @@
|
|||||||
|
|
||||||
namespace App\Tests\Export\Renderer;
|
namespace App\Tests\Export\Renderer;
|
||||||
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Export\Renderer\PDFRenderer;
|
use App\Export\Renderer\PDFRenderer;
|
||||||
use App\Repository\UserRepository;
|
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
|
||||||
use App\Security\CurrentUser;
|
|
||||||
use App\Timesheet\UserDateTimeFactory;
|
|
||||||
use App\Utils\HtmlToPdfConverter;
|
use App\Utils\HtmlToPdfConverter;
|
||||||
use App\Utils\MPdfConverter;
|
use App\Utils\MPdfConverter;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,17 +24,7 @@ class PdfRendererTest extends AbstractRendererTest
|
|||||||
{
|
{
|
||||||
protected function getDateTimeFactory()
|
protected function getDateTimeFactory()
|
||||||
{
|
{
|
||||||
$user = new User();
|
return (new UserDateTimeFactoryFactory($this))->create();
|
||||||
$repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getById'])->disableOriginalConstructor()->getMock();
|
|
||||||
$repository->expects($this->once())->method('getById')->willReturn($user);
|
|
||||||
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
|
|
||||||
$token->expects($this->once())->method('getUser')->willReturn($user);
|
|
||||||
$tokenStorage = new TokenStorage();
|
|
||||||
$tokenStorage->setToken($token);
|
|
||||||
|
|
||||||
$user = new CurrentUser($tokenStorage, $repository);
|
|
||||||
|
|
||||||
return new UserDateTimeFactory($user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConfiguration()
|
public function testConfiguration()
|
||||||
|
|||||||
31
tests/Mocks/AbstractMockFactory.php
Normal file
31
tests/Mocks/AbstractMockFactory.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Kimai time-tracking app.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Tests\Mocks;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockBuilder;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
abstract class AbstractMockFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var TestCase
|
||||||
|
*/
|
||||||
|
protected $testCase;
|
||||||
|
|
||||||
|
public function __construct(TestCase $testCase)
|
||||||
|
{
|
||||||
|
$this->testCase = $testCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getMockBuilder(string $className): MockBuilder
|
||||||
|
{
|
||||||
|
return new MockBuilder($this->testCase, $className);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
tests/Mocks/Security/UserDateTimeFactoryFactory.php
Normal file
47
tests/Mocks/Security/UserDateTimeFactoryFactory.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Kimai time-tracking app.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Tests\Mocks\Security;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Entity\UserPreference;
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use App\Security\CurrentUser;
|
||||||
|
use App\Tests\Mocks\AbstractMockFactory;
|
||||||
|
use App\Timesheet\UserDateTimeFactory;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
|
|
||||||
|
class UserDateTimeFactoryFactory extends AbstractMockFactory
|
||||||
|
{
|
||||||
|
public function create(?string $timezone = null): UserDateTimeFactory
|
||||||
|
{
|
||||||
|
return new UserDateTimeFactory($this->getCurrentUserMock($timezone));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getCurrentUserMock(?string $timezone = null)
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
if (null !== $timezone) {
|
||||||
|
$pref = new UserPreference();
|
||||||
|
$pref->setName('timezone');
|
||||||
|
$pref->setValue($timezone);
|
||||||
|
$user->addPreference($pref);
|
||||||
|
}
|
||||||
|
$repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getById'])->disableOriginalConstructor()->getMock();
|
||||||
|
$repository->expects(TestCase::exactly(1))->method('getById')->willReturn($user);
|
||||||
|
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
|
||||||
|
$token->expects(TestCase::exactly(1))->method('getUser')->willReturn($user);
|
||||||
|
$tokenStorage = new TokenStorage();
|
||||||
|
$tokenStorage->setToken($token);
|
||||||
|
|
||||||
|
return new CurrentUser($tokenStorage, $repository);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,14 +9,9 @@
|
|||||||
|
|
||||||
namespace App\Tests\Timesheet;
|
namespace App\Tests\Timesheet;
|
||||||
|
|
||||||
use App\Entity\User;
|
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
|
||||||
use App\Entity\UserPreference;
|
|
||||||
use App\Repository\UserRepository;
|
|
||||||
use App\Security\CurrentUser;
|
|
||||||
use App\Timesheet\UserDateTimeFactory;
|
use App\Timesheet\UserDateTimeFactory;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \App\Timesheet\UserDateTimeFactory
|
* @covers \App\Timesheet\UserDateTimeFactory
|
||||||
@@ -25,28 +20,9 @@ class UserDateTimeFactoryTest extends TestCase
|
|||||||
{
|
{
|
||||||
public const TEST_TIMEZONE = 'Europe/London';
|
public const TEST_TIMEZONE = 'Europe/London';
|
||||||
|
|
||||||
protected function createDateTimeFactory(string $timezone)
|
protected function createDateTimeFactory(?string $timezone = null): UserDateTimeFactory
|
||||||
{
|
{
|
||||||
return new UserDateTimeFactory($this->getCurrentUserMock($timezone));
|
return (new UserDateTimeFactoryFactory($this))->create($timezone);
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCurrentUserMock($timezone = null)
|
|
||||||
{
|
|
||||||
$user = new User();
|
|
||||||
if (null !== $timezone) {
|
|
||||||
$pref = new UserPreference();
|
|
||||||
$pref->setName('timezone');
|
|
||||||
$pref->setValue($timezone);
|
|
||||||
$user->addPreference($pref);
|
|
||||||
}
|
|
||||||
$repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getById'])->disableOriginalConstructor()->getMock();
|
|
||||||
$repository->expects($this->once())->method('getById')->willReturn($user);
|
|
||||||
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
|
|
||||||
$token->expects($this->once())->method('getUser')->willReturn($user);
|
|
||||||
$tokenStorage = new TokenStorage();
|
|
||||||
$tokenStorage->setToken($token);
|
|
||||||
|
|
||||||
return new CurrentUser($tokenStorage, $repository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetTimezone()
|
public function testGetTimezone()
|
||||||
@@ -57,20 +33,13 @@ class UserDateTimeFactoryTest extends TestCase
|
|||||||
|
|
||||||
public function testGetTimezoneWithFallbackTimezone()
|
public function testGetTimezoneWithFallbackTimezone()
|
||||||
{
|
{
|
||||||
$repository = $this->getMockBuilder(UserRepository::class)->disableOriginalConstructor()->getMock();
|
$sut = $this->createDateTimeFactory();
|
||||||
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
|
|
||||||
$token->expects($this->once())->method('getUser')->willReturn('anonymous');
|
|
||||||
$tokenStorage = new TokenStorage();
|
|
||||||
$tokenStorage->setToken($token);
|
|
||||||
|
|
||||||
$current = new CurrentUser($tokenStorage, $repository);
|
|
||||||
$sut = new UserDateTimeFactory($current);
|
|
||||||
$this->assertEquals(date_default_timezone_get(), $sut->getTimezone()->getName());
|
$this->assertEquals(date_default_timezone_get(), $sut->getTimezone()->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStartOfMonth()
|
public function testGetStartOfMonth()
|
||||||
{
|
{
|
||||||
$expected = new \DateTime();
|
$expected = new \DateTime('now', new \DateTimeZone(self::TEST_TIMEZONE));
|
||||||
|
|
||||||
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
||||||
$dateTime = $sut->getStartOfMonth();
|
$dateTime = $sut->getStartOfMonth();
|
||||||
@@ -85,7 +54,7 @@ class UserDateTimeFactoryTest extends TestCase
|
|||||||
|
|
||||||
public function testGetEndOfMonth()
|
public function testGetEndOfMonth()
|
||||||
{
|
{
|
||||||
$expected = new \DateTime('last day of this month');
|
$expected = new \DateTime('last day of this month', new \DateTimeZone(self::TEST_TIMEZONE));
|
||||||
|
|
||||||
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
||||||
$dateTime = $sut->getEndOfMonth();
|
$dateTime = $sut->getEndOfMonth();
|
||||||
|
|||||||
Reference in New Issue
Block a user