Skip to content

Commit ac1c77a

Browse files
authored
Merge pull request #222 from DigitalTimK/tests/coverage
Improve tests
2 parents 8c6da98 + a108e9f commit ac1c77a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+590
-229
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
composer.phar
22
/vendor/
3+
/var/
34
composer.lock
45
.DS_Store
56

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

16-
.phpunit.result.cache
17-
coverage/
17+
.phpunit.result.cache

.php-cs-fixer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
->in(__DIR__ . '/tests')
4949
;
5050

51+
// see rules: https://mlocati.github.io/php-cs-fixer-configurator/#version:3.8
52+
5153
$config = new Config();
5254
$config
5355
->setRiskyAllowed(true)
@@ -62,8 +64,13 @@
6264
'single_quote' => true,
6365
'mb_str_functions' => true,
6466
'array_syntax' => ['syntax' => 'short'],
65-
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal'],
67+
'binary_operator_spaces' => [
68+
'operators' => [
69+
'=>' => 'align_single_space_minimal',
70+
'=' => 'align_single_space_minimal',
71+
],
6672
],
73+
'php_unit_test_class_requires_covers' => false,
6774
])
6875
->setFinder($finder)
6976
;

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ For every implemented feature add unit tests and check all is green by running t
5757

5858
```bash
5959
# using an alias
60-
$ composer test
60+
$ composer code-test
6161

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

6868
```bash
6969
# using an alias
70-
$ composer test -- --filter BigBlueButtonTest::testApiVersion
70+
$ composer code-test -- --filter BigBlueButtonTest::testApiVersion
7171

7272
# or the same w/o alias
7373
./vendor/bin/phpunit --filter BigBlueButtonTest::testApiVersion
7474
```
75+
A code-coverage report will be created along with the tests. This report will be stored in:
76+
````
77+
./var/coverage/
78+
````
79+
In case of trouble with the creation of the code-coverage report (e.g. local environment does not fulfill requirements)
80+
the creation can be skipped with:
81+
```bash
82+
# using an alias
83+
$ composer code-test -- --no-coverage
84+
```
7585

7686
**Remark:**
7787

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"bbb",
88
"api"
99
],
10-
"homepage": "http://bigbluebutton.org/",
10+
"homepage": "https://bigbluebutton.org/",
1111
"license": "LGPL-3.0-or-later",
1212
"authors": [
1313
{
@@ -42,12 +42,12 @@
4242
"wapmorgan/php-deprecation-detector": "^2.0.33",
4343
"phpstan/phpstan": "^1.10",
4444
"tracy/tracy": "2.9",
45-
"vlucas/phpdotenv": "^5.6"
45+
"vlucas/phpdotenv": "^5.6",
46+
"phpunit/php-code-coverage": "9.2.30"
4647
},
4748
"scripts": {
4849
"code-check": "./vendor/bin/phpstan analyse",
49-
"test": "./vendor/bin/phpunit",
50-
"test-cov": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html coverage",
50+
"code-test": "./vendor/bin/phpunit",
5151
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky yes",
5252
"sniffer": "./vendor/bin/phpcs src/",
5353
"phploc": "./vendor/bin/phploc src/",

phpunit.xml.dist

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="./tests/bootstrap.php"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
convertDeprecationsToExceptions="true"
13+
processIsolation="false"
14+
stopOnFailure="false"
15+
verbose="true"
16+
>
317
<coverage processUncoveredFiles="true">
418
<include>
5-
<directory suffix=".php">./src/</directory>
19+
<directory suffix=".php">src</directory>
620
</include>
21+
<report>
22+
<html outputDirectory="./var/coverage/" />
23+
</report>
724
</coverage>
825
<php>
926
<env name="XDEBUG_MODE" value="coverage"/>
1027
</php>
1128
<testsuites>
1229
<testsuite name="BigBlueButton test suite">
13-
<directory>./tests/</directory>
30+
<directory>tests</directory>
1431
</testsuite>
1532
</testsuites>
1633
</phpunit>

src/BigBlueButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ private function sendRequest(string $url, string $payload = '', string $contentT
594594
}
595595

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

600600
// CLOSE AND UNSET

tests/BigBlueButtonTest.php

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
use BigBlueButton\Parameters\HooksDestroyParameters;
3131
use BigBlueButton\Parameters\IsMeetingRunningParameters;
3232
use BigBlueButton\Parameters\PublishRecordingsParameters;
33-
use BigBlueButton\Util\ParamsIterator;
34-
use Dotenv\Dotenv;
33+
use BigBlueButton\TestServices\EnvLoader;
34+
use BigBlueButton\TestServices\Fixtures;
35+
use BigBlueButton\TestServices\ParamsIterator;
3536

3637
/**
3738
* Class BigBlueButtonTest.
3839
*
3940
* @internal
40-
*
41-
* @coversNothing
4241
*/
4342
class BigBlueButtonTest extends TestCase
4443
{
@@ -51,7 +50,7 @@ public function setUp(): void
5150
{
5251
parent::setUp();
5352

54-
$this->loadEnvironmentVariables();
53+
EnvLoader::loadEnvironmentVariables();
5554

5655
$this->bbb = new BigBlueButton();
5756
}
@@ -95,8 +94,8 @@ public function testApiVersion(): void
9594
*/
9695
public function testCreateMeetingUrl(): void
9796
{
98-
$params = $this->generateCreateParams();
99-
$url = $this->bbb->getCreateMeetingUrl($this->getCreateMock($params));
97+
$params = Fixtures::generateCreateParams();
98+
$url = $this->bbb->getCreateMeetingUrl(Fixtures::getCreateMeetingParametersMock($params));
10099

101100
$paramsIterator = new ParamsIterator();
102101
$paramsIterator->iterate($params, $url);
@@ -107,8 +106,9 @@ public function testCreateMeetingUrl(): void
107106
*/
108107
public function testCreateMeeting(): void
109108
{
110-
$params = $this->generateCreateParams();
111-
$result = $this->bbb->createMeeting($this->getCreateMock($params));
109+
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
110+
111+
$result = $this->bbb->createMeeting($createMeetingParams);
112112

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

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

140140
$result = $this->bbb->createMeeting($params);
@@ -149,7 +149,7 @@ public function testCreateMeetingWithDocumentUrlAndFileName(): void
149149
*/
150150
public function testCreateMeetingWithDocumentEmbedded(): void
151151
{
152-
$params = $this->getCreateMock($this->generateCreateParams());
152+
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
153153

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

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

@@ -185,9 +185,9 @@ public function testCreateMeetingWithMultiDocument(): void
185185
*/
186186
public function testCreateJoinMeetingUrl(): void
187187
{
188-
$joinMeetingParams = $this->generateJoinMeetingParams();
188+
$joinMeetingParams = Fixtures::generateJoinMeetingParams();
189189

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

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

208210
// prepare to join the meeting
209-
$joinMeetingParams = $this->generateJoinMeetingParams();
210-
$joinMeetingMock = $this->getJoinMeetingMock($joinMeetingParams);
211-
$joinMeetingMock->setRedirect(false);
211+
$joinMeetingParams = Fixtures::generateJoinMeetingParams();
212+
$joinMeetingMock = Fixtures::getJoinMeetingMock($joinMeetingParams);
212213

213214
// adapt to join the above created meeting
215+
$joinMeetingMock->setRedirect(false);
214216
$joinMeetingMock->setMeetingId($createMeetingResponse->getMeetingId());
215217
$joinMeetingMock->setCreationTime($createMeetingResponse->getCreationTime());
216218

@@ -239,8 +241,8 @@ public function testJoinMeeting(): void
239241
*/
240242
public function testCreateEndMeetingUrl(): void
241243
{
242-
$params = $this->generateEndMeetingParams();
243-
$url = $this->bbb->getEndMeetingURL($this->getEndMeetingMock($params));
244+
$params = Fixtures::generateEndMeetingParams();
245+
$url = $this->bbb->getEndMeetingURL(Fixtures::getEndMeetingMock($params));
244246
$paramsIterator = new ParamsIterator();
245247
$paramsIterator->iterate($params, $url);
246248
}
@@ -257,13 +259,13 @@ public function testEndMeeting(): void
257259

258260
public function testEndNonExistingMeeting(): void
259261
{
260-
$params = $this->generateEndMeetingParams();
261-
$result = $this->bbb->endMeeting($this->getEndMeetingMock($params));
262+
$params = Fixtures::generateEndMeetingParams();
263+
$result = $this->bbb->endMeeting(Fixtures::getEndMeetingMock($params));
262264
$this->assertEquals('FAILED', $result->getReturnCode());
263265
$this->assertTrue($result->failed());
264266
}
265267

266-
// Is Meeting Running
268+
// Is Meeting Running / Existing
267269

268270
public function testIsMeetingRunning(): void
269271
{
@@ -389,16 +391,16 @@ public function testDeleteRecordings(): void
389391
*/
390392
public function testUpdateRecordingsUrl(): void
391393
{
392-
$params = $this->generateUpdateRecordingsParams();
393-
$url = $this->bbb->getUpdateRecordingsUrl($this->getUpdateRecordingsParamsMock($params));
394+
$params = Fixtures::generateUpdateRecordingsParams();
395+
$url = $this->bbb->getUpdateRecordingsUrl(Fixtures::getUpdateRecordingsParamsMock($params));
394396
$paramsIterator = new ParamsIterator();
395397
$paramsIterator->iterate($params, $url);
396398
}
397399

398400
public function testUpdateRecordings(): void
399401
{
400-
$params = $this->generateUpdateRecordingsParams();
401-
$result = $this->bbb->updateRecordings($this->getUpdateRecordingsParamsMock($params));
402+
$params = Fixtures::generateUpdateRecordingsParams();
403+
$result = $this->bbb->updateRecordings(Fixtures::getUpdateRecordingsParamsMock($params));
402404
$this->assertEquals('FAILED', $result->getReturnCode());
403405
$this->assertTrue($result->failed());
404406
}
@@ -439,26 +441,4 @@ public function testHooksDestroy(): void
439441
$hooksCreateResponse = $this->bbb->hooksDestroy($hooksDestroyParameters);
440442
$this->assertFalse($hooksCreateResponse->success(), $hooksCreateResponse->getMessage());
441443
}
442-
443-
/**
444-
* @see https://github.com/vlucas/phpdotenv
445-
*/
446-
private function loadEnvironmentVariables(): void
447-
{
448-
$envPath = __DIR__ . '/..';
449-
$envFileMain = '.env';
450-
$envFileLocal = '.env.local';
451-
452-
if (file_exists("{$envPath}/{$envFileLocal}")) {
453-
$envFile = $envFileLocal;
454-
} elseif (file_exists("{$envPath}/{$envFileMain}")) {
455-
$envFile = $envFileMain;
456-
} else {
457-
throw new \RuntimeException("Environment file ('{$envFileMain}' nor '{$envFileLocal}') not found!");
458-
}
459-
460-
$dotenv = Dotenv::createUnsafeImmutable($envPath, $envFile);
461-
$dotenv->load();
462-
$dotenv->required(['BBB_SECRET', 'BBB_SERVER_BASE_URL']);
463-
}
464444
}

0 commit comments

Comments
 (0)