Skip to content

Commit

Permalink
chore: fixed many issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-s committed Jun 26, 2024
1 parent 41c24a2 commit 6412165
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 101 deletions.
50 changes: 0 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -145,71 +145,21 @@ parameters:
count: 1
path: test/functional/Resource/AccountTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\AccountTest\\:\\:testAccount\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/AccountTest.php

-
message: "#^Call to an undefined method Seafile\\\\Client\\\\Type\\\\Library\\:\\:decrypt\\(\\)\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testCreate\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testHistory\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testList\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testRename\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Property Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:\\$libraryResource \\(Seafile\\\\Client\\\\Resource\\\\Library\\|null\\) does not accept Seafile\\\\Client\\\\Type\\\\Library\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Strict comparison using \\=\\=\\= between string and true will always evaluate to false\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Variable \\$cfg in isset\\(\\) is never defined\\.$#"
count: 1
path: test/functional/Resource/FileTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\GroupTest\\:\\:testGetAll\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/GroupTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\ShareLinksTest\\:\\:testShareLinks\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/ShareLinksTest.php

-
message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\StarredFileTest\\:\\:testStarFile\\(\\) has no return type specified\\.$#"
count: 1
path: test/functional/Resource/StarredFileTest.php

-
message: "#^Call to an undefined method PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\|Seafile\\\\Client\\\\Http\\\\Client\\:\\:expects\\(\\)\\.$#"
count: 4
Expand Down
2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Config\RectorConfig;
Expand Down Expand Up @@ -42,7 +41,6 @@

$rectorConfig->rules([
CountArrayToEmptyArrayComparisonRector::class,
DateFuncCallToCarbonRector::class,
LongArrayToShortArrayRector::class,
RenameVariableToMatchMethodCallReturnTypeRector::class,
SymplifyQuoteEscapeRector::class,
Expand Down
29 changes: 5 additions & 24 deletions src/Type/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,11 @@
*/
class Library extends Type
{
/**
* @var string
*/
public $permission = '';

/**
* @var string
*/
public $encrypted = '';

/**
* @var string
*/
public $mtimeRelative = '';

/**
* @var DateTime
*/
public $mtime;

/**
* @var string
*/
public $owner = '';
public string $permission = '';
public string $encrypted = '';
public string $mtimeRelative = '';
public DateTime $mtime;
public string $owner = '';

/**
* @var string
Expand Down
17 changes: 5 additions & 12 deletions test/functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@
*/
class FunctionalTestCase extends TestCase
{
/** @var Client|null */
protected $client;

/** @var Logger|null */
protected $logger;

/** @var LibraryType|null */
protected $testLib;

/** @var Generator|null|Internet|Lorem|Person */
protected $faker;
protected ?Client $client;
protected ?Logger $logger;
protected ?LibraryType $testLib;
protected Internet|Lorem|null|Generator|Person $faker;

/**
* Skip functional tests when they do not have been set up correctly. Please refer to README.md on how to set them up.
Expand Down Expand Up @@ -132,7 +125,7 @@ protected function getTestLibraryType(): LibraryType
$library = new Library($this->client);
$this->testLib = $library->getById($libId);

if ($this->testLib->encrypted === true && array_key_exists('TEST_LIB_ENCRYPTED_PASSWORD', $_ENV)) {
if ($this->testLib->encrypted && array_key_exists('TEST_LIB_ENCRYPTED_PASSWORD', $_ENV)) {
self::assertTrue($library->decrypt(
$libId,
[
Expand Down
10 changes: 4 additions & 6 deletions test/functional/Resource/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Seafile\Client\Tests\Functional\Resource;

use Carbon\Carbon;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Seafile\Client\Resource\Directory;
use Seafile\Client\Resource\File;
use Seafile\Client\Resource\Library;
use Seafile\Client\Tests\Functional\FunctionalTestCase;
use Seafile\Client\Type\DirectoryItem;

Expand Down Expand Up @@ -78,7 +76,7 @@ public function testHistory(): void
$newFilename = tempnam($GLOBALS['BUILD_TMP'], 'Seafile-PHP-SDK_Test_File_History_Upload_');
rename($newFilename, $newFilename . '.txt');
$newFilename .= '.txt';
file_put_contents($newFilename, 'Hello World: ' . Carbon::now()->format('Y-m-d H:i:s'));
file_put_contents($newFilename, 'Hello World: ' . (new \DateTime)->format('Y-m-d H:i:s'));

$this->logger->debug("#################### Uploading file " . $newFilename);

Expand Down Expand Up @@ -162,7 +160,7 @@ public function testRename(): void
$libId = $_ENV['TEST_LIB_ENCRYPTED_ID'];
$library = $this->getTestLibraryType();

if ($library->encrypted === true && isset($cfg->testLibPassword)) {
if ($library->encrypted && isset($cfg->testLibPassword)) {
$success = $this->library->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_ENCRYPTED_PASSWORD']]]);
self::assertTrue($success);
}
Expand All @@ -176,7 +174,7 @@ public function testRename(): void
$success = $this->file->create($library, $dirItem);
self::assertTrue($success);

$newFilename = 'test_' . Carbon::now()->format('U') . '.txt';
$newFilename = 'test_' . (new \DateTime)->format('U') . '.txt';
$dirItem = $this->file->getFileDetail($library, $path . $fileName);

$this->logger->debug("#################### File to be renamed: " . $path . $dirItem->name);
Expand All @@ -185,7 +183,7 @@ public function testRename(): void
self::assertTrue($success);
$this->logger->debug("#################### File renamed from " . $path . $fileName . ' to ' . $newFilename);

$newFilename = 'even_newer_file_name_test_' . Carbon::now()->format('U') . '.txt';
$newFilename = 'even_newer_file_name_test_' . (new \DateTime)->format('U') . '.txt';
$success = $this->file->rename($library, $dirItem, $newFilename);

self::assertTrue($success);
Expand Down
4 changes: 2 additions & 2 deletions test/functional/Resource/ShareLinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Seafile\Client\Tests\Functional\Resource;

use Carbon\Carbon;
use Exception;
use Seafile\Client\Resource\File;
use Seafile\Client\Resource\Library;
Expand Down Expand Up @@ -43,6 +42,7 @@ protected function setUp(): void
* and successfully so that's postponed for now.
*
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function testShareLinks(): void
{
Expand All @@ -68,7 +68,7 @@ public function testShareLinks(): void
$newFilename = $GLOBALS['BUILD_TMP'] . '/Seafile-PHP-SDK_Test_Upload.txt';

if (!file_exists($newFilename)) {
file_put_contents($newFilename, 'Hello World: ' . Carbon::now()->format('Y-m-d H:i:s'));
file_put_contents($newFilename, 'Hello World: ' . (new \DateTime)->format('Y-m-d H:i:s'));
}

$this->logger->debug("#################### Uploading file " . $newFilename);
Expand Down
3 changes: 1 addition & 2 deletions test/unit/Resource/StarredFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function testStar(): void
)
// Return what was passed to offsetGet as a new instance
->will(self::returnCallback(
function ($method, $uri, array $params) use ($starResponse, $library, $directoryItem): Response|\Response {

function ($method, $uri, array $params) use ($starResponse, $library, $directoryItem): Response {
$hasParams = array_key_exists('headers', $params)
&& array_key_exists('multipart', $params)
&& array_key_exists('name', $params['multipart'][0])
Expand Down
5 changes: 2 additions & 3 deletions test/unit/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ class UnitTestCase extends TestCase
*
* @param object $object Instantiated object that we will run method on.
* @param string $methodName Method name to call
* @param array $parameters Array of parameters to pass into method.
* @param array<int, int|\Seafile\Client\Type\Library>|array<int, string> $parameters Params to pass to method.
*
* @return mixed Method return.
* @throws ReflectionException
*/
public function invokeMethod(&$object, string $methodName, array $parameters = [])
public function invokeMethod(object &$object, string $methodName, array $parameters = []): mixed
{
$reflectionClass = new ReflectionClass($object::class);
$reflectionMethod = $reflectionClass->getMethod($methodName);
$reflectionMethod->setAccessible(true);

return $reflectionMethod->invokeArgs($object, $parameters);
}
Expand Down

0 comments on commit 6412165

Please sign in to comment.