1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace MongoDB\Tests;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use ReflectionClass;
use stdClass;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
public function provideInvalidDocumentValues()
{
return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
}
/**
* Return the test collection name.
*
* @return string
*/
protected function getCollectionName()
{
$class = new ReflectionClass($this);
return sprintf('%s.%s', $class->getShortName(), hash('crc32b', $this->getName()));
}
/**
* Return the test database name.
*
* @return string
*/
protected function getDatabaseName()
{
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 getInvalidReadConcernValues()
{
return [123, 3.14, 'foo', true, [], new stdClass, new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)];
}
/**
* Return a list of invalid ReadPreference values.
*
* @return array
*/
protected function getInvalidReadPreferenceValues()
{
return [123, 3.14, 'foo', true, [], new stdClass, new ReadConcern, new WriteConcern(1)];
}
/**
* 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()
{
return [123, 3.14, 'foo', true, [], new stdClass, new ReadConcern, new ReadPreference(ReadPreference::RP_PRIMARY)];
}
/**
* Return the test namespace.
*
* @return string
*/
protected function getNamespace()
{
return sprintf('%s.%s', $this->getDatabaseName(), $this->getCollectionName());
}
/**
* Return the connection URI.
*
* @return string
*/
protected function getUri()
{
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);
}
}