Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
Refactor tests and classes to use PHP attributes
Browse files Browse the repository at this point in the history
This commit updates all test cases to use native PHP8 attribute syntax instead of comments for PHPUnit annotations. The method visibility has also been adjusted to be compliant with the PHPUnit v9. Additionally, multiple unnecessary comment blocks have been removed from the source codes for better readability. All changes have been made across various classes and test cases.

Signed-off-by: mesilov <[email protected]>
  • Loading branch information
mesilov committed Jul 6, 2024
1 parent d04c08a commit 2afc7d6
Show file tree
Hide file tree
Showing 27 changed files with 199 additions and 296 deletions.
4 changes: 3 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ parameters:
- src/
- tests/Integration/Services/Telephony
- tests/Integration/Services/User
- tests/Unit/
bootstrapFiles:
- tests/bootstrap.php
parallel:
jobSize: 20
maximumNumberOfProcesses: 8
minimumNumberOfJobsPerProcess: 2
editorUrlTitle: '%%relFile%%:%%line%%'
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
treatPhpDocTypesAsCertain: false
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src/Core/',
__DIR__ . '/src/Application/',
__DIR__ . '/src/Services/Telephony',
__DIR__ . '/tests/Integration/Services/Telephony',
__DIR__ . '/src/Services/User',
__DIR__ . '/tests/Integration/Services/User',
__DIR__ . '/tests/Unit/',
])
->withCache(cacheDirectory: __DIR__ . '.cache/rector')
->withSets(
Expand Down
37 changes: 7 additions & 30 deletions src/Application/ApplicationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
class ApplicationStatus
{
private const STATUS_SHORT_FREE = 'F';

private const STATUS_SHORT_DEMO = 'D';

private const STATUS_SHORT_TRIAL = 'T';

private const STATUS_SHORT_PAID = 'P';

private const STATUS_SHORT_LOCAL = 'L';

private const STATUS_SHORT_SUBSCRIPTION = 'S';
private string $statusCode;

private readonly string $statusCode;

/**
* @param string $statusShortCode
*
* @throws InvalidArgumentException
*/
public function __construct(string $statusShortCode)
Expand All @@ -42,17 +46,11 @@ public static function free(): self
return new self(self::STATUS_SHORT_FREE);
}

/**
* @return bool
*/
public function isFree(): bool
{
return 'free' === $this->statusCode;
}

/**
* @return bool
*/
public function isDemo(): bool
{
return 'demo' === $this->statusCode;
Expand All @@ -63,9 +61,6 @@ public static function demo(): self
return new self(self::STATUS_SHORT_DEMO);
}

/**
* @return bool
*/
public function isTrial(): bool
{
return 'trial' === $this->statusCode;
Expand All @@ -76,9 +71,6 @@ public static function trial(): self
return new self(self::STATUS_SHORT_TRIAL);
}

/**
* @return bool
*/
public function isPaid(): bool
{
return 'paid' === $this->statusCode;
Expand All @@ -89,9 +81,6 @@ public static function paid(): self
return new self(self::STATUS_SHORT_PAID);
}

/**
* @return bool
*/
public function isLocal(): bool
{
return 'local' === $this->statusCode;
Expand All @@ -102,9 +91,6 @@ public static function local(): self
return new self(self::STATUS_SHORT_LOCAL);
}

/**
* @return bool
*/
public function isSubscription(): bool
{
return 'subscription' === $this->statusCode;
Expand All @@ -115,18 +101,12 @@ public static function subscription(): self
return new self(self::STATUS_SHORT_SUBSCRIPTION);
}

/**
* @return string
*/
public function getStatusCode(): string
{
return $this->statusCode;
}

/**
* @param Request $request
*
* @return self
* @throws InvalidArgumentException
*/
public static function initFromRequest(Request $request): self
Expand All @@ -135,9 +115,6 @@ public static function initFromRequest(Request $request): self
}

/**
* @param string $shortStatusCode
*
* @return self
* @throws InvalidArgumentException
*/
public static function initFromString(string $shortStatusCode): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public function getStatus(): Bitrix24AccountStatus;
*/
public function getAuthToken(): AuthToken;

/**
* @param RenewedAuthToken $renewedAuthToken
*
* @return void
*/

public function renewAuthToken(RenewedAuthToken $renewedAuthToken): void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ interface Bitrix24AccountRepositoryInterface
/**
* Get Bitrix24 account by id
*/
public function getById(Uuid $id): Bitrix24Accounts\Entity\Bitrix24AccountInterface;
public function getById(Uuid $uuid): Bitrix24Accounts\Entity\Bitrix24AccountInterface;

/**
* @param Bitrix24Accounts\Entity\Bitrix24AccountInterface $entity
* @param bool $isFlush save entity to storage, commit transaction in oltp database
*/
public function save(Bitrix24Accounts\Entity\Bitrix24AccountInterface $entity, bool $isFlush = false): void;
public function save(Bitrix24Accounts\Entity\Bitrix24AccountInterface $bitrix24Account, bool $isFlush = false): void;
}
11 changes: 1 addition & 10 deletions src/Application/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@

abstract class AbstractRequest
{
protected Request $request;

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*/
public function __construct(Request $request)
public function __construct(protected Request $request)
{
$this->request = $request;
}

/**
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest(): Request
{
return $this->request;
Expand Down
6 changes: 3 additions & 3 deletions src/Application/Requests/Events/AbstractEventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
abstract class AbstractEventRequest extends AbstractRequest implements EventInterface
{
protected string $eventCode;

protected int $timestamp;

protected array $eventPayload;

protected int $eventId;

/**
* @param Request $request
*/
public function __construct(Request $request)
{
parent::__construct($request);
Expand Down
50 changes: 21 additions & 29 deletions src/Application/Requests/Placement/PlacementRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@

class PlacementRequest extends AbstractRequest
{
private AuthToken $accessToken;
private string $memberId;
private ApplicationStatus $applicationStatus;
private string $code;
private readonly AuthToken $accessToken;

private readonly string $memberId;

private readonly ApplicationStatus $applicationStatus;

private readonly string $code;

/**
* @var array<string, mixed>
*/
private array $placementOptions;
private string $domainUrl;
private string $languageCode;
private readonly array $placementOptions;

private readonly string $domainUrl;

private readonly string $languageCode;

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
* @throws \JsonException
Expand All @@ -47,10 +52,12 @@ public function __construct(Request $request)
if ($options === null) {
throw new InvalidArgumentException('invalid data in PLACEMENT_OPTIONS json payload');
}

// fix "undefined" string in options when placement loaded in telephony settings
if (!is_array($options)) {
$options = [];
}

$this->placementOptions = $options;
}

Expand All @@ -59,50 +66,35 @@ public function getApplicationStatus(): ApplicationStatus
return $this->applicationStatus;
}

/**
* @return string
*/
public function getMemberId(): string
{
return $this->memberId;
}

/**
* @return \Bitrix24\SDK\Core\Credentials\AuthToken
*/
public function getAccessToken(): AuthToken
{
return $this->accessToken;
}

/**
* @return string
*/
public function getCode(): string
{
return $this->code;
}

/**
* @return array|mixed
*/
public function getPlacementOptions()

public function getPlacementOptions(): array
{
return $this->placementOptions;
}

/**
* @return mixed|string
*/
public function getDomainUrl()

public function getDomainUrl(): string
{
return $this->domainUrl;
}

/**
* @return mixed|string
*/
public function getLanguageCode()

public function getLanguageCode(): string
{
return $this->languageCode;
}
Expand Down
14 changes: 2 additions & 12 deletions tests/Unit/Application/ApplicationStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
use Generator;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Application\ApplicationStatus::class)]
class ApplicationStatusTest extends TestCase
{
/**
* @param string $shortCode
* @param string $longCode
*
* @return void
* @dataProvider statusDataProvider
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
*/
#[\PHPUnit\Framework\Attributes\DataProvider('statusDataProvider')]
public function testGetStatusCode(string $shortCode, string $longCode): void
{
$this->assertEquals(
Expand All @@ -27,19 +25,14 @@ public function testGetStatusCode(string $shortCode, string $longCode): void
);
}

/**
* @return void
*/
public function testInvalidStatusCode(): void
{
$this->expectException(InvalidArgumentException::class);
new ApplicationStatus('foo');
}

/**
* @return void
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
* @covers \Bitrix24\SDK\Application\ApplicationStatus::initFromString
*/
public function testInitFromString(): void
{
Expand Down Expand Up @@ -76,9 +69,6 @@ public function testSubscription(): void
$this->assertTrue(ApplicationStatus::subscription()->isSubscription());
}

/**
* @return \Generator
*/
public static function statusDataProvider(): Generator
{
yield 'free' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
class Bitrix24AccountInterfaceReferenceImplementationTest extends Bitrix24AccountInterfaceTest
{
protected function createBitrix24AccountImplementation(
Uuid $id,
Uuid $uuid,
int $bitrix24UserId,
bool $isBitrix24UserAdmin,
string $memberId,
string $domainUrl,
Bitrix24AccountStatus $accountStatus,
Bitrix24AccountStatus $bitrix24AccountStatus,
AuthToken $authToken,
CarbonImmutable $createdAt,
CarbonImmutable $updatedAt,
Expand All @@ -33,12 +33,12 @@ protected function createBitrix24AccountImplementation(
): Bitrix24AccountInterface
{
return new Bitrix24AccountReferenceEntityImplementation(
$id,
$uuid,
$bitrix24UserId,
$isBitrix24UserAdmin,
$memberId,
$domainUrl,
$accountStatus,
$bitrix24AccountStatus,
$authToken,
$createdAt,
$updatedAt,
Expand Down
Loading

0 comments on commit 2afc7d6

Please sign in to comment.