Commit 24d34dcc authored by Jeremy Mikola's avatar Jeremy Mikola

Create base classes for unit and functional tests

parent c035baed
......@@ -16,6 +16,8 @@
<php>
<ini name="error_reporting" value="-1"/>
<env name="MONGODB_URI" value="mongodb://localhost:27017"/>
<env name="MONGODB_DATABASE" value="phplib_test"/>
</php>
<testsuites>
......
<?php
namespace MongoDB\Tests;
use MongoDB\Driver\Manager;
abstract class FunctionalTestCase extends TestCase
{
protected $manager;
public function setUp()
{
$this->manager = new Manager($this->getUri());
}
}
<?php
namespace MongoDB\Tests;
use ReflectionClass;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
/**
* Return the test collection name.
*
* @return string
*/
public function getCollectionName()
{
$class = new ReflectionClass($this);
return sprintf('%s.%s', $class->getShortName(), $this->getName(false));
}
/**
* Return the test database name.
*
* @return string
*/
public function getDatabaseName()
{
return getenv('MONGODB_DATABASE') ?: 'phplib_test';
}
/**
* Return the test namespace.
*
* @return string
*/
public function getNamespace()
{
return sprintf('%s.%s', $this->getDatabaseName(), $this->getCollectionName());
}
/**
* Return the connection URI.
*
* @return string
*/
public function getUri()
{
return getenv('MONGODB_URI') ?: 'mongodb://localhost:27017';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment