Skip to content

Commit

Permalink
Merge pull request #222 from DigitalTimK/tests/coverage
Browse files Browse the repository at this point in the history
Improve tests
  • Loading branch information
GhaziTriki authored Apr 20, 2024
2 parents 8c6da98 + a108e9f commit ac1c77a
Show file tree
Hide file tree
Showing 42 changed files with 590 additions and 229 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
composer.phar
/vendor/
/var/
composer.lock
.DS_Store

Expand All @@ -13,5 +14,4 @@ composer.lock
# PHP CS Fixer cache file
.php-cs-fixer.cache

.phpunit.result.cache
coverage/
.phpunit.result.cache
9 changes: 8 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
->in(__DIR__ . '/tests')
;

// see rules: https://mlocati.github.io/php-cs-fixer-configurator/#version:3.8

$config = new Config();
$config
->setRiskyAllowed(true)
Expand All @@ -62,8 +64,13 @@
'single_quote' => true,
'mb_str_functions' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal'],
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align_single_space_minimal',
'=' => 'align_single_space_minimal',
],
],
'php_unit_test_class_requires_covers' => false,
])
->setFinder($finder)
;
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ For every implemented feature add unit tests and check all is green by running t

```bash
# using an alias
$ composer test
$ composer code-test

# or the same w/o alias
./vendor/bin/phpunit
Expand All @@ -67,11 +67,21 @@ To run a single test

```bash
# using an alias
$ composer test -- --filter BigBlueButtonTest::testApiVersion
$ composer code-test -- --filter BigBlueButtonTest::testApiVersion

# or the same w/o alias
./vendor/bin/phpunit --filter BigBlueButtonTest::testApiVersion
```
A code-coverage report will be created along with the tests. This report will be stored in:
````
./var/coverage/
````
In case of trouble with the creation of the code-coverage report (e.g. local environment does not fulfill requirements)
the creation can be skipped with:
```bash
# using an alias
$ composer code-test -- --no-coverage
```

**Remark:**

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"bbb",
"api"
],
"homepage": "http://bigbluebutton.org/",
"homepage": "https://bigbluebutton.org/",
"license": "LGPL-3.0-or-later",
"authors": [
{
Expand Down Expand Up @@ -42,12 +42,12 @@
"wapmorgan/php-deprecation-detector": "^2.0.33",
"phpstan/phpstan": "^1.10",
"tracy/tracy": "2.9",
"vlucas/phpdotenv": "^5.6"
"vlucas/phpdotenv": "^5.6",
"phpunit/php-code-coverage": "9.2.30"
},
"scripts": {
"code-check": "./vendor/bin/phpstan analyse",
"test": "./vendor/bin/phpunit",
"test-cov": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html coverage",
"code-test": "./vendor/bin/phpunit",
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky yes",
"sniffer": "./vendor/bin/phpcs src/",
"phploc": "./vendor/bin/phploc src/",
Expand Down
23 changes: 20 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">src</directory>
</include>
<report>
<html outputDirectory="./var/coverage/" />
</report>
</coverage>
<php>
<env name="XDEBUG_MODE" value="coverage"/>
</php>
<testsuites>
<testsuite name="BigBlueButton test suite">
<directory>./tests/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/BigBlueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private function sendRequest(string $url, string $payload = '', string $contentT
}

if ($httpCode < 200 || $httpCode >= 300) {
throw new BadResponseException('Bad response, HTTP code: ' . $httpCode);
throw new BadResponseException('Bad response, HTTP code: ' . $httpCode . ', url: ' . $url);
}

// CLOSE AND UNSET
Expand Down
78 changes: 29 additions & 49 deletions tests/BigBlueButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
use BigBlueButton\Parameters\HooksDestroyParameters;
use BigBlueButton\Parameters\IsMeetingRunningParameters;
use BigBlueButton\Parameters\PublishRecordingsParameters;
use BigBlueButton\Util\ParamsIterator;
use Dotenv\Dotenv;
use BigBlueButton\TestServices\EnvLoader;
use BigBlueButton\TestServices\Fixtures;
use BigBlueButton\TestServices\ParamsIterator;

/**
* Class BigBlueButtonTest.
*
* @internal
*
* @coversNothing
*/
class BigBlueButtonTest extends TestCase
{
Expand All @@ -51,7 +50,7 @@ public function setUp(): void
{
parent::setUp();

$this->loadEnvironmentVariables();
EnvLoader::loadEnvironmentVariables();

$this->bbb = new BigBlueButton();
}
Expand Down Expand Up @@ -95,8 +94,8 @@ public function testApiVersion(): void
*/
public function testCreateMeetingUrl(): void
{
$params = $this->generateCreateParams();
$url = $this->bbb->getCreateMeetingUrl($this->getCreateMock($params));
$params = Fixtures::generateCreateParams();
$url = $this->bbb->getCreateMeetingUrl(Fixtures::getCreateMeetingParametersMock($params));

$paramsIterator = new ParamsIterator();
$paramsIterator->iterate($params, $url);
Expand All @@ -107,8 +106,9 @@ public function testCreateMeetingUrl(): void
*/
public function testCreateMeeting(): void
{
$params = $this->generateCreateParams();
$result = $this->bbb->createMeeting($this->getCreateMock($params));
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());

$result = $this->bbb->createMeeting($createMeetingParams);

$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
Expand All @@ -119,7 +119,7 @@ public function testCreateMeeting(): void
*/
public function testCreateMeetingWithDocumentUrl(): void
{
$params = $this->getCreateMock($this->generateCreateParams());
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$params->addPresentation('https://picsum.photos/3840/2160/?random');

$result = $this->bbb->createMeeting($params);
Expand All @@ -134,7 +134,7 @@ public function testCreateMeetingWithDocumentUrl(): void
*/
public function testCreateMeetingWithDocumentUrlAndFileName(): void
{
$params = $this->getCreateMock($this->generateCreateParams());
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'placeholder.png');

$result = $this->bbb->createMeeting($params);
Expand All @@ -149,7 +149,7 @@ public function testCreateMeetingWithDocumentUrlAndFileName(): void
*/
public function testCreateMeetingWithDocumentEmbedded(): void
{
$params = $this->getCreateMock($this->generateCreateParams());
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());

$params->addPresentation('bbb_logo.png', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png'));

Expand All @@ -165,7 +165,7 @@ public function testCreateMeetingWithDocumentEmbedded(): void
*/
public function testCreateMeetingWithMultiDocument(): void
{
$params = $this->getCreateMock($this->generateCreateParams());
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'presentation.png');
$params->addPresentation('logo.png', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png'));

Expand All @@ -185,9 +185,9 @@ public function testCreateMeetingWithMultiDocument(): void
*/
public function testCreateJoinMeetingUrl(): void
{
$joinMeetingParams = $this->generateJoinMeetingParams();
$joinMeetingParams = Fixtures::generateJoinMeetingParams();

$joinMeetingMock = $this->getJoinMeetingMock($joinMeetingParams);
$joinMeetingMock = Fixtures::getJoinMeetingMock($joinMeetingParams);

$url = $this->bbb->getJoinMeetingURL($joinMeetingMock);
$paramsIterator = new ParamsIterator();
Expand All @@ -204,13 +204,15 @@ public function testJoinMeeting(): void
// create a meeting that can be joined
$createMeetingParameters = new CreateMeetingParameters($this->faker->uuid(), $this->faker->word());
$createMeetingResponse = $this->bbb->createMeeting($createMeetingParameters);
$this->assertEquals('SUCCESS', $createMeetingResponse->getReturnCode());
$this->assertTrue($createMeetingResponse->success());

// prepare to join the meeting
$joinMeetingParams = $this->generateJoinMeetingParams();
$joinMeetingMock = $this->getJoinMeetingMock($joinMeetingParams);
$joinMeetingMock->setRedirect(false);
$joinMeetingParams = Fixtures::generateJoinMeetingParams();
$joinMeetingMock = Fixtures::getJoinMeetingMock($joinMeetingParams);

// adapt to join the above created meeting
$joinMeetingMock->setRedirect(false);
$joinMeetingMock->setMeetingId($createMeetingResponse->getMeetingId());
$joinMeetingMock->setCreationTime($createMeetingResponse->getCreationTime());

Expand Down Expand Up @@ -239,8 +241,8 @@ public function testJoinMeeting(): void
*/
public function testCreateEndMeetingUrl(): void
{
$params = $this->generateEndMeetingParams();
$url = $this->bbb->getEndMeetingURL($this->getEndMeetingMock($params));
$params = Fixtures::generateEndMeetingParams();
$url = $this->bbb->getEndMeetingURL(Fixtures::getEndMeetingMock($params));
$paramsIterator = new ParamsIterator();
$paramsIterator->iterate($params, $url);
}
Expand All @@ -257,13 +259,13 @@ public function testEndMeeting(): void

public function testEndNonExistingMeeting(): void
{
$params = $this->generateEndMeetingParams();
$result = $this->bbb->endMeeting($this->getEndMeetingMock($params));
$params = Fixtures::generateEndMeetingParams();
$result = $this->bbb->endMeeting(Fixtures::getEndMeetingMock($params));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}

// Is Meeting Running
// Is Meeting Running / Existing

public function testIsMeetingRunning(): void
{
Expand Down Expand Up @@ -389,16 +391,16 @@ public function testDeleteRecordings(): void
*/
public function testUpdateRecordingsUrl(): void
{
$params = $this->generateUpdateRecordingsParams();
$url = $this->bbb->getUpdateRecordingsUrl($this->getUpdateRecordingsParamsMock($params));
$params = Fixtures::generateUpdateRecordingsParams();
$url = $this->bbb->getUpdateRecordingsUrl(Fixtures::getUpdateRecordingsParamsMock($params));
$paramsIterator = new ParamsIterator();
$paramsIterator->iterate($params, $url);
}

public function testUpdateRecordings(): void
{
$params = $this->generateUpdateRecordingsParams();
$result = $this->bbb->updateRecordings($this->getUpdateRecordingsParamsMock($params));
$params = Fixtures::generateUpdateRecordingsParams();
$result = $this->bbb->updateRecordings(Fixtures::getUpdateRecordingsParamsMock($params));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}
Expand Down Expand Up @@ -439,26 +441,4 @@ public function testHooksDestroy(): void
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
$this->assertFalse($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
}

/**
* @see https://github.com/vlucas/phpdotenv
*/
private function loadEnvironmentVariables(): void
{
$envPath = __DIR__ . '/..';
$envFileMain = '.env';
$envFileLocal = '.env.local';

if (file_exists("{$envPath}/{$envFileLocal}")) {
$envFile = $envFileLocal;
} elseif (file_exists("{$envPath}/{$envFileMain}")) {
$envFile = $envFileMain;
} else {
throw new \RuntimeException("Environment file ('{$envFileMain}' nor '{$envFileLocal}') not found!");
}

$dotenv = Dotenv::createUnsafeImmutable($envPath, $envFile);
$dotenv->load();
$dotenv->required(['BBB_SECRET', 'BBB_SERVER_BASE_URL']);
}
}
Loading

0 comments on commit ac1c77a

Please sign in to comment.