Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 35453e8

Browse files
committed
[test] Use environment variables instead constants
1 parent 0b8302b commit 35453e8

File tree

8 files changed

+67
-119
lines changed

8 files changed

+67
-119
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
.travis.yml export-ignore
77
.php_cs export-ignore
88
phpunit.xml.dist export-ignore
9-
phpunit.xml.travis export-ignore

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ sudo: false
22

33
language: php
44

5+
env:
6+
global:
7+
- TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED=true
8+
59
matrix:
610
fast_finish: true
711
include:
@@ -27,8 +31,8 @@ install:
2731
- travis_retry composer install --no-interaction --ignore-platform-reqs
2832

2933
script:
30-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis --coverage-clover clover.xml ; fi
31-
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis ; fi
34+
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
35+
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
3236
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
3337

3438
after_script:

phpunit.xml.dist

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
functionality works as expected. Such tests include those for
2929
Zend\Soap and Zend\Session, which require that headers not be sent
3030
in order to work. -->
31-
<const name="TESTS_ZEND_OB_ENABLED" value="false" />
31+
<env name="TESTS_ZEND_OB_ENABLED" value="false" />
3232

3333
<!-- Note: the following is a FULL list of ALL POSSIBLE constants
3434
currently in use in ZF2 for ALL COMPONENTS; you should choose the
3535
constants appropriate to the component you are migrating. -->
3636

37-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED" value="false" />
38-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE" value=":memory:" />
39-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_ENABLED" value="false" />
40-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_HOSTNAME" value="127.0.0.1" />
41-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PORT" value="50000" />
42-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_USERNAME" value="" />
43-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PASSWORD" value="" />
44-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_DATABASE" value="*LOCAL" />
45-
<const name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_CREDENTIAL_TABLE" value="YOURLIB.TESTING_USERS" />
46-
<const name="TESTS_ZEND_AUTH_ADAPTER_LDAP_ONLINE_ENABLED" value="false" />
37+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED" value="false" />
38+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE" value=":memory:" />
39+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_ENABLED" value="false" />
40+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_HOSTNAME" value="127.0.0.1" />
41+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PORT" value="50000" />
42+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_USERNAME" value="" />
43+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PASSWORD" value="" />
44+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_DATABASE" value="*LOCAL" />
45+
<env name="TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_CREDENTIAL_TABLE" value="YOURLIB.TESTING_USERS" />
46+
<env name="TESTS_ZEND_AUTH_ADAPTER_LDAP_ONLINE_ENABLED" value="false" />
4747

4848
</php>
4949
</phpunit>

phpunit.xml.travis

Lines changed: 0 additions & 51 deletions
This file was deleted.

test/Adapter/DbTable/CallbackCheckAdapterTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class CallbackCheckAdapterTest extends \PHPUnit_Framework_TestCase
3838
*/
3939
public function setUp()
4040
{
41-
if (!defined('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED') ||
42-
constant('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED') === false
43-
) {
41+
if (!getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED')) {
4442
$this->markTestSkipped('Tests are not enabled in phpunit.xml');
4543
return;
4644
} elseif (!extension_loaded('pdo')) {
@@ -349,7 +347,7 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS
349347
protected function _setupDbAdapter($optionalParams = array())
350348
{
351349
$params = array('driver' => 'pdo_sqlite',
352-
'dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE);
350+
'dbname' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE'));
353351

354352
if (!empty($optionalParams)) {
355353
$params['options'] = $optionalParams;

test/Adapter/DbTable/CredentialTreatmentAdapterDb2Test.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,39 @@ class CredentialTreatmentAdapterDb2Test extends \PHPUnit_Framework_TestCase
3535
/**
3636
* Database adapter configuration
3737
*/
38-
protected $dbAdapterParams = array(
39-
'driver' => 'IbmDb2',
40-
'dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_DATABASE,
41-
'username' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_USERNAME,
42-
'password' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PASSWORD,
43-
'platform_options' => array('quote_identifiers' => false),
44-
'driver_options' => array(),
45-
);
38+
protected $dbAdapterParams;
4639

4740
/**
4841
* DB2 table to use for testing
4942
*
5043
* @var string in the format 'LIBRARY_NAME.TABLE_NAME' or
5144
*/
52-
protected $tableName = TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_CREDENTIAL_TABLE;
45+
protected $tableName;
5346

5447
/**
5548
* Set up test configuration
5649
*/
5750
public function setUp()
5851
{
59-
if (!defined('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_ENABLED')
60-
|| constant('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_ENABLED') === false
61-
) {
52+
if (!getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_ENABLED')) {
6253
$this->markTestSkipped('Tests are not enabled in phpunit.xml');
6354
}
6455

6556
if (! extension_loaded('ibm_db2')) {
6657
$this->markTestSkipped('ibm_db2 extension is not loaded');
6758
}
6859

60+
$this->dbAdapterParams = array(
61+
'driver' => 'IbmDb2',
62+
'dbname' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_DATABASE'),
63+
'username' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_USERNAME'),
64+
'password' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_PASSWORD'),
65+
'platform_options' => array('quote_identifiers' => false),
66+
'driver_options' => array(),
67+
);
6968
$this->dbAdapterParams['driver_options']['i5_commit'] = constant('DB2_I5_TXN_NO_COMMIT');
7069
$this->dbAdapterParams['driver_options']['i5_naming'] = constant('DB2_I5_NAMING_OFF');
70+
$this->tableName = getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_DB2_CREDENTIAL_TABLE');
7171

7272
$this->setupDbAdapter();
7373
$this->setupAuthAdapter();

test/Adapter/DbTable/CredentialTreatmentAdapterTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class CredentialTreatmentAdapterTest extends \PHPUnit_Framework_TestCase
3838
*/
3939
public function setUp()
4040
{
41-
if (!defined('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED') ||
42-
constant('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED') === false
43-
) {
41+
if (!getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_ENABLED')) {
4442
$this->markTestSkipped('Tests are not enabled in phpunit.xml');
4543
return;
4644
} elseif (!extension_loaded('pdo')) {
@@ -336,7 +334,7 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS
336334
protected function _setupDbAdapter($optionalParams = array())
337335
{
338336
$params = array('driver' => 'pdo_sqlite',
339-
'dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE);
337+
'dbname' => getenv('TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE'));
340338

341339
if (!empty($optionalParams)) {
342340
$params['options'] = $optionalParams;

test/Adapter/Ldap/OnlineTest.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,46 @@ class OnlineTest extends \PHPUnit_Framework_TestCase
3232

3333
public function setUp()
3434
{
35-
if (!constant('TESTS_ZEND_AUTH_ADAPTER_LDAP_ONLINE_ENABLED')) {
35+
if (!getenv('TESTS_ZEND_AUTH_ADAPTER_LDAP_ONLINE_ENABLED')) {
3636
$this->markTestSkipped('LDAP online tests are not enabled');
3737
}
3838
$this->options = array(
39-
'host' => TESTS_ZEND_LDAP_HOST,
40-
'username' => TESTS_ZEND_LDAP_USERNAME,
41-
'password' => TESTS_ZEND_LDAP_PASSWORD,
42-
'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
39+
'host' => getenv('TESTS_ZEND_LDAP_HOST'),
40+
'username' => getenv('TESTS_ZEND_LDAP_USERNAME'),
41+
'password' => getenv('TESTS_ZEND_LDAP_PASSWORD'),
42+
'baseDn' => getenv('TESTS_ZEND_LDAP_BASE_DN'),
4343
);
44-
if (defined('TESTS_ZEND_LDAP_PORT')) {
45-
$this->options['port'] = TESTS_ZEND_LDAP_PORT;
44+
if (getenv('TESTS_ZEND_LDAP_PORT')) {
45+
$this->options['port'] = getenv('TESTS_ZEND_LDAP_PORT');
4646
}
47-
if (defined('TESTS_ZEND_LDAP_USE_START_TLS')) {
48-
$this->options['useStartTls'] = TESTS_ZEND_LDAP_USE_START_TLS;
47+
if (getenv('TESTS_ZEND_LDAP_USE_START_TLS')) {
48+
$this->options['useStartTls'] = getenv('TESTS_ZEND_LDAP_USE_START_TLS');
4949
}
50-
if (defined('TESTS_ZEND_LDAP_USE_SSL')) {
51-
$this->options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL;
50+
if (getenv('TESTS_ZEND_LDAP_USE_SSL')) {
51+
$this->options['useSsl'] = getenv('TESTS_ZEND_LDAP_USE_SSL');
5252
}
53-
if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN')) {
54-
$this->options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN;
53+
if (getenv('TESTS_ZEND_LDAP_BIND_REQUIRES_DN')) {
54+
$this->options['bindRequiresDn'] = getenv('TESTS_ZEND_LDAP_BIND_REQUIRES_DN');
5555
}
56-
if (defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT')) {
57-
$this->options['accountFilterFormat'] = TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT;
56+
if (getenv('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT')) {
57+
$this->options['accountFilterFormat'] = getenv('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT');
5858
}
59-
if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
60-
$this->options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
59+
if (getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
60+
$this->options['accountDomainName'] = getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME');
6161
}
62-
if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
63-
$this->options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT;
62+
if (getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
63+
$this->options['accountDomainNameShort'] = getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT');
6464
}
6565

66-
if (defined('TESTS_ZEND_LDAP_ALT_USERNAME')) {
67-
$this->names[Ldap\Ldap::ACCTNAME_FORM_USERNAME] = TESTS_ZEND_LDAP_ALT_USERNAME;
68-
if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
66+
if (getenv('TESTS_ZEND_LDAP_ALT_USERNAME')) {
67+
$this->names[Ldap\Ldap::ACCTNAME_FORM_USERNAME] = getenv('TESTS_ZEND_LDAP_ALT_USERNAME');
68+
if (getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
6969
$this->names[Ldap\Ldap::ACCTNAME_FORM_PRINCIPAL] =
70-
TESTS_ZEND_LDAP_ALT_USERNAME . '@' . TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
70+
getenv('TESTS_ZEND_LDAP_ALT_USERNAME') . '@' . getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME');
7171
}
72-
if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
72+
if (getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
7373
$this->names[Ldap\Ldap::ACCTNAME_FORM_BACKSLASH] =
74-
TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT . '\\' . TESTS_ZEND_LDAP_ALT_USERNAME;
74+
getenv('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT') . '\\' . getenv('TESTS_ZEND_LDAP_ALT_USERNAME');
7575
}
7676
}
7777
}
@@ -80,8 +80,8 @@ public function testSimpleAuth()
8080
{
8181
$adapter = new Adapter\Ldap(
8282
array($this->options),
83-
TESTS_ZEND_LDAP_ALT_USERNAME,
84-
TESTS_ZEND_LDAP_ALT_PASSWORD
83+
getenv('TESTS_ZEND_LDAP_ALT_USERNAME'),
84+
getenv('TESTS_ZEND_LDAP_ALT_PASSWORD')
8585
);
8686

8787
$result = $adapter->authenticate();
@@ -103,7 +103,7 @@ public function testCanonAuth()
103103
$options = $this->options;
104104
$options['accountCanonicalForm'] = $form;
105105
$adapter = new Adapter\Ldap(array($options));
106-
$adapter->setPassword(TESTS_ZEND_LDAP_ALT_PASSWORD);
106+
$adapter->setPassword(getenv('TESTS_ZEND_LDAP_ALT_PASSWORD'));
107107
foreach ($this->names as $username) {
108108
$adapter->setUsername($username);
109109
$result = $adapter->authenticate();
@@ -119,7 +119,7 @@ public function testInvalidPassAuth()
119119
{
120120
$adapter = new Adapter\Ldap(
121121
array($this->options),
122-
TESTS_ZEND_LDAP_ALT_USERNAME,
122+
getenv('TESTS_ZEND_LDAP_ALT_USERNAME'),
123123
'invalid'
124124
);
125125

@@ -166,24 +166,24 @@ public function testAccountObjectRetrieval()
166166
{
167167
$adapter = new Adapter\Ldap(
168168
array($this->options),
169-
TESTS_ZEND_LDAP_ALT_USERNAME,
170-
TESTS_ZEND_LDAP_ALT_PASSWORD
169+
getenv('TESTS_ZEND_LDAP_ALT_USERNAME'),
170+
getenv('TESTS_ZEND_LDAP_ALT_PASSWORD')
171171
);
172172

173173
$result = $adapter->authenticate();
174174
$account = $adapter->getAccountObject();
175175

176176
//$this->assertTrue($result->isValid());
177177
$this->assertInternalType('object', $account);
178-
$this->assertEquals(TESTS_ZEND_LDAP_ALT_DN, $account->dn);
178+
$this->assertEquals(getenv('TESTS_ZEND_LDAP_ALT_DN'), $account->dn);
179179
}
180180

181181
public function testAccountObjectRetrievalWithOmittedAttributes()
182182
{
183183
$adapter = new Adapter\Ldap(
184184
array($this->options),
185-
TESTS_ZEND_LDAP_ALT_USERNAME,
186-
TESTS_ZEND_LDAP_ALT_PASSWORD
185+
getenv('TESTS_ZEND_LDAP_ALT_USERNAME'),
186+
getenv('TESTS_ZEND_LDAP_ALT_PASSWORD')
187187
);
188188

189189
$result = $adapter->authenticate();

0 commit comments

Comments
 (0)