Skip to content

Commit

Permalink
psalm error resolved
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
  • Loading branch information
nabim777 committed Aug 1, 2024
1 parent d5b98bb commit dc97da6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/Migration/Version2640Date20240628114301.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array<string, string|null> $options
* @param array $options
* @return null|ISchemaWrapper
* @throws DoesNotExistException
* @throws Exception
Expand Down
5 changes: 4 additions & 1 deletion tests/acceptance/features/bootstrap/DirectUploadContext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
Expand Down Expand Up @@ -215,6 +216,8 @@ public function before(BeforeScenarioScope $scope):void {
$environment = $scope->getEnvironment();

// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
if($environment instanceof InitializedContextEnvironment) {
$this->featureContext = $environment->getContext('FeatureContext');
}
}
}
59 changes: 39 additions & 20 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
Expand Down Expand Up @@ -32,7 +33,7 @@ class FeatureContext implements Context {
private SharingContext $sharingContext;
private DirectUploadContext $directUploadContext;
/**
* @var array<int>
* @var array<int|null>
*/
private array $createdFiles = [];

Expand Down Expand Up @@ -575,7 +576,7 @@ public function uploadFileWithContent(
string $user,
?string $content,
string $destination
): int {
): ?int {
$this->response = $this->makeDavRequest(
$user,
$this->regularUserPassword,
Expand Down Expand Up @@ -692,28 +693,39 @@ public function verifyTableNodeColumns(TableNode $table, ?array $requiredHeader
}
}

public function getIdOfElement(string $user, string $element): int {
$propfindResponse = $this->makeDavRequest(
$user,
$this->regularUserPassword,
"PROPFIND",
$element,
null,
'<?xml version="1.0"?>
/**
* @param string $user
* @param string $element
*
* @return int|null
*/
public function getIdOfElement(string $user, string $element): ?int {
try {
$propfindResponse = $this->makeDavRequest(
$user,
$this->regularUserPassword,
"PROPFIND",
$element,
null,
'<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
<oc:fileid />
</d:prop>
</d:propfind>'
);
$xmlBody = $propfindResponse->getBody()->getContents();
$responseXmlObject = new SimpleXMLElement($xmlBody);
$responseXmlObject->registerXPathNamespace(
'oc',
'http://owncloud.org/ns'
);
return (int)(string)$responseXmlObject->xpath('//oc:fileid')[0];
);
$xmlBody = $propfindResponse->getBody()->getContents();
$responseXmlObject = new SimpleXMLElement($xmlBody);
$responseXmlObject->registerXPathNamespace(
'oc',
'http://owncloud.org/ns'
);
return (int)(string)$responseXmlObject->xpath('//oc:fileid')[0];
} catch (Exception $e) {
return null;
}
}

/**
* @param string $path
* @param string $method
Expand Down Expand Up @@ -1077,6 +1089,11 @@ public function sendRequestsToAppEndpoint(
$fullUrl = $this->getBaseUrl();
$fullUrl .= "index.php/apps/integration_openproject/" . $endpoint;

// Handle PyStringNode
if ($data instanceof PyStringNode) {
$data = (string)$data;
}

// don't set content-type for multipart requests
if (is_array($data) && $headers === null) {
$options['multipart'] = $data;
Expand Down Expand Up @@ -1144,8 +1161,10 @@ public function before(BeforeScenarioScope $scope):void {
$environment = $scope->getEnvironment();

// Get all the contexts you need in this context
$this->sharingContext = $environment->getContext('SharingContext');
$this->directUploadContext = $environment->getContext('DirectUploadContext');
if($environment instanceof InitializedContextEnvironment) {
$this->sharingContext = $environment->getContext('SharingContext');
$this->directUploadContext = $environment->getContext('DirectUploadContext');
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/acceptance/features/bootstrap/FilesVersionsContext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
Expand Down Expand Up @@ -110,6 +111,8 @@ public function before(BeforeScenarioScope $scope):void {
$environment = $scope->getEnvironment();

// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
if($environment instanceof InitializedContextEnvironment) {
$this->featureContext = $environment->getContext('FeatureContext');
}
}
}
5 changes: 4 additions & 1 deletion tests/acceptance/features/bootstrap/GroupfoldersContext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
Expand Down Expand Up @@ -203,7 +204,9 @@ public function before(BeforeScenarioScope $scope):void {
$environment = $scope->getEnvironment();

// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
if($environment instanceof InitializedContextEnvironment) {
$this->featureContext = $environment->getContext('FeatureContext');
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/acceptance/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;

class SharingContext implements Context {
Expand Down Expand Up @@ -161,6 +162,8 @@ public function before(BeforeScenarioScope $scope):void {
$environment = $scope->getEnvironment();

// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
if($environment instanceof InitializedContextEnvironment) {
$this->featureContext = $environment->getContext('FeatureContext');
}
}
}
2 changes: 1 addition & 1 deletion tests/lib/Controller/DirectUploadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function testDirectUploadFileNotUploaded(string $tmpName, int $error):voi
}

/**
* @return array<int, array<int, int|string>>
* @return array<int, array<int, \Exception|int|string>>
*/
public function newFileExceptionsDataProvider() {
return [
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Controller/FilesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ public function getFilesControllerMock(
MockObject $folderMock,
MockObject $mountCacheMock = null,
MockObject $davUtilsMock = null
): FilesController {
): FilesController|MockObject {
$storageMock = $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock();
$storageMock->method('getUserFolder')->willReturn($folderMock);

Expand Down
1 change: 1 addition & 0 deletions tests/lib/Controller/OpenProjectAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function setUpMocks(): void {
* @return void
*/
public function getUserValueMock($token = '123') {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getUserValue')
->withConsecutive(
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Reference/WorkPackageReferenceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getWorkReferenceProviderMock(
$refrenceMangager = null,
$openProjectAPIService = null,
$userId = null
): WorkPackageReferenceProvider {
): WorkPackageReferenceProvider|MockObject {
if ($configMock === null) {
$configMock = $this->createMock(IConfig::class);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ private function getServiceMock(
$db = null,
$iLogFactory = null,
$iURLGenerator = null
): OpenProjectAPIService {
): OpenProjectAPIService|MockObject {
$onlyMethods[] = 'getBaseUrl';
if ($rootMock === null) {
$rootMock = $this->createMock(IRootFolder::class);
Expand Down Expand Up @@ -3678,7 +3678,7 @@ public function auditLogDataProvider(): array {
* @param int $logLevel
* @param string $pathToAuditLog
* @param array<mixed> $logCondition
* @param string $isAdminAuditAppInstalled
* @param bool $isAdminAuditAppInstalled
* @param bool $expectedResult
*
* @return void
Expand Down

0 comments on commit dc97da6

Please sign in to comment.