Skip to content

Commit

Permalink
Merge branch 'feature/ensure-recipient' of https://github.com/OskarSt…
Browse files Browse the repository at this point in the history
  • Loading branch information
slunak committed Sep 2, 2024
2 parents cd2fd44 + 98f8a19 commit 810bf65
Show file tree
Hide file tree
Showing 28 changed files with 170 additions and 289 deletions.
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ also fix common issues with [Rector](https://github.com/rector/rector)
make refactoring
```

#### Code Documentation

Document your code with [phpDocumentor](https://github.com/phpDocumentor/phpDocumentor) version 3.

#### Static Analysis

Analyze your code with [PHPStan](https://github.com/phpstan/phpstan).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"ergebnis/php-cs-fixer-config": "^6.34",
"friendsofphp/php-cs-fixer": "^3.61",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "*",
"phpunit/phpunit": "^11.0",
"rector/rector": "^1.2"
},
"autoload": {
Expand Down
4 changes: 4 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPaths([
Expand All @@ -20,4 +21,7 @@
__DIR__.'/tests',
])
->withPhpSets(php82: true)
->withSets([
PHPUnitSetList::PHPUNIT_110,
])
->withTypeCoverageLevel(0);
19 changes: 5 additions & 14 deletions src/Api/Glances/GlanceDataFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,27 @@ class GlanceDataFields
/**
* (100 characters) - a description of the data being shown, such as "Widgets Sold".
*/
private ?string $title;
private ?string $title = null;

/**
* (100 characters) - the main line of data, used on most screens.
*/
private ?string $text;
private ?string $text = null;

/**
* (100 characters) - a second line of data.
*/
private ?string $subtext;
private ?string $subtext = null;

/**
* (integer, may be negative) - shown on smaller screens; useful for simple counts.
*/
private ?int $count;
private ?int $count = null;

/**
* (integer 0 through 100, inclusive) - shown on some screens as a progress bar/circle.
*/
private ?int $percent;

public function __construct()
{
$this->title = null;
$this->text = null;
$this->subtext = null;
$this->count = null;
$this->percent = null;
}
private ?int $percent = null;

public function getTitle(): ?string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Subscription/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
readonly class Subscription
{
public function __construct(
private readonly Application $application,
private readonly string $subscriptionCode,
private Application $application,
private string $subscriptionCode,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/MessageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function buildApiUrl(): string
/**
* Builds array for CURLOPT_POSTFIELDS curl argument.
*
* @return array<string, null|\CURLFile|int|string>
* @return array<string, (null|\CURLFile|int|string)>
*/
public function buildCurlPostFields(Notification $notification): array
{
Expand Down
38 changes: 11 additions & 27 deletions tests/Api/Glances/GlanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Api\Glances;

use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Serhiy\Pushover\Api\Glances\Glance;
use Serhiy\Pushover\Api\Glances\GlanceDataFields;
Expand All @@ -39,33 +41,25 @@ public function testCanBeConstructed(): Glance
return $glance;
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetGlanceDataFields(Glance $glance): void
{
$this->assertInstanceOf(GlanceDataFields::class, $glance->getGlanceDataFields());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetApplication(Glance $glance): void
{
$this->assertInstanceOf(Application::class, $glance->getApplication());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetRecipient(Glance $glance): void
{
$this->assertInstanceOf(Recipient::class, $glance->getRecipient());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetApplication(Glance $glance): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand All @@ -74,9 +68,7 @@ public function testSetApplication(Glance $glance): void
$this->assertInstanceOf(Application::class, $glance->getApplication());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetGlanceDataFields(Glance $glance): void
{
$glanceDataFields = new GlanceDataFields();
Expand All @@ -85,9 +77,7 @@ public function testSetGlanceDataFields(Glance $glance): void
$this->assertInstanceOf(GlanceDataFields::class, $glance->getGlanceDataFields());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetRecipient(Glance $glance): void
{
$recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key
Expand All @@ -96,9 +86,7 @@ public function testSetRecipient(Glance $glance): void
$this->assertInstanceOf(Recipient::class, $recipient);
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testHasAtLeastOneField(Glance $glance): void
{
$this->assertFalse($glance->hasAtLeastOneField());
Expand All @@ -108,17 +96,13 @@ public function testHasAtLeastOneField(Glance $glance): void
$this->assertTrue($glance->hasAtLeastOneField());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testHasRecipient(Glance $glance): void
{
$this->assertTrue($glance->hasRecipient());
}

/**
* @group Integration
*/
#[Group('Integration')]
public function testPush(): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand Down
22 changes: 7 additions & 15 deletions tests/Api/Groups/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Api\Groups;

use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group as PHPUnitGroup;
use PHPUnit\Framework\TestCase;
use Serhiy\Pushover\Api\Groups\Group;
use Serhiy\Pushover\Application;
Expand All @@ -35,26 +37,20 @@ public function testCanBeConstructed(): Group
return $group;
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetApplication(Group $group): void
{
$this->assertInstanceOf(Application::class, $group->getApplication());
$this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $group->getApplication()->getToken());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetKey(Group $group): void
{
$this->assertSame('eeee5555EEEE5555ffff6666FFFF66', $group->getKey());
}

/**
* @group Integration
*/
#[PHPUnitGroup('Integration')]
public function testRetrieveGroupInformation(): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand All @@ -65,9 +61,7 @@ public function testRetrieveGroupInformation(): void
$this->assertInstanceOf(RetrieveGroupResponse::class, $response);
}

/**
* @group Integration
*/
#[PHPUnitGroup('Integration')]
public function testCreate(): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand All @@ -78,9 +72,7 @@ public function testCreate(): void
$this->assertInstanceOf(CreateGroupResponse::class, $response);
}

/**
* @group Integration
*/
#[PHPUnitGroup('Integration')]
public function testList(): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand Down
46 changes: 13 additions & 33 deletions tests/Api/Licensing/LicenseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Api\Licensing;

use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Serhiy\Pushover\Api\Licensing\License;
use Serhiy\Pushover\Application;
Expand All @@ -32,17 +34,13 @@ public function testCanBeConstructed(): License
return $license;
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetApplication(License $license): void
{
$this->assertInstanceOf(Application::class, $license->getApplication());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetApplication(License $license): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand All @@ -51,17 +49,13 @@ public function testSetApplication(License $license): void
$this->assertInstanceOf(Application::class, $license->getApplication());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetRecipient(License $license): void
{
$this->assertNull($license->getRecipient());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetRecipient(License $license): void
{
$recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key
Expand All @@ -73,17 +67,13 @@ public function testSetRecipient(License $license): void
$this->assertNull($license->getRecipient());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetEmail(License $license): void
{
$this->assertNull($license->getEmail());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetEmail(License $license): void
{
$email = 'dummy@email.com';
Expand All @@ -95,17 +85,13 @@ public function testSetEmail(License $license): void
$this->assertNull($license->getEmail());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetOs(License $license): void
{
$this->assertNull($license->getOs());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testSetOs(License $license): void
{
$license->setOs(License::OS_ANDROID);
Expand All @@ -118,9 +104,7 @@ public function testSetOs(License $license): void
$license->setOs('Wrong_OS');
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testCanBeAssigned(License $license): void
{
$recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key
Expand All @@ -141,9 +125,7 @@ public function testCanBeAssigned(License $license): void
$this->assertFalse($license->canBeAssigned());
}

/**
* @depends testCanBeConstructed
*/
#[Depends('testCanBeConstructed')]
public function testGetAvailableOsTypes(License $license): void
{
$licenseTypes = [
Expand All @@ -156,9 +138,7 @@ public function testGetAvailableOsTypes(License $license): void
$this->assertEquals($licenseTypes, $license->getAvailableOsTypes());
}

/**
* @group Integration
*/
#[Group('Integration')]
public function testCheckCredits(): void
{
$application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token
Expand Down
Loading

0 comments on commit 810bf65

Please sign in to comment.