This repository has been archived by the owner on May 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommon.php
69 lines (57 loc) · 1.76 KB
/
Common.php
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
<?php
namespace zsql\Tests;
use mysqli;
use ReflectionClass;
use PHPUnit_Framework_TestCase;
use zsql\Adapter\MysqliAdapter;
use zsql\Connection\MysqliFactory;
class Common extends PHPUnit_Framework_TestCase
{
protected $fixtureOneRowCount = 2;
protected $useVerboseErrorHandler = false;
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
if( $this->useVerboseErrorHandler ) {
$this->setVerboseErrorHandler();
}
}
protected function setVerboseErrorHandler()
{
$handler = function ($errorNumber, $errorString, $errorFile, $errorLine) {
echo "ERROR INFO\nMessage: $errorString\nFile: $errorFile\nLine: $errorLine\n";
};
set_error_handler($handler);
}
protected function fixtureModelOneFactory()
{
return new Fixture\BasicModel($this->createMysqliAdapter());
}
/**
* @return MysqliAdapter
*/
protected function createMysqliAdapter()
{
return new MysqliAdapter($this->createMysqliFactory()->createMysqli());
}
protected function databaseFactory()
{
return $this->createMysqliAdapter();
}
protected function createMysqliFactory()
{
return new MysqliFactory(
ZSQL_TEST_DATABASE_HOST,
ZSQL_TEST_DATABASE_USERNAME,
ZSQL_TEST_DATABASE_PASSWORD,
ZSQL_TEST_DATABASE_DBNAME
);
}
public function getReflectedPropertyValue($class, $propertyName)
{
$reflectedClass = new ReflectionClass($class);
$property = $reflectedClass->getProperty($propertyName);
$property->setAccessible(true);
return $property->getValue($class);
}
}