Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion .github/workflows/lint-and-analyse-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ permissions:
contents: read

jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ["8.2", "8.3"]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Set up PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install Composer dependencies
# Allow the previous check to fail but not abort
if: always()
uses: ramsey/composer-install@v2
with:
# Ignore zip for php-webdriver/webdriver
composer-options: "--ignore-platform-req=ext-zip"

- name: Create config.php for unit tests
run: cp config/config.dist.php config/config.php

- name: Unit Tests
run: composer phpunit

lint-php-files:
runs-on: ubuntu-latest
strategy:
Expand All @@ -41,7 +74,7 @@ jobs:
uses: ramsey/composer-install@v2
with:
# Ignore zip for php-webdriver/webdriver
composer-options: "--ignore-platform-req=ext-zip"
composer-options: "--ignore-platform-reqs"

# TODO: Enable this after resolving issues
# - name: Cache coding-standard
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@

# php8 phpcompatibility report
php8-report.log

# phpunit cache
.phpunit.cache/test-results
1 change: 1 addition & 0 deletions Domain/CreditCost.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class CreditCost
{
/**
* Number of Credits for the given cost
* @var int
*/
private $count;
Expand Down
8 changes: 7 additions & 1 deletion Pages/ResourceDisplayPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public function GetTimezone();
*/
public function GetBeginTime();

/**
*
* @return string
*/
public function GetBeginDate();

/**
* @return string
*/
Expand Down Expand Up @@ -237,7 +243,7 @@ public function GetStartDate()
}
return $startDate;
}

public function BindResource(BookableResource $resource)
{
$this->Set('ResourceName', $resource->GetName());
Expand Down
2 changes: 1 addition & 1 deletion Presenters/ResourceDisplayPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function Reserve()
$maxDate = Date::Now()->ToTimezone($timezone)->AddDays($maxFutureDays+1)->GetDate();

$resultCollector = new ReservationResultCollector();

if ($date->GetBegin()->GreaterThan($maxDate)) {
$resultCollector->SetSaveSuccessfulMessage(false);
$resultCollector->SetErrors(["Unauthorized"]);
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"require-dev": {
"squizlabs/php_codesniffer": "^3.7.1",
"phpcompatibility/php-compatibility": "^9.3.5",
"kint-php/kint": "^4.2.3"
"kint-php/kint": "^4.2.3",
"phpunit/phpunit": "^11.3"
},
"require": {
"php": ">=8.1",
Expand Down Expand Up @@ -35,8 +36,9 @@
"build": "./tools/phing",
"fix": "./tools/php-cs-fixer fix -v",
"lint": "./tools/php-cs-fixer fix -vv --dry-run",
"phpunit": "./vendor/bin/phpunit",
"test": [
"./tools/phpunit",
"@phpunit",
"@lint"
],
"sniffer:php8": "phpcs -p ./ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --report-full=./php8-report.log --ignore=./vendor/*,./tools/*,./.git/*,./tpl_c/*,./build/*,./.phpdoc/*,./var/*,./Web/scripts/*,./Web/css/* --runtime-set testVersion 8.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/Common/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public function SubtractMinutes($minutes)
*/
public function AddHours($hours)
{
return new Date($this->Format(self::SHORT_FORMAT) . " +" . $hours . " hours", $this->timezone);
return new Date($this->Format(self::SHORT_FORMAT) . $this->getOperator($hours) . abs($hours) . " hours", $this->timezone);
}

/**
Expand Down
117 changes: 48 additions & 69 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,73 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- doc: https://phpunit.readthedocs.io/en/latest/configuration.html -->
<!-- manpage: https://manpages.debian.org/testing/phpunit/phpunit.1.en.html -->

<phpunit bootstrap = "./tests/autoload.php"
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
cacheResultFile = "./var/cache/.phpunit.result.cache"
verbose = "false"
defaultTestSuite = "all"
>
<!-- organizing tests: https://phpunit.readthedocs.io/en/latest/organizing-tests.html -->
<testsuites>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html#the-testsuite-element -->
<!-- run only specificed tests: 'phpunit -_-filter [path/to/*Test.php / folder with tests]' -->
<!-- run only a specific testsuite: 'phpunit -_-testsuite <testsuite-name>' -->
<testsuite name="all">
<directory>./tests</directory>
</testsuite>

<testsuite name="application">
<directory>./tests/Application</directory>
</testsuite>

<testsuite name="domain">
<directory>./tests/Domain</directory>
</testsuite>

<testsuite name="plugins">
<directory>./tests/Plugins</directory>
</testsuite>

<testsuite name="presenters">
<directory>./tests/Presenters</directory>
</testsuite>

<testsuite name="webservice">
<directory>./tests/WebService</directory>
</testsuite>

<testsuite name="webservices">
<directory>./tests/WebServices</directory>
</testsuite>
</testsuites>

<!-- to generate coverage report: phpunit -_-coverage-html ./var/ -->
<coverage cacheDirectory="./var/cache/phpunit">
<include>
<directory suffix=".php">Controls</directory>
<directory suffix=".php">Domain</directory>
<directory suffix=".php">Jobs</directory>
<directory suffix=".php">lib</directory>
<directory suffix=".php">Pages</directory>
<directory suffix=".php">Plugins</directory>
<directory suffix=".php">Presenters</directory>
<directory suffix=".php">Web</directory>
<directory suffix=".php">WebServices</directory>
</include>
<exclude>
<directory suffix=".php">lib/external</directory>
</exclude>
</coverage>

<php>
<env name="APP_ENV" value="testing"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" defaultTestSuite="all" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<!-- organizing tests: https://phpunit.readthedocs.io/en/latest/organizing-tests.html -->
<testsuites>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html#the-testsuite-element -->
<!-- run only specificed tests: 'phpunit -_-filter [path/to/*Test.php / folder with tests]' -->
<!-- run only a specific testsuite: 'phpunit -_-testsuite <testsuite-name>' -->
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
<testsuite name="application">
<directory>./tests/Application</directory>
</testsuite>
<testsuite name="domain">
<directory>./tests/Domain</directory>
</testsuite>
<testsuite name="plugins">
<directory>./tests/Plugins</directory>
</testsuite>
<testsuite name="presenters">
<directory>./tests/Presenters</directory>
</testsuite>
<testsuite name="webservice">
<directory>./tests/WebService</directory>
</testsuite>
<testsuite name="webservices">
<directory>./tests/WebServices</directory>
</testsuite>
</testsuites>
<!-- to generate coverage report: phpunit -_-coverage-html ./var/ -->
<php>
<env name="APP_ENV" value="testing"/>
</php>
<source>
<include>
<directory suffix=".php">Controls</directory>
<directory suffix=".php">Domain</directory>
<directory suffix=".php">Jobs</directory>
<directory suffix=".php">lib</directory>
<directory suffix=".php">Pages</directory>
<directory suffix=".php">Plugins</directory>
<directory suffix=".php">Presenters</directory>
<directory suffix=".php">Web</directory>
<directory suffix=".php">WebServices</directory>
</include>
<exclude>
<directory suffix=".php">lib/external</directory>
</exclude>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions tests/Application/Admin/GroupAdminGroupsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php');

class GroupAdminGroupsRepositoryTests extends TestBase
class GroupAdminGroupsRepositoryTest extends TestBase
{
public function testGetsListOfGroupsThatThisUserCanAdminister()
{
Expand All @@ -16,7 +16,7 @@ public function testGetsListOfGroupsThatThisUserCanAdminister()
$userRepo->expects($this->once())
->method('LoadById')
->with($this->equalTo($this->fakeUser->UserId))
->will($this->returnValue($user));
->willReturn($user);

$groupRepository = new GroupAdminGroupRepository($userRepo, $this->fakeUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php');

class GroupAdminManageReservationsServiceTests extends TestBase
class GroupAdminManageReservationsServiceTest extends TestBase
{
public function testGetsListOfReservationsThatThisUserCanAdminister()
{
Expand All @@ -19,7 +19,7 @@ public function testGetsListOfReservationsThatThisUserCanAdminister()
$userRepo->expects($this->once())
->method('LoadById')
->with($this->equalTo($this->fakeUser->UserId))
->will($this->returnValue($user));
->willReturn($user);

$service = new GroupAdminManageReservationsService($reservationRepo, $userRepo, $reservationAuth, $handler, $persistenceService);

Expand Down
10 changes: 5 additions & 5 deletions tests/Application/Admin/ManageReservationsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php');

class ManageReservationsServiceTests extends TestBase
class ManageReservationsServiceTest extends TestBase
{
/**
* @var IReservationViewRepository|PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese
$this->reservationViewRepository->expects($this->once())
->method('GetList')
->with($pageNumber, $pageSize, null, null, $filter->GetFilter())
->will($this->returnValue($data));
->willReturn($data);

$actualData = $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser);

Expand All @@ -74,12 +74,12 @@ public function testLoadsReservationIfTheUserCanEdit()
$this->reservationViewRepository->expects($this->once())
->method('GetReservationForEditing')
->with($this->equalTo($referenceNumber))
->will($this->returnValue($reservation));
->willReturn($reservation);

$this->reservationAuthorization->expects($this->once())
->method('CanEdit')
->with($this->equalTo($reservation), $this->equalTo($user))
->will($this->returnValue(true));
->willReturn(true);

$res = $this->service->LoadByReferenceNumber($referenceNumber, $user);

Expand All @@ -103,7 +103,7 @@ public function testUpdatesReservationAttributeIfTheUserCanEdit()
$this->persistenceService->expects($this->once())
->method('LoadByReferenceNumber')
->with($this->equalTo($referenceNumber))
->will($this->returnValue($reservation));
->willReturn($reservation);

$this->reservationHandler->expects($this->once())
->method('Handle')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once(ROOT_DIR . 'lib/Application/Admin/namespace.php');

class ResourceAdminManageReservationsServiceTests extends TestBase
class ResourceAdminManageReservationsServiceTest extends TestBase
{
/**
* @var IReservationViewRepository|PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese
$this->userRepository->expects($this->once())
->method('LoadGroups')
->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::RESOURCE_ADMIN))
->will($this->returnValue($groups));
->willReturn($groups);

$filter = new ReservationFilter();
$expectedFilter = $filter->GetFilter();
Expand All @@ -63,7 +63,7 @@ public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingRese
$this->reservationViewRepository->expects($this->once())
->method('GetList')
->with($pageNumber, $pageSize, null, null, $expectedFilter)
->will($this->returnValue($data));
->willReturn($data);

$actualData = $this->service->LoadFiltered($pageNumber, $pageSize, null, null, $filter, $this->fakeUser);

Expand Down
Loading