Skip to content

Commit ebe9b98

Browse files
committed
Create base classes for unit and functional tests
1 parent f93886c commit ebe9b98

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
<php>
1818
<ini name="error_reporting" value="-1"/>
19+
<env name="MONGODB_URI" value="mongodb://localhost:27017"/>
20+
<env name="MONGODB_DATABASE" value="phplib_test"/>
1921
</php>
2022

2123
<testsuites>

tests/FunctionalTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace MongoDB\Tests;
4+
5+
use MongoDB\Driver\Manager;
6+
7+
abstract class FunctionalTestCase extends TestCase
8+
{
9+
protected $manager;
10+
11+
public function setUp()
12+
{
13+
$this->manager = new Manager($this->getUri());
14+
}
15+
}

tests/TestCase.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace MongoDB\Tests;
4+
5+
use ReflectionClass;
6+
7+
abstract class TestCase extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* Return the test collection name.
11+
*
12+
* @return string
13+
*/
14+
public function getCollectionName()
15+
{
16+
$class = new ReflectionClass($this);
17+
18+
return sprintf('%s.%s', $class->getShortName(), $this->getName(false));
19+
}
20+
21+
/**
22+
* Return the test database name.
23+
*
24+
* @return string
25+
*/
26+
public function getDatabaseName()
27+
{
28+
return getenv('MONGODB_DATABASE') ?: 'phplib_test';
29+
}
30+
31+
/**
32+
* Return the test namespace.
33+
*
34+
* @return string
35+
*/
36+
public function getNamespace()
37+
{
38+
return sprintf('%s.%s', $this->getDatabaseName(), $this->getCollectionName());
39+
}
40+
41+
/**
42+
* Return the connection URI.
43+
*
44+
* @return string
45+
*/
46+
public function getUri()
47+
{
48+
return getenv('MONGODB_URI') ?: 'mongodb://localhost:27017';
49+
}
50+
}

0 commit comments

Comments
 (0)