Skip to content

Samples-as-a-tests#119

Merged
seba-aln merged 7 commits intomasterfrom
tests/add-samples-as-a-test
Jun 26, 2025
Merged

Samples-as-a-tests#119
seba-aln merged 7 commits intomasterfrom
tests/add-samples-as-a-test

Conversation

@seba-aln
Copy link

This adds a lot of samples. Improves testing and coverage

@pubnub-ops-terraform
Copy link

pubnub-ops-terraform commented Jun 24, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)


// snippet.uuid_metadata_operations
try {
$result = $user->setUUIDMetadata()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I other place you used:
$admin->setUuidMetadata()
Is this desired ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP's function names are case insensitive. this though should be written with uppercase uuid

}

// Helper function to safely execute operations (deprecated - using direct try/catch now)
function safeTest($callable, $description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method needed? Where it is used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. probably leftover from copypaste


class AppContextTest extends TestCase
{
public function testExamples(): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this name be more descriptive?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a test for examples. how much descriptive a single method name in pretty much self explanatory class should be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe testAppContextCodeSnippets ?

$subscribeKey = getenv('SUBSCRIBE_KEY') ?: 'demo';

$config = new PNConfiguration();
$config->setSubscribeKey(getenv('SUBSCRIBE_KEY', 'demo'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to pass $publishKey variable here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

->profileUrl($user['profileUrl'])
->custom($user['custom'])
->sync();
assert($setUserMetadataResult->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about: "By default, PHP compiles out assert() calls unless you enable zend.assertions=1 and assert.exception=1. In a typical CLI script they won’t even run, so you’ll never know if one failed."
?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've found in docs and on php.watch symbols history the default for zend.assertions is 1 so they are by default enabled.

return random_bytes(static::IV_LENGTH);
}

public function getCipherKey($cipherKey = null): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be type-hinted?

@@ -41,17 +41,17 @@ public function encrypt(string $text, ?string $cipherKey = null): CryptoPayload
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In getSecret method is this required to check:
!is_null($cipherKey)
if method signature enforce cipherKey being not null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably redundant, but not the scope of this task.

return new static(
[
LegacyCryptor::CRYPTOR_ID => new LegacyCryptor($cipherKey, $useRandomIV),
AesCbcCryptor::CRYPTOR_ID => new AesCbcCryptor($cipherKey),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of:
aesCbcCryptor::CRYPTOR_ID
shouldn't be:
AesCbcCryptor::CRYPTOR_ID
?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

@@ -193,7 +193,7 @@ protected function customParams()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok for buildData method to return null when signature declare return type as string ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type in comment is just a hint for compatibility with parent IIRC

@@ -139,4 +171,361 @@ public function testThrowErrorOnNoFileFound(): void
$this->expectException(PubNubServerException::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testThrowErrorOnMalformedResponse
there is
$pubnub->setClient($client);
and
$this->pubnub->setClient($client);

Are those two needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->pubnub->setClient($client); this one was not needed

@seba-aln seba-aln merged commit 2cd05ff into master Jun 26, 2025
12 checks passed
@seba-aln seba-aln deleted the tests/add-samples-as-a-test branch June 26, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants