Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit ba966e5

Browse files
committed
:octocat: test cleanup
1 parent c7c261e commit ba966e5

File tree

9 files changed

+61
-16
lines changed

9 files changed

+61
-16
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
"ext-curl": "*",
3131
"ext-json":"*",
3232
"ext-simplexml":"*",
33-
"chillerlan/php-oauth-core": "dev-main#1522c62b715fe1300d3774c00be155565d83ace8",
33+
"chillerlan/php-oauth-core": "dev-main#9f6de524f16f332cdb4d8b6d16e079085145091b",
3434
"psr/http-client":"^1.0",
3535
"psr/http-message": "^1.0"
3636
},
3737
"require-dev": {
3838
"chillerlan/php-dotenv": "^2.1",
3939
"chillerlan/php-prototype-dom": "^3.0.1",
40+
"guzzlehttp/guzzle": "^7.3",
41+
"guzzlehttp/psr7": "2.0.0-beta1",
4042
"phpunit/phpunit": "^9.5",
4143
"phan/phan": "^4.0"
4244
},

phpunit.xml.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@
2424
<junit outputFile=".build/logs/junit.xml"/>
2525
</logging>
2626
<php>
27+
<!-- whether the test runs on CI or not - set to false to allow live API tests to run -->
2728
<const name="TEST_IS_CI" value="true"/>
29+
<!-- the config directory, where .env, cacert.pem and test oauth tokens reside, relative from project root -->
30+
<const name="TEST_CFGDIR" value="./config"/>
31+
<!-- the filename of your .env file -->
32+
<const name="TEST_ENVFILE" value=".env_example"/>
33+
<!-- the http client factory for live api tests -->
2834
<const name="TEST_CLIENT_FACTORY" value="chillerlan\OAuthTest\ChillerlanHttpClientFactory"/>
35+
<!-- PSR-17 factories to use in tests -->
2936
<const name="REQUEST_FACTORY" value="chillerlan\HTTP\Psr17\RequestFactory"/>
3037
<const name="RESPONSE_FACTORY" value="chillerlan\HTTP\Psr17\ResponseFactory"/>
3138
<const name="STREAM_FACTORY" value="chillerlan\HTTP\Psr17\StreamFactory"/>

tests/APITestTrait.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Trait APITestTrait
4+
*
5+
* @created 12.04.2021
6+
* @author smiley <smiley@chillerlan.net>
7+
* @copyright 2021 smiley
8+
* @license MIT
9+
*/
10+
11+
namespace chillerlan\OAuthTest\Providers;
12+
13+
use chillerlan\DotEnv\DotEnv;
14+
use chillerlan\OAuth\OAuthOptions;
15+
use chillerlan\Settings\SettingsContainerInterface;
16+
use Exception;
17+
use function constant, defined, realpath;
18+
19+
trait APITestTrait{
20+
21+
protected DotEnv $dotEnv;
22+
protected string $ENV;
23+
24+
protected function setUp():void{
25+
26+
foreach(['TEST_CFGDIR', 'TEST_ENVFILE'] as $constant){
27+
if(!defined($constant)){
28+
throw new Exception($constant.' not set -> see phpunit.xml');
29+
}
30+
}
31+
32+
// get the .env config
33+
$this->CFG = realpath(__DIR__.'/../'.constant('TEST_CFGDIR'));
34+
$this->dotEnv = (new DotEnv($this->CFG, constant('TEST_ENVFILE')))->load();
35+
$this->testuser = (string)$this->dotEnv->get($this->ENV.'_TESTUSER');
36+
37+
parent::setUp();
38+
}
39+
40+
protected function initOptions():SettingsContainerInterface{
41+
return new OAuthOptions([
42+
'key' => $this->dotEnv->get($this->ENV.'_KEY'),
43+
'secret' => $this->dotEnv->get($this->ENV.'_SECRET'),
44+
'tokenAutoRefresh' => true,
45+
]);
46+
}
47+
48+
}

tests/OAuth1APITest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@
1616
* @property \chillerlan\OAuth\Core\OAuth1Interface $provider
1717
*/
1818
abstract class OAuth1APITest extends OAuth1APITestAbstract{
19-
20-
protected string $CFG = __DIR__.'/../config';
21-
19+
use APITestTrait;
2220
}

tests/OAuth1ProviderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@
1515
*/
1616
abstract class OAuth1ProviderTest extends OAuth1ProviderTestAbstract{
1717

18-
protected string $CFG = __DIR__.'/../config';
19-
2018
}

tests/OAuth2APITest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@
1616
* @property \chillerlan\OAuth\Core\OAuth2Interface $provider
1717
*/
1818
abstract class OAuth2APITest extends OAuth2APITestAbstract{
19-
20-
protected string $CFG = __DIR__.'/../config';
21-
19+
use APITestTrait;
2220
}

tests/OAuth2ProviderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@
1515
*/
1616
abstract class OAuth2ProviderTest extends OAuth2ProviderTestAbstract{
1717

18-
protected string $CFG = __DIR__.'/../config';
19-
2018
}

tests/OAuthAPITest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@
1616
* @property \chillerlan\OAuth\Core\OAuthInterface $provider
1717
*/
1818
abstract class OAuthAPITest extends OAuthAPITestAbstract{
19-
20-
protected string $CFG = __DIR__.'/../config';
21-
19+
use APITestTrait;
2220
}

tests/OAuthProviderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@
1515
*/
1616
abstract class OAuthProviderTest extends OAuthProviderTestAbstract{
1717

18-
protected string $CFG = __DIR__.'/../config';
19-
2018
}

0 commit comments

Comments
 (0)