|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Novactive Collection. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Luke Visinoni <[email protected], [email protected]> |
|
6
|
|
|
* @author Sébastien Morel <[email protected], [email protected]> |
|
7
|
|
|
* @copyright 2017 Novactive |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Novactive\Tests; |
|
12
|
|
|
|
|
13
|
|
|
use ArrayIterator; |
|
14
|
|
|
use Faker\Factory; |
|
15
|
|
|
use PHPUnit_Framework_TestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class UnitTestCase. |
|
19
|
|
|
* |
|
20
|
|
|
* This allows us to set up shared fixtures that can be used between test cases... |
|
21
|
|
|
*/ |
|
22
|
|
|
class UnitTestCase extends PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $fixtures = []; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$faker = Factory::create(); |
|
32
|
|
|
$faker->seed(4231986); |
|
33
|
|
|
|
|
34
|
|
|
$this->fixtures['array'] = ['first', 'second', 'third']; |
|
35
|
|
|
$this->fixtures['assoc'] = ['1st' => 'first', '2nd' => 'second', '3rd' => 'third']; |
|
36
|
|
|
$this->fixtures['digits'] = []; |
|
37
|
|
|
$this->fixtures['users'] = []; |
|
38
|
|
|
|
|
39
|
|
|
for ($i = 0; $i < 10; $i++) { |
|
40
|
|
|
$username = $faker->unique()->userName; |
|
41
|
|
|
$this->fixtures['digits'][] = $faker->numberBetween(1, 10000); |
|
42
|
|
|
$this->fixtures['users'][$username] = [ |
|
43
|
|
|
'username' => $username, |
|
44
|
|
|
'email' => $faker->unique()->safeEmail, |
|
45
|
|
|
'remote_addr' => $faker->ipv4, |
|
46
|
|
|
'homepage' => $faker->domainName, |
|
47
|
|
|
'firstname' => $faker->firstName, |
|
48
|
|
|
'lastname' => $faker->lastName, |
|
49
|
|
|
'address' => $faker->streetAddress, |
|
50
|
|
|
'city' => $faker->city, |
|
51
|
|
|
'state' => $faker->state, |
|
52
|
|
|
'zipcode' => $faker->postcode, |
|
53
|
|
|
'phone' => $faker->phoneNumber, |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->fixtures['names'] = array_column($this->fixtures['users'], 'firstname'); |
|
58
|
|
|
$this->fixtures['emails'] = array_column($this->fixtures['users'], 'email'); |
|
59
|
|
|
$this->fixtures['phones'] = array_column($this->fixtures['users'], 'phone'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function tearDown() |
|
63
|
|
|
{ |
|
64
|
|
|
// nothing to do here... |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Returns a recorder that expectes to be "touched" $count times. |
|
69
|
|
|
* |
|
70
|
|
|
* This allows us to test that a certain thing happened $count number of times. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $count |
|
73
|
|
|
* @param string $method |
|
74
|
|
|
* |
|
75
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function getMethodCallRecorderForCount($count, $method = 'touch') |
|
78
|
|
|
{ |
|
79
|
|
|
$recorder = $this->getMockBuilder(stdClass::class) |
|
80
|
|
|
->setMethods([$method]) |
|
81
|
|
|
->getMock(); |
|
82
|
|
|
|
|
83
|
|
|
$recorder->expects($this->exactly($count)) |
|
84
|
|
|
->method($method); |
|
85
|
|
|
|
|
86
|
|
|
return $recorder; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function getIteratorForArray(array $arr = []) |
|
90
|
|
|
{ |
|
91
|
|
|
return new ArrayIterator($arr); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|