Navigation Menu

Skip to content

Commit

Permalink
minor #17911 [Ldap] Added environment-based Ldap server configuration…
Browse files Browse the repository at this point in the history
… for tests (csarrazi)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Ldap] Added environment-based Ldap server configuration for tests

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This PR makes Ldap server host and port configurable by using environment variables. This enables a developer to test the Ldap component locally, or on a vagrant virtual machine, depending on the use case.

If one wishes to run the tests against his own Ldap server, one simply needs to use the `LDAP_HOST` and `LDAP_PORT` environment variables when running the `phpunit` command.

Commits
-------

d0fbaea Added environment-based Ldap server configuration for tests
  • Loading branch information
fabpot committed Feb 26, 2016
2 parents db07500 + d0fbaea commit 0eaf329
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Expand Up @@ -13,6 +13,8 @@
<ini name="memory_limit" value="-1" />
<env name="DUMP_LIGHT_ARRAY" value="" />
<env name="DUMP_STRING_LENGTH" value="" />
<env name="LDAP_HOST" value="127.0.0.1" />
<env name="LDAP_PORT" value="3389" />
</php>

<testsuites>
Expand Down
Expand Up @@ -19,7 +19,7 @@
/**
* @requires extension ldap
*/
class AdapterTest extends \PHPUnit_Framework_TestCase
class AdapterTest extends LdapTestCase
{
public function testLdapEscape()
{
Expand All @@ -33,7 +33,7 @@ public function testLdapEscape()
*/
public function testLdapQuery()
{
$ldap = new Adapter(array('host' => 'localhost', 'port' => 3389));
$ldap = new Adapter($this->getLdapConfig());

$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array());
Expand Down
Expand Up @@ -19,14 +19,14 @@
/**
* @requires extension ldap
*/
class LdapManagerTest extends \PHPUnit_Framework_TestCase
class LdapManagerTest extends LdapTestCase
{
/** @var Adapter */
private $adapter;

protected function setUp()
{
$this->adapter = new Adapter(array('host' => 'localhost', 'port' => 3389));
$this->adapter = new Adapter($this->getLdapConfig());
$this->adapter->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
}

Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Ldap/Tests/LdapTestCase.php
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Component\Ldap\Tests;

class LdapTestCase extends \PHPUnit_Framework_TestCase
{
protected function getLdapConfig()
{
return array(
'host' => getenv('LDAP_HOST'),
'port' => getenv('LDAP_PORT'),
);
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Ldap/phpunit.xml.dist
Expand Up @@ -8,6 +8,8 @@
>
<php>
<ini name="error_reporting" value="-1" />
<env name="LDAP_HOST" value="127.0.0.1" />
<env name="LDAP_PORT" value="3389" />
</php>

<testsuites>
Expand Down

0 comments on commit 0eaf329

Please sign in to comment.