Commit ae97a8d9 authored by Jeremy Mikola's avatar Jeremy Mikola

Move invalid data providers to base TestCase class

parent a4992db2
...@@ -341,6 +341,11 @@ class BulkWriteTest extends TestCase ...@@ -341,6 +341,11 @@ class BulkWriteTest extends TestCase
); );
} }
public function provideInvalidBooleanValues()
{
return $this->wrapValuesForDataProvider($this->getInvalidBooleanValues());
}
public function provideInvalidConstructorOptions() public function provideInvalidConstructorOptions()
{ {
$options = []; $options = [];
......
...@@ -3,50 +3,10 @@ ...@@ -3,50 +3,10 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Tests\TestCase as BaseTestCase; use MongoDB\Tests\TestCase as BaseTestCase;
use stdClass;
/** /**
* Base class for Operation unit tests. * Base class for Operation unit tests.
*/ */
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
public function provideInvalidDocumentValues()
{
return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
}
public function provideInvalidBooleanValues()
{
return $this->wrapValuesForDataProvider($this->getInvalidBooleanValues());
}
protected function getInvalidArrayValues()
{
return [123, 3.14, 'foo', true, new stdClass];
}
protected function getInvalidBooleanValues()
{
return [123, 3.14, 'foo', [], new stdClass];
}
protected function getInvalidDocumentValues()
{
return [123, 3.14, 'foo', true];
}
protected function getInvalidIntegerValues()
{
return [3.14, 'foo', true, [], new stdClass];
}
protected function getInvalidStringValues()
{
return [123, 3.14, true, [], new stdClass];
}
protected function wrapValuesForDataProvider(array $values)
{
return array_map(function($value) { return [$value]; }, $values);
}
} }
...@@ -7,6 +7,11 @@ use stdClass; ...@@ -7,6 +7,11 @@ use stdClass;
abstract class TestCase extends \PHPUnit_Framework_TestCase abstract class TestCase extends \PHPUnit_Framework_TestCase
{ {
public function provideInvalidDocumentValues()
{
return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
}
/** /**
* Return the test collection name. * Return the test collection name.
* *
...@@ -29,11 +34,71 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase ...@@ -29,11 +34,71 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
return getenv('MONGODB_DATABASE') ?: 'phplib_test'; return getenv('MONGODB_DATABASE') ?: 'phplib_test';
} }
/**
* Return a list of invalid array values.
*
* @return array
*/
protected function getInvalidArrayValues()
{
return [123, 3.14, 'foo', true, new stdClass];
}
/**
* Return a list of invalid boolean values.
*
* @return array
*/
protected function getInvalidBooleanValues()
{
return [123, 3.14, 'foo', [], new stdClass];
}
/**
* Return a list of invalid document values.
*
* @return array
*/
protected function getInvalidDocumentValues()
{
return [123, 3.14, 'foo', true];
}
/**
* Return a list of invalid integer values.
*
* @return array
*/
protected function getInvalidIntegerValues()
{
return [3.14, 'foo', true, [], new stdClass];
}
/**
* Return a list of invalid ReadPreference values.
*
* @return array
*/
protected function getInvalidReadPreferenceValues() protected function getInvalidReadPreferenceValues()
{ {
return [123, 3.14, 'foo', true, [], new stdClass]; return [123, 3.14, 'foo', true, [], new stdClass];
} }
/**
* Return a list of invalid string values.
*
* @return array
*/
protected function getInvalidStringValues()
{
return [123, 3.14, true, [], new stdClass];
}
/**
* Return a list of invalid WriteConcern values.
*
* @return array
*/
protected function getInvalidWriteConcernValues() protected function getInvalidWriteConcernValues()
{ {
return [123, 3.14, 'foo', true, [], new stdClass]; return [123, 3.14, 'foo', true, [], new stdClass];
...@@ -58,4 +123,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase ...@@ -58,4 +123,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
{ {
return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017'; return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017';
} }
/**
* Wrap a list of values for use as a single-argument data provider.
*
* @param array $values List of values
* @return array
*/
protected function wrapValuesForDataProvider(array $values)
{
return array_map(function($value) { return [$value]; }, $values);
}
} }
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