Skip to content

Commit

Permalink
Merge pull request #340 from owncloud/update-php-cs-fixer
Browse files Browse the repository at this point in the history
[Tests-Only][CI] Update php cs fixer to version 3
  • Loading branch information
phil-davis authored Jun 15, 2021
2 parents 3055b00 + 592724c commit 7e7e865
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 34 deletions.
52 changes: 42 additions & 10 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def main(ctx):

dependsOn(before, coverageTests)

nonCoverageTests = nonCoveragePipelines(ctx)
if (nonCoverageTests == False):
print('Errors detected in nonCoveragePipelines. Review messages above.')
return []

dependsOn(before, nonCoverageTests)

stages = stagePipelines(ctx)
if (stages == False):
print('Errors detected. Review messages above.')
Expand All @@ -98,18 +105,28 @@ def main(ctx):
dependsOn(coverageTests, afterCoverageTests)

after = afterPipelines(ctx)
dependsOn(afterCoverageTests + stages, after)
dependsOn(afterCoverageTests + nonCoverageTests + stages, after)

return before + coverageTests + afterCoverageTests + stages + after
return before + coverageTests + afterCoverageTests + nonCoverageTests + stages + after

def beforePipelines():
return codestyle() + jscodestyle() + phpstan() + phan()

def coveragePipelines(ctx):
# All pipelines that might have coverage or other test analysis reported
jsPipelines = javascript(ctx)
phpUnitPipelines = phpTests(ctx, 'phpunit')
phpIntegrationPipelines = phpTests(ctx, 'phpintegration')
# All unit test pipelines that have coverage or other test analysis reported
jsPipelines = javascript(ctx, True)
phpUnitPipelines = phpTests(ctx, 'phpunit', True)
phpIntegrationPipelines = phpTests(ctx, 'phpintegration', True)
if (jsPipelines == False) or (phpUnitPipelines == False) or (phpIntegrationPipelines == False):
return False

return jsPipelines + phpUnitPipelines + phpIntegrationPipelines

def nonCoveragePipelines(ctx):
# All unit test pipelines that do not have coverage or other test analysis reported
jsPipelines = javascript(ctx, False)
phpUnitPipelines = phpTests(ctx, 'phpunit', False)
phpIntegrationPipelines = phpTests(ctx, 'phpintegration', False)
if (jsPipelines == False) or (phpUnitPipelines == False) or (phpIntegrationPipelines == False):
return False

Expand Down Expand Up @@ -485,7 +502,7 @@ def build():

return pipelines

def javascript(ctx):
def javascript(ctx, withCoverage):
pipelines = []

if 'javascript' not in config:
Expand Down Expand Up @@ -523,6 +540,14 @@ def javascript(ctx):
if params['skip']:
return pipelines

# if we only want pipelines with coverage, and this pipeline does not do coverage, then do not include it
if withCoverage and not params['coverage']:
return pipelines

# if we only want pipelines without coverage, and this pipeline does coverage, then do not include it
if not withCoverage and params['coverage']:
return pipelines

result = {
'kind': 'pipeline',
'type': 'docker',
Expand Down Expand Up @@ -585,7 +610,7 @@ def javascript(ctx):

return [result]

def phpTests(ctx, testType):
def phpTests(ctx, testType, withCoverage):
pipelines = []

if testType not in config:
Expand Down Expand Up @@ -638,6 +663,14 @@ def phpTests(ctx, testType):
if params['skip']:
continue

# if we only want pipelines with coverage, and this pipeline does not do coverage, then do not include it
if withCoverage and not params['coverage']:
continue

# if we only want pipelines without coverage, and this pipeline does coverage, then do not include it
if not withCoverage and params['coverage']:
continue

cephS3Params = params['cephS3']
if type(cephS3Params) == "bool":
cephS3Needed = cephS3Params
Expand Down Expand Up @@ -824,7 +857,7 @@ def acceptance(ctx):
suites[suite] = suite
else:
suites = matrix['suites']

if 'debugSuites' in matrix and len(matrix['debugSuites']) != 0:
if type(matrix['debugSuites']) == "list":
suites = {}
Expand Down Expand Up @@ -1221,7 +1254,6 @@ def ldapService(ldapNeeded):
'LDAP_ORGANISATION': 'owncloud',
'LDAP_ADMIN_PASSWORD': 'admin',
'LDAP_TLS_VERIFY_CLIENT': 'never',
'HOSTNAME': 'ldap',
}
}]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ nbproject
/.buildpath

.php_cs.cache
.php-cs-fixer.cache

# Composer
vendor/
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ test-php-codecheck: ## Test php codecheck
.PHONY: test-php-style
test-php-style: ## Run php-cs-fixer and check owncloud code-style
test-php-style: vendor-bin/owncloud-codestyle/vendor vendor-bin/php_codesniffer/vendor
$(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes --dry-run
$(PHP_CS_FIXER) fix -v --diff --allow-risky yes --dry-run
$(PHP_CODESNIFFER) --runtime-set ignore_warnings_on_exit --standard=phpcs.xml tests/acceptance

.PHONY: test-php-style-fix
test-php-style-fix: ## Run php-cs-fixer and fix code style issues
test-php-style-fix: vendor-bin/owncloud-codestyle/vendor
$(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes
$(PHP_CS_FIXER) fix -v --diff --allow-risky yes

.PHONY: test-php-phan
test-php-phan: ## Run phan
Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/NotificationOptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use OCA\Notifications\Configuration\OptionsStorage;

class NotificationOptionsController extends Controller {
const ERROR_CODE_MISSING_USER_SESSION = 1;
const ERROR_CODE_OPTION_NOT_SUPPORTED = 2;
const ERROR_CODE_INCOMPLETE_DATA = 3;
public const ERROR_CODE_MISSING_USER_SESSION = 1;
public const ERROR_CODE_OPTION_NOT_SUPPORTED = 2;
public const ERROR_CODE_INCOMPLETE_DATA = 3;

/** @var IUserSession */
private $userSession;
Expand Down
18 changes: 12 additions & 6 deletions lib/Mailer/NotificationMailerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,29 @@ public function sendMail(INotification $notification) {
$targetUser = $notification->getUser();

if (!$this->sender->willSendNotification($notification)) {
$this->logger->debug("notification $nObjectType#$nObjectId won't be sent to $targetUser via email: personal configuration for $targetUser prevents it",
['app' => $this->appName]);
$this->logger->debug(
"notification $nObjectType#$nObjectId won't be sent to $targetUser via email: personal configuration for $targetUser prevents it",
['app' => $this->appName]
);
return;
}

$userObject = $this->userManager->get($targetUser);

if ($userObject === null) {
$this->logger->warning("notification $nObjectType#$nObjectId can't be sent to $targetUser via email: the user is missing",
['app' => $this->appName]);
$this->logger->warning(
"notification $nObjectType#$nObjectId can't be sent to $targetUser via email: the user is missing",
['app' => $this->appName]
);
return;
}

$targetEmail = $userObject->getEMailAddress();
if ($targetEmail === null) {
$this->logger->warning("notification $nObjectType#$nObjectId can't be sent to $targetUser via email: email for the user isn't set",
['app' => $this->appName]);
$this->logger->warning(
"notification $nObjectType#$nObjectId can't be sent to $targetUser via email: email for the user isn't set",
['app' => $this->appName]
);
return;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Controller/EndpointControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ public function testNotificationToArray($id, $app, $user, $timestamp, $objectTyp
->method('actionToArray')
->willReturn('action');

$this->assertEquals([
$this->assertEquals(
[
'notification_id' => $id,
'app' => $app,
'user' => $user,
Expand Down Expand Up @@ -474,7 +475,8 @@ public function testActionToArray($label, $link, $requestType, $isPrimary) {
->method('isPrimary')
->willReturn($isPrimary);

$this->assertEquals([
$this->assertEquals(
[
'label' => $label,
'link' => $link,
'type' => $requestType,
Expand Down
26 changes: 18 additions & 8 deletions tests/acceptance/features/bootstrap/NotificationsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function userIsSentANotification($user) {
$bodyTable = new TableNode([['user', $user]]);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'POST', '/apps/testing/api/v1/notifications',
'POST',
'/apps/testing/api/v1/notifications',
$bodyTable,
null
);
Expand All @@ -80,7 +81,8 @@ public function userHasBeenSentANotification($user) {
$response = $this->featureContext->getResponse();
Assert::assertEquals(200, $response->getStatusCode());
Assert::assertEquals(
200, (int) $this->ocsContext->getOCSResponseStatusCode($response)
200,
(int) $this->ocsContext->getOCSResponseStatusCode($response)
);
}

Expand Down Expand Up @@ -128,7 +130,9 @@ public function userIsSentANotificationWith($user, TableNode $formData) {

$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->featureContext->getAdminUsername(),
'POST', '/apps/testing/api/v1/notifications', $formData
'POST',
'/apps/testing/api/v1/notifications',
$formData
);
}

Expand All @@ -145,7 +149,8 @@ public function userHasBeenSentANotificationWith($user, TableNode $formData) {
$response = $this->featureContext->getResponse();
Assert::assertEquals(200, $response->getStatusCode());
Assert::assertEquals(
200, (int) $this->ocsContext->getOCSResponseStatusCode($response)
200,
(int) $this->ocsContext->getOCSResponseStatusCode($response)
);
}

Expand Down Expand Up @@ -235,26 +240,31 @@ public function userSetsEmailNotificationOption($user, $setting) {

$response = HttpRequestHelper::sendRequest(
$fullUrl,
"PATCH", $user, $this->featureContext->getUserPassword($user),
"PATCH",
$user,
$this->featureContext->getUserPassword($user),
['Content-Type' => 'application/json'],
'{"email_sending_option":"' . $setting . '"}'
);
$this->setCSRFDotDisabled($oldCSRFSetting);

Assert::assertEquals(
200, $response->getStatusCode(),
200,
$response->getStatusCode(),
"could not set notification option " . $response->getReasonPhrase()
);
$responseDecoded = \json_decode($response->getBody());
Assert::assertEquals(
$responseDecoded->data->options->id, $user,
$responseDecoded->data->options->id,
$user,
"Could not set notification option! " .
"'user' in the response is:'" .
$responseDecoded->data->options->id . "' " .
"but should be: '$user'"
);
Assert::assertEquals(
$responseDecoded->data->options->email_sending_option, $setting,
$responseDecoded->data->options->email_sending_option,
$setting,
"Could not set notification option! " .
"'email_sending_option' in the response is:'" .
$responseDecoded->data->options->email_sending_option . "' " .
Expand Down
4 changes: 3 additions & 1 deletion tests/acceptance/features/bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
$classLoader = new \Composer\Autoload\ClassLoader();
$classLoader->addPsr4("Page\\", __DIR__ . "/../lib", true);
$classLoader->addPsr4(
"", __DIR__ . "/../../../../../../tests/acceptance/features/bootstrap", true
"",
__DIR__ . "/../../../../../../tests/acceptance/features/bootstrap",
true
);

$classLoader->register();
4 changes: 2 additions & 2 deletions vendor-bin/owncloud-codestyle/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"owncloud/coding-standard": "^2.0"
"owncloud/coding-standard": "^3.0"
}
}
}

0 comments on commit 7e7e865

Please sign in to comment.